blob: 1a6c5baab851ddf727992507b1590b8e86252f36 [file] [log] [blame]
[email protected]a7252f12013-03-15 04:57:341// Copyright 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
thestig90a09082014-09-10 07:59:465#include "base/files/file_util.h"
[email protected]bec084292013-05-21 21:31:446#include "cc/output/gl_renderer.h"
[email protected]f224cc92013-06-06 23:23:327#include "cc/output/software_renderer.h"
[email protected]18a70192013-04-26 16:18:258#include "cc/quads/render_pass.h"
[email protected]ca435682013-03-29 04:09:479#include "cc/test/pixel_comparator.h"
[email protected]a7252f12013-03-15 04:57:3410#include "testing/gtest/include/gtest/gtest.h"
heejin.r.chungd28506ba2014-10-23 16:36:2011#include "ui/gfx/geometry/size.h"
[email protected]fe18c772014-02-22 08:08:2312#include "ui/gl/gl_implementation.h"
[email protected]a7252f12013-03-15 04:57:3413
14#ifndef CC_TEST_PIXEL_TEST_H_
15#define CC_TEST_PIXEL_TEST_H_
16
17namespace cc {
[email protected]63894582013-06-18 18:24:2418class CopyOutputResult;
[email protected]598067a02013-04-29 20:35:0719class DirectRenderer;
[email protected]59fee302013-12-10 17:53:3020class FakeOutputSurfaceClient;
[email protected]a7252f12013-03-15 04:57:3421class OutputSurface;
22class ResourceProvider;
[email protected]59fee302013-12-10 17:53:3023class SoftwareRenderer;
reveman22dd9292014-10-13 20:52:0524class TestGpuMemoryBufferManager;
25class TestSharedBitmapManager;
[email protected]a7252f12013-03-15 04:57:3426
[email protected]59fee302013-12-10 17:53:3027class PixelTest : public testing::Test, RendererClient {
[email protected]a7252f12013-03-15 04:57:3428 protected:
29 PixelTest();
30 virtual ~PixelTest();
31
[email protected]18a70192013-04-26 16:18:2532 bool RunPixelTest(RenderPassList* pass_list,
[email protected]18a70192013-04-26 16:18:2533 const base::FilePath& ref_file,
34 const PixelComparator& comparator);
[email protected]a7252f12013-03-15 04:57:3435
[email protected]b5174d712013-08-28 08:10:4336 bool RunPixelTestWithReadbackTarget(
37 RenderPassList* pass_list,
38 RenderPass* target,
[email protected]b5174d712013-08-28 08:10:4339 const base::FilePath& ref_file,
40 const PixelComparator& comparator);
[email protected]6bec38a32013-05-08 23:52:1441
[email protected]573e8e32013-09-09 17:24:3242 LayerTreeSettings settings_;
[email protected]a7252f12013-03-15 04:57:3443 gfx::Size device_viewport_size_;
[email protected]251699b2013-10-09 00:21:2644 bool disable_picture_quad_image_filtering_;
[email protected]f224cc92013-06-06 23:23:3245 class PixelTestRendererClient;
[email protected]59fee302013-12-10 17:53:3046 scoped_ptr<FakeOutputSurfaceClient> output_surface_client_;
[email protected]a7252f12013-03-15 04:57:3447 scoped_ptr<OutputSurface> output_surface_;
reveman22dd9292014-10-13 20:52:0548 scoped_ptr<TestSharedBitmapManager> shared_bitmap_manager_;
49 scoped_ptr<TestGpuMemoryBufferManager> gpu_memory_buffer_manager_;
skyostil3976a3f2014-09-04 22:07:2350 scoped_ptr<BlockingTaskRunner> main_thread_task_runner_;
[email protected]a7252f12013-03-15 04:57:3451 scoped_ptr<ResourceProvider> resource_provider_;
[email protected]ea468c6c2013-09-10 08:25:1152 scoped_ptr<TextureMailboxDeleter> texture_mailbox_deleter_;
[email protected]598067a02013-04-29 20:35:0753 scoped_ptr<DirectRenderer> renderer_;
[email protected]18a70192013-04-26 16:18:2554 scoped_ptr<SkBitmap> result_bitmap_;
[email protected]59fee302013-12-10 17:53:3055 gfx::Vector2d external_device_viewport_offset_;
56 gfx::Rect external_device_clip_rect_;
[email protected]18a70192013-04-26 16:18:2557
Stephen Whiteac87ab02014-10-07 19:01:3658 void SetUpGLRenderer(bool use_skia_gpu_backend);
[email protected]598067a02013-04-29 20:35:0759 void SetUpSoftwareRenderer();
60
[email protected]64348ea2014-01-29 22:58:2661 void ForceExpandedViewport(const gfx::Size& surface_expansion);
[email protected]243e4f12014-02-05 09:18:4262 void ForceViewportOffset(const gfx::Vector2d& viewport_offset);
[email protected]0023fc72014-01-10 20:05:0663 void ForceDeviceClip(const gfx::Rect& clip);
[email protected]c32a1962013-07-30 19:41:1764 void EnableExternalStencilTest();
[email protected]f224cc92013-06-06 23:23:3265
[email protected]59fee302013-12-10 17:53:3066 // RendererClient implementation.
dcheng716bedf2014-10-21 09:51:0867 void SetFullRootLayerDamage() override {}
[email protected]59fee302013-12-10 17:53:3068
[email protected]18a70192013-04-26 16:18:2569 private:
[email protected]63894582013-06-18 18:24:2470 void ReadbackResult(base::Closure quit_run_loop,
71 scoped_ptr<CopyOutputResult> result);
[email protected]18a70192013-04-26 16:18:2572
73 bool PixelsMatchReference(const base::FilePath& ref_file,
74 const PixelComparator& comparator);
[email protected]fe18c772014-02-22 08:08:2375
76 scoped_ptr<gfx::DisableNullDrawGLBindings> enable_pixel_output_;
[email protected]a7252f12013-03-15 04:57:3477};
78
[email protected]598067a02013-04-29 20:35:0779template<typename RendererType>
80class RendererPixelTest : public PixelTest {
81 public:
82 RendererType* renderer() {
83 return static_cast<RendererType*>(renderer_.get());
84 }
85
[email protected]bec084292013-05-21 21:31:4486 bool UseSkiaGPUBackend() const;
[email protected]f224cc92013-06-06 23:23:3287 bool ExpandedViewport() const;
[email protected]bec084292013-05-21 21:31:4488
[email protected]598067a02013-04-29 20:35:0789 protected:
mostynbf68776d82014-10-06 18:07:3790 virtual void SetUp() override;
[email protected]598067a02013-04-29 20:35:0791};
92
[email protected]f224cc92013-06-06 23:23:3293// Wrappers to differentiate renderers where the the output surface and viewport
94// have an externally determined size and offset.
95class GLRendererWithExpandedViewport : public GLRenderer {
96 public:
97 GLRendererWithExpandedViewport(RendererClient* client,
[email protected]573e8e32013-09-09 17:24:3298 const LayerTreeSettings* settings,
99 OutputSurface* output_surface,
100 ResourceProvider* resource_provider,
[email protected]ea468c6c2013-09-10 08:25:11101 TextureMailboxDeleter* texture_mailbox_deleter,
[email protected]573e8e32013-09-09 17:24:32102 int highp_threshold_min)
[email protected]f224cc92013-06-06 23:23:32103 : GLRenderer(client,
[email protected]573e8e32013-09-09 17:24:32104 settings,
[email protected]f224cc92013-06-06 23:23:32105 output_surface,
106 resource_provider,
[email protected]ea468c6c2013-09-10 08:25:11107 texture_mailbox_deleter,
[email protected]f224cc92013-06-06 23:23:32108 highp_threshold_min) {}
109};
110
111class SoftwareRendererWithExpandedViewport : public SoftwareRenderer {
112 public:
113 SoftwareRendererWithExpandedViewport(RendererClient* client,
[email protected]573e8e32013-09-09 17:24:32114 const LayerTreeSettings* settings,
115 OutputSurface* output_surface,
116 ResourceProvider* resource_provider)
117 : SoftwareRenderer(client, settings, output_surface, resource_provider) {}
[email protected]f224cc92013-06-06 23:23:32118};
119
[email protected]598067a02013-04-29 20:35:07120template<>
121inline void RendererPixelTest<GLRenderer>::SetUp() {
Stephen Whiteac87ab02014-10-07 19:01:36122 SetUpGLRenderer(false);
[email protected]bec084292013-05-21 21:31:44123}
124
125template<>
126inline bool RendererPixelTest<GLRenderer>::UseSkiaGPUBackend() const {
127 return false;
128}
129
130template<>
[email protected]f224cc92013-06-06 23:23:32131inline bool RendererPixelTest<GLRenderer>::ExpandedViewport() const {
132 return false;
133}
134
135template<>
[email protected]f224cc92013-06-06 23:23:32136inline void RendererPixelTest<GLRendererWithExpandedViewport>::SetUp() {
Stephen Whiteac87ab02014-10-07 19:01:36137 SetUpGLRenderer(false);
[email protected]59fee302013-12-10 17:53:30138 ForceExpandedViewport(gfx::Size(50, 50));
139 ForceViewportOffset(gfx::Vector2d(10, 20));
[email protected]f224cc92013-06-06 23:23:32140}
141
142template <>
143inline bool
144RendererPixelTest<GLRendererWithExpandedViewport>::UseSkiaGPUBackend() const {
145 return false;
146}
147
148template <>
149inline bool
150RendererPixelTest<GLRendererWithExpandedViewport>::ExpandedViewport() const {
151 return true;
152}
153
Stephen Whiteac87ab02014-10-07 19:01:36154template<>
[email protected]598067a02013-04-29 20:35:07155inline void RendererPixelTest<SoftwareRenderer>::SetUp() {
156 SetUpSoftwareRenderer();
157}
158
[email protected]bec084292013-05-21 21:31:44159template<>
160inline bool RendererPixelTest<SoftwareRenderer>::UseSkiaGPUBackend() const {
161 return false;
162}
163
[email protected]f224cc92013-06-06 23:23:32164template <>
165inline bool RendererPixelTest<SoftwareRenderer>::ExpandedViewport() const {
166 return false;
167}
168
169template<>
170inline void RendererPixelTest<SoftwareRendererWithExpandedViewport>::SetUp() {
171 SetUpSoftwareRenderer();
[email protected]59fee302013-12-10 17:53:30172 ForceExpandedViewport(gfx::Size(50, 50));
173 ForceViewportOffset(gfx::Vector2d(10, 20));
[email protected]f224cc92013-06-06 23:23:32174}
175
176template <>
177inline bool RendererPixelTest<
178 SoftwareRendererWithExpandedViewport>::UseSkiaGPUBackend() const {
179 return false;
180}
181
182template <>
183inline bool RendererPixelTest<
184 SoftwareRendererWithExpandedViewport>::ExpandedViewport() const {
185 return true;
186}
187
[email protected]598067a02013-04-29 20:35:07188typedef RendererPixelTest<GLRenderer> GLRendererPixelTest;
189typedef RendererPixelTest<SoftwareRenderer> SoftwareRendererPixelTest;
190
[email protected]a7252f12013-03-15 04:57:34191} // namespace cc
192
193#endif // CC_TEST_PIXEL_TEST_H_