Revert of Create a new AccountTrackerService (patchset #8 of https://codereview.chrom...
[chromium-blink-merge.git] / cc / test / pixel_test.h
blob46c9bf76d63b51d464e419950d7c60a70776cd42
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/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/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 SharedBitmapManager;
26 class PixelTest : public testing::Test, RendererClient {
27 protected:
28 PixelTest();
29 virtual ~PixelTest();
31 bool RunPixelTest(RenderPassList* pass_list,
32 const base::FilePath& ref_file,
33 const PixelComparator& comparator);
35 bool RunPixelTestWithReadbackTarget(
36 RenderPassList* pass_list,
37 RenderPass* target,
38 const base::FilePath& ref_file,
39 const PixelComparator& comparator);
41 LayerTreeSettings settings_;
42 gfx::Size device_viewport_size_;
43 bool disable_picture_quad_image_filtering_;
44 class PixelTestRendererClient;
45 scoped_ptr<FakeOutputSurfaceClient> output_surface_client_;
46 scoped_ptr<OutputSurface> output_surface_;
47 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_;
48 scoped_ptr<ResourceProvider> resource_provider_;
49 scoped_ptr<TextureMailboxDeleter> texture_mailbox_deleter_;
50 scoped_ptr<DirectRenderer> renderer_;
51 scoped_ptr<SkBitmap> result_bitmap_;
52 gfx::Vector2d external_device_viewport_offset_;
53 gfx::Rect external_device_clip_rect_;
55 void SetUpGLRenderer(bool use_skia_gpu_backend);
56 void SetUpSoftwareRenderer();
58 void ForceExpandedViewport(const gfx::Size& surface_expansion);
59 void ForceViewportOffset(const gfx::Vector2d& viewport_offset);
60 void ForceDeviceClip(const gfx::Rect& clip);
61 void EnableExternalStencilTest();
63 // RendererClient implementation.
64 virtual void SetFullRootLayerDamage() OVERRIDE {}
65 virtual void RunOnDemandRasterTask(Task* on_demand_raster_task) OVERRIDE;
67 private:
68 void ReadbackResult(base::Closure quit_run_loop,
69 scoped_ptr<CopyOutputResult> result);
71 bool PixelsMatchReference(const base::FilePath& ref_file,
72 const PixelComparator& comparator);
74 scoped_ptr<gfx::DisableNullDrawGLBindings> enable_pixel_output_;
77 template<typename RendererType>
78 class RendererPixelTest : public PixelTest {
79 public:
80 RendererType* renderer() {
81 return static_cast<RendererType*>(renderer_.get());
84 bool UseSkiaGPUBackend() const;
85 bool ExpandedViewport() const;
87 protected:
88 virtual void SetUp() OVERRIDE;
91 // Wrappers to differentiate renderers where the the output surface and viewport
92 // have an externally determined size and offset.
93 class GLRendererWithExpandedViewport : public GLRenderer {
94 public:
95 GLRendererWithExpandedViewport(RendererClient* client,
96 const LayerTreeSettings* settings,
97 OutputSurface* output_surface,
98 ResourceProvider* resource_provider,
99 TextureMailboxDeleter* texture_mailbox_deleter,
100 int highp_threshold_min)
101 : GLRenderer(client,
102 settings,
103 output_surface,
104 resource_provider,
105 texture_mailbox_deleter,
106 highp_threshold_min) {}
109 class SoftwareRendererWithExpandedViewport : public SoftwareRenderer {
110 public:
111 SoftwareRendererWithExpandedViewport(RendererClient* client,
112 const LayerTreeSettings* settings,
113 OutputSurface* output_surface,
114 ResourceProvider* resource_provider)
115 : SoftwareRenderer(client, settings, output_surface, resource_provider) {}
118 template<>
119 inline void RendererPixelTest<GLRenderer>::SetUp() {
120 SetUpGLRenderer(false);
123 template<>
124 inline bool RendererPixelTest<GLRenderer>::UseSkiaGPUBackend() const {
125 return false;
128 template<>
129 inline bool RendererPixelTest<GLRenderer>::ExpandedViewport() const {
130 return false;
133 template<>
134 inline void RendererPixelTest<GLRendererWithExpandedViewport>::SetUp() {
135 SetUpGLRenderer(false);
136 ForceExpandedViewport(gfx::Size(50, 50));
137 ForceViewportOffset(gfx::Vector2d(10, 20));
140 template <>
141 inline bool
142 RendererPixelTest<GLRendererWithExpandedViewport>::UseSkiaGPUBackend() const {
143 return false;
146 template <>
147 inline bool
148 RendererPixelTest<GLRendererWithExpandedViewport>::ExpandedViewport() const {
149 return true;
152 template<>
153 inline void RendererPixelTest<SoftwareRenderer>::SetUp() {
154 SetUpSoftwareRenderer();
157 template<>
158 inline bool RendererPixelTest<SoftwareRenderer>::UseSkiaGPUBackend() const {
159 return false;
162 template <>
163 inline bool RendererPixelTest<SoftwareRenderer>::ExpandedViewport() const {
164 return false;
167 template<>
168 inline void RendererPixelTest<SoftwareRendererWithExpandedViewport>::SetUp() {
169 SetUpSoftwareRenderer();
170 ForceExpandedViewport(gfx::Size(50, 50));
171 ForceViewportOffset(gfx::Vector2d(10, 20));
174 template <>
175 inline bool RendererPixelTest<
176 SoftwareRendererWithExpandedViewport>::UseSkiaGPUBackend() const {
177 return false;
180 template <>
181 inline bool RendererPixelTest<
182 SoftwareRendererWithExpandedViewport>::ExpandedViewport() const {
183 return true;
186 typedef RendererPixelTest<GLRenderer> GLRendererPixelTest;
187 typedef RendererPixelTest<SoftwareRenderer> SoftwareRendererPixelTest;
189 } // namespace cc
191 #endif // CC_TEST_PIXEL_TEST_H_