Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(408)

Side by Side Diff: cc/test/pixel_test.h

Issue 15579002: Implement transform/clip support for Android WebView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Turn on fuzzy comparator for new SoftwareRenderer tests Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/file_util.h" 5 #include "base/file_util.h"
6 #include "cc/output/gl_renderer.h" 6 #include "cc/output/gl_renderer.h"
7 #include "cc/output/software_renderer.h"
7 #include "cc/quads/render_pass.h" 8 #include "cc/quads/render_pass.h"
8 #include "cc/test/pixel_comparator.h" 9 #include "cc/test/pixel_comparator.h"
9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/gfx/size.h" 11 #include "ui/gfx/size.h"
11 12
12 #ifndef CC_TEST_PIXEL_TEST_H_ 13 #ifndef CC_TEST_PIXEL_TEST_H_
13 #define CC_TEST_PIXEL_TEST_H_ 14 #define CC_TEST_PIXEL_TEST_H_
14 15
15 namespace cc { 16 namespace cc {
16 class DirectRenderer; 17 class DirectRenderer;
17 class SoftwareRenderer; 18 class SoftwareRenderer;
18 class OutputSurface; 19 class OutputSurface;
19 class ResourceProvider; 20 class ResourceProvider;
20 21
21 class PixelTest : public testing::Test { 22 class PixelTest : public testing::Test {
22 protected: 23 protected:
23 PixelTest(); 24 PixelTest();
24 virtual ~PixelTest(); 25 virtual ~PixelTest();
25 26
26 bool RunPixelTest(RenderPassList* pass_list, 27 bool RunPixelTest(RenderPassList* pass_list,
27 const base::FilePath& ref_file, 28 const base::FilePath& ref_file,
28 const PixelComparator& comparator); 29 const PixelComparator& comparator);
29 30
30 bool RunPixelTestWithReadbackTarget(RenderPassList* pass_list, 31 bool RunPixelTestWithReadbackTarget(RenderPassList* pass_list,
31 RenderPass* target, 32 RenderPass* target,
32 const base::FilePath& ref_file, 33 const base::FilePath& ref_file,
33 const PixelComparator& comparator); 34 const PixelComparator& comparator);
34 35
35 gfx::Size device_viewport_size_; 36 gfx::Size device_viewport_size_;
37 class PixelTestOutputSurface;
38 class PixelTestRendererClient;
36 scoped_ptr<OutputSurface> output_surface_; 39 scoped_ptr<OutputSurface> output_surface_;
37 scoped_ptr<ResourceProvider> resource_provider_; 40 scoped_ptr<ResourceProvider> resource_provider_;
38 class PixelTestRendererClient;
39 scoped_ptr<PixelTestRendererClient> fake_client_; 41 scoped_ptr<PixelTestRendererClient> fake_client_;
40 scoped_ptr<DirectRenderer> renderer_; 42 scoped_ptr<DirectRenderer> renderer_;
41 scoped_ptr<SkBitmap> result_bitmap_; 43 scoped_ptr<SkBitmap> result_bitmap_;
42 44
43 void SetUpGLRenderer(bool use_skia_gpu_backend); 45 void SetUpGLRenderer(bool use_skia_gpu_backend);
44 void SetUpSoftwareRenderer(); 46 void SetUpSoftwareRenderer();
45 47
48 void ForceExpandedViewport(gfx::Size surface_expansion,
49 gfx::Vector2d viewport_offset);
50
46 private: 51 private:
47 void ReadbackResult(base::Closure quit_run_loop, scoped_ptr<SkBitmap> bitmap); 52 void ReadbackResult(base::Closure quit_run_loop, scoped_ptr<SkBitmap> bitmap);
48 53
49 bool PixelsMatchReference(const base::FilePath& ref_file, 54 bool PixelsMatchReference(const base::FilePath& ref_file,
50 const PixelComparator& comparator); 55 const PixelComparator& comparator);
51 }; 56 };
52 57
53 template<typename RendererType> 58 template<typename RendererType>
54 class RendererPixelTest : public PixelTest { 59 class RendererPixelTest : public PixelTest {
55 public: 60 public:
56 RendererType* renderer() { 61 RendererType* renderer() {
57 return static_cast<RendererType*>(renderer_.get()); 62 return static_cast<RendererType*>(renderer_.get());
58 } 63 }
59 64
60 bool UseSkiaGPUBackend() const; 65 bool UseSkiaGPUBackend() const;
66 bool ExpandedViewport() const;
61 67
62 protected: 68 protected:
63 virtual void SetUp() OVERRIDE; 69 virtual void SetUp() OVERRIDE;
64 }; 70 };
65 71
66 // A simple wrapper to differentiate a renderer that should use ganesh 72 // A simple wrapper to differentiate a renderer that should use ganesh
67 // and one that shouldn't in templates. 73 // and one that shouldn't in templates.
68 class GLRendererWithSkiaGPUBackend : public GLRenderer { 74 class GLRendererWithSkiaGPUBackend : public GLRenderer {
69 public: 75 public:
70 GLRendererWithSkiaGPUBackend(RendererClient* client, 76 GLRendererWithSkiaGPUBackend(RendererClient* client,
71 OutputSurface* output_surface, 77 OutputSurface* output_surface,
72 ResourceProvider* resource_provider, 78 ResourceProvider* resource_provider,
73 int highp_threshold_min) 79 int highp_threshold_min)
74 : GLRenderer(client, 80 : GLRenderer(client,
75 output_surface, 81 output_surface,
76 resource_provider, 82 resource_provider,
77 highp_threshold_min) {} 83 highp_threshold_min) {}
78 }; 84 };
79 85
86 // Wrappers to differentiate renderers where the the output surface and viewport
87 // have an externally determined size and offset.
88 class GLRendererWithExpandedViewport : public GLRenderer {
89 public:
90 GLRendererWithExpandedViewport(RendererClient* client,
91 OutputSurface* output_surface,
92 ResourceProvider* resource_provider,
93 int highp_threshold_min)
94 : GLRenderer(client,
95 output_surface,
96 resource_provider,
97 highp_threshold_min) {}
98 };
99
100 class SoftwareRendererWithExpandedViewport : public SoftwareRenderer {
101 public:
102 SoftwareRendererWithExpandedViewport(RendererClient* client,
103 OutputSurface* output_surface,
104 ResourceProvider* resource_provider)
105 : SoftwareRenderer(client,
106 output_surface,
107 resource_provider) {}
108 };
109
110
80 template<> 111 template<>
81 inline void RendererPixelTest<GLRenderer>::SetUp() { 112 inline void RendererPixelTest<GLRenderer>::SetUp() {
82 SetUpGLRenderer(false); 113 SetUpGLRenderer(false);
83 DCHECK(!renderer()->CanUseSkiaGPUBackend()); 114 DCHECK(!renderer()->CanUseSkiaGPUBackend());
84 } 115 }
85 116
86 template<> 117 template<>
87 inline bool RendererPixelTest<GLRenderer>::UseSkiaGPUBackend() const { 118 inline bool RendererPixelTest<GLRenderer>::UseSkiaGPUBackend() const {
88 return false; 119 return false;
89 } 120 }
90 121
91 template<> 122 template<>
123 inline bool RendererPixelTest<GLRenderer>::ExpandedViewport() const {
124 return false;
125 }
126
127 template<>
92 inline void RendererPixelTest<GLRendererWithSkiaGPUBackend>::SetUp() { 128 inline void RendererPixelTest<GLRendererWithSkiaGPUBackend>::SetUp() {
93 SetUpGLRenderer(true); 129 SetUpGLRenderer(true);
94 DCHECK(renderer()->CanUseSkiaGPUBackend()); 130 DCHECK(renderer()->CanUseSkiaGPUBackend());
95 } 131 }
96 132
97 template <> 133 template <>
98 inline bool 134 inline bool
99 RendererPixelTest<GLRendererWithSkiaGPUBackend>::UseSkiaGPUBackend() const { 135 RendererPixelTest<GLRendererWithSkiaGPUBackend>::UseSkiaGPUBackend() const {
100 return true; 136 return true;
101 } 137 }
102 138
139 template <>
140 inline bool RendererPixelTest<GLRendererWithSkiaGPUBackend>::ExpandedViewport()
141 const {
142 return false;
143 }
144
145 template<>
146 inline void RendererPixelTest<GLRendererWithExpandedViewport>::SetUp() {
147 SetUpGLRenderer(false);
148 ForceExpandedViewport(gfx::Size(50, 50), gfx::Vector2d(10, 20));
149 }
150
151 template <>
152 inline bool
153 RendererPixelTest<GLRendererWithExpandedViewport>::UseSkiaGPUBackend() const {
154 return false;
155 }
156
157 template <>
158 inline bool
159 RendererPixelTest<GLRendererWithExpandedViewport>::ExpandedViewport() const {
160 return true;
161 }
162
103 template<> 163 template<>
104 inline void RendererPixelTest<SoftwareRenderer>::SetUp() { 164 inline void RendererPixelTest<SoftwareRenderer>::SetUp() {
105 SetUpSoftwareRenderer(); 165 SetUpSoftwareRenderer();
106 } 166 }
107 167
108 template<> 168 template<>
109 inline bool RendererPixelTest<SoftwareRenderer>::UseSkiaGPUBackend() const { 169 inline bool RendererPixelTest<SoftwareRenderer>::UseSkiaGPUBackend() const {
110 return false; 170 return false;
111 } 171 }
112 172
173 template <>
174 inline bool RendererPixelTest<SoftwareRenderer>::ExpandedViewport() const {
175 return false;
176 }
177
178 template<>
179 inline void RendererPixelTest<SoftwareRendererWithExpandedViewport>::SetUp() {
180 SetUpSoftwareRenderer();
181 ForceExpandedViewport(gfx::Size(50, 50), gfx::Vector2d(10, 20));
182 }
183
184 template <>
185 inline bool RendererPixelTest<
186 SoftwareRendererWithExpandedViewport>::UseSkiaGPUBackend() const {
187 return false;
188 }
189
190 template <>
191 inline bool RendererPixelTest<
192 SoftwareRendererWithExpandedViewport>::ExpandedViewport() const {
193 return true;
194 }
195
113 typedef RendererPixelTest<GLRenderer> GLRendererPixelTest; 196 typedef RendererPixelTest<GLRenderer> GLRendererPixelTest;
114 typedef RendererPixelTest<GLRendererWithSkiaGPUBackend> 197 typedef RendererPixelTest<GLRendererWithSkiaGPUBackend>
115 GLRendererSkiaGPUBackendPixelTest; 198 GLRendererSkiaGPUBackendPixelTest;
116 typedef RendererPixelTest<SoftwareRenderer> SoftwareRendererPixelTest; 199 typedef RendererPixelTest<SoftwareRenderer> SoftwareRendererPixelTest;
117 200
118 } // namespace cc 201 } // namespace cc
119 202
120 #endif // CC_TEST_PIXEL_TEST_H_ 203 #endif // CC_TEST_PIXEL_TEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698