mac: Don't limit GL_MAX_TEXTURE_SIZE on 10.9.0+.
[chromium-blink-merge.git] / cc / test / pixel_test.h
blob3c5350c8634b6bf910f290de19724cd988bfc682
1 // 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.
5 #include "base/files/file_util.h"
6 #include "cc/output/gl_renderer.h"
7 #include "cc/output/software_renderer.h"
8 #include "cc/quads/render_pass.h"
9 #include "cc/test/pixel_comparator.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/gfx/geometry/size.h"
12 #include "ui/gl/gl_implementation.h"
14 #ifndef CC_TEST_PIXEL_TEST_H_
15 #define CC_TEST_PIXEL_TEST_H_
17 namespace cc {
18 class CopyOutputResult;
19 class DirectRenderer;
20 class FakeOutputSurfaceClient;
21 class OutputSurface;
22 class ResourceProvider;
23 class SoftwareRenderer;
24 class TestGpuMemoryBufferManager;
25 class TestSharedBitmapManager;
27 class PixelTest : public testing::Test, RendererClient {
28 protected:
29 PixelTest();
30 virtual ~PixelTest();
32 bool RunPixelTest(RenderPassList* pass_list,
33 const base::FilePath& ref_file,
34 const PixelComparator& comparator);
36 bool RunPixelTestWithReadbackTarget(
37 RenderPassList* pass_list,
38 RenderPass* target,
39 const base::FilePath& ref_file,
40 const PixelComparator& comparator);
42 bool RunPixelTestWithReadbackTargetAndArea(RenderPassList* pass_list,
43 RenderPass* target,
44 const base::FilePath& ref_file,
45 const PixelComparator& comparator,
46 const gfx::Rect* copy_rect);
48 LayerTreeSettings settings_;
49 gfx::Size device_viewport_size_;
50 bool disable_picture_quad_image_filtering_;
51 class PixelTestRendererClient;
52 scoped_ptr<FakeOutputSurfaceClient> output_surface_client_;
53 scoped_ptr<OutputSurface> output_surface_;
54 scoped_ptr<TestSharedBitmapManager> shared_bitmap_manager_;
55 scoped_ptr<TestGpuMemoryBufferManager> gpu_memory_buffer_manager_;
56 scoped_ptr<BlockingTaskRunner> main_thread_task_runner_;
57 scoped_ptr<ResourceProvider> resource_provider_;
58 scoped_ptr<TextureMailboxDeleter> texture_mailbox_deleter_;
59 scoped_ptr<DirectRenderer> renderer_;
60 scoped_ptr<SkBitmap> result_bitmap_;
61 gfx::Vector2d external_device_viewport_offset_;
62 gfx::Rect external_device_clip_rect_;
64 void SetUpGLRenderer(bool use_skia_gpu_backend, bool flipped_output_surface);
65 void SetUpSoftwareRenderer();
67 void ForceExpandedViewport(const gfx::Size& surface_expansion);
68 void ForceViewportOffset(const gfx::Vector2d& viewport_offset);
69 void ForceDeviceClip(const gfx::Rect& clip);
70 void EnableExternalStencilTest();
72 // RendererClient implementation.
73 void SetFullRootLayerDamage() override {}
75 private:
76 void ReadbackResult(base::Closure quit_run_loop,
77 scoped_ptr<CopyOutputResult> result);
79 bool PixelsMatchReference(const base::FilePath& ref_file,
80 const PixelComparator& comparator);
82 scoped_ptr<gfx::DisableNullDrawGLBindings> enable_pixel_output_;
85 template<typename RendererType>
86 class RendererPixelTest : public PixelTest {
87 public:
88 RendererType* renderer() {
89 return static_cast<RendererType*>(renderer_.get());
92 bool UseSkiaGPUBackend() const;
93 bool ExpandedViewport() const;
95 protected:
96 void SetUp() override;
99 // Wrappers to differentiate renderers where the the output surface and viewport
100 // have an externally determined size and offset.
101 class GLRendererWithExpandedViewport : public GLRenderer {
102 public:
103 GLRendererWithExpandedViewport(RendererClient* client,
104 const RendererSettings* settings,
105 OutputSurface* output_surface,
106 ResourceProvider* resource_provider,
107 TextureMailboxDeleter* texture_mailbox_deleter,
108 int highp_threshold_min)
109 : GLRenderer(client,
110 settings,
111 output_surface,
112 resource_provider,
113 texture_mailbox_deleter,
114 highp_threshold_min) {}
117 class SoftwareRendererWithExpandedViewport : public SoftwareRenderer {
118 public:
119 SoftwareRendererWithExpandedViewport(RendererClient* client,
120 const RendererSettings* settings,
121 OutputSurface* output_surface,
122 ResourceProvider* resource_provider)
123 : SoftwareRenderer(client, settings, output_surface, resource_provider) {}
126 class GLRendererWithFlippedSurface : public GLRenderer {
127 public:
128 GLRendererWithFlippedSurface(RendererClient* client,
129 const RendererSettings* settings,
130 OutputSurface* output_surface,
131 ResourceProvider* resource_provider,
132 TextureMailboxDeleter* texture_mailbox_deleter,
133 int highp_threshold_min)
134 : GLRenderer(client,
135 settings,
136 output_surface,
137 resource_provider,
138 texture_mailbox_deleter,
139 highp_threshold_min) {}
142 template<>
143 inline void RendererPixelTest<GLRenderer>::SetUp() {
144 SetUpGLRenderer(false, false);
147 template<>
148 inline bool RendererPixelTest<GLRenderer>::UseSkiaGPUBackend() const {
149 return false;
152 template<>
153 inline bool RendererPixelTest<GLRenderer>::ExpandedViewport() const {
154 return false;
157 template<>
158 inline void RendererPixelTest<GLRendererWithExpandedViewport>::SetUp() {
159 SetUpGLRenderer(false, false);
160 ForceExpandedViewport(gfx::Size(50, 50));
161 ForceViewportOffset(gfx::Vector2d(10, 20));
164 template <>
165 inline bool
166 RendererPixelTest<GLRendererWithExpandedViewport>::UseSkiaGPUBackend() const {
167 return false;
170 template <>
171 inline bool
172 RendererPixelTest<GLRendererWithExpandedViewport>::ExpandedViewport() const {
173 return true;
176 template <>
177 inline void RendererPixelTest<GLRendererWithFlippedSurface>::SetUp() {
178 SetUpGLRenderer(false, true);
181 template <>
182 inline bool RendererPixelTest<GLRendererWithFlippedSurface>::UseSkiaGPUBackend()
183 const {
184 return false;
187 template <>
188 inline bool RendererPixelTest<GLRendererWithFlippedSurface>::ExpandedViewport()
189 const {
190 return true;
193 template <>
194 inline void RendererPixelTest<SoftwareRenderer>::SetUp() {
195 SetUpSoftwareRenderer();
198 template<>
199 inline bool RendererPixelTest<SoftwareRenderer>::UseSkiaGPUBackend() const {
200 return false;
203 template <>
204 inline bool RendererPixelTest<SoftwareRenderer>::ExpandedViewport() const {
205 return false;
208 template<>
209 inline void RendererPixelTest<SoftwareRendererWithExpandedViewport>::SetUp() {
210 SetUpSoftwareRenderer();
211 ForceExpandedViewport(gfx::Size(50, 50));
212 ForceViewportOffset(gfx::Vector2d(10, 20));
215 template <>
216 inline bool RendererPixelTest<
217 SoftwareRendererWithExpandedViewport>::UseSkiaGPUBackend() const {
218 return false;
221 template <>
222 inline bool RendererPixelTest<
223 SoftwareRendererWithExpandedViewport>::ExpandedViewport() const {
224 return true;
227 typedef RendererPixelTest<GLRenderer> GLRendererPixelTest;
228 typedef RendererPixelTest<SoftwareRenderer> SoftwareRendererPixelTest;
230 } // namespace cc
232 #endif // CC_TEST_PIXEL_TEST_H_