Revert 264226 "Reduce dependency of TiclInvalidationService on P..."
[chromium-blink-merge.git] / cc / test / pixel_test.h
blobdc01098eb35ee1dabbd5156be20fae22ac8df2f0
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 enum OffscreenContextOption {
32 NoOffscreenContext,
33 WithOffscreenContext
36 bool RunPixelTest(RenderPassList* pass_list,
37 OffscreenContextOption provide_offscreen_context,
38 const base::FilePath& ref_file,
39 const PixelComparator& comparator);
41 bool RunPixelTestWithReadbackTarget(
42 RenderPassList* pass_list,
43 RenderPass* target,
44 OffscreenContextOption provide_offscreen_context,
45 const base::FilePath& ref_file,
46 const PixelComparator& comparator);
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<SharedBitmapManager> shared_bitmap_manager_;
55 scoped_ptr<ResourceProvider> resource_provider_;
56 scoped_ptr<TextureMailboxDeleter> texture_mailbox_deleter_;
57 scoped_ptr<DirectRenderer> renderer_;
58 scoped_ptr<SkBitmap> result_bitmap_;
59 gfx::Vector2d external_device_viewport_offset_;
60 gfx::Rect external_device_clip_rect_;
62 void SetUpGLRenderer(bool use_skia_gpu_backend);
63 void SetUpSoftwareRenderer();
65 void ForceExpandedViewport(const gfx::Size& surface_expansion);
66 void ForceViewportOffset(const gfx::Vector2d& viewport_offset);
67 void ForceDeviceClip(const gfx::Rect& clip);
68 void EnableExternalStencilTest();
70 // RendererClient implementation.
71 virtual void SetFullRootLayerDamage() OVERRIDE {}
73 private:
74 void ReadbackResult(base::Closure quit_run_loop,
75 scoped_ptr<CopyOutputResult> result);
77 bool PixelsMatchReference(const base::FilePath& ref_file,
78 const PixelComparator& comparator);
80 scoped_ptr<gfx::DisableNullDrawGLBindings> enable_pixel_output_;
83 template<typename RendererType>
84 class RendererPixelTest : public PixelTest {
85 public:
86 RendererType* renderer() {
87 return static_cast<RendererType*>(renderer_.get());
90 bool UseSkiaGPUBackend() const;
91 bool ExpandedViewport() const;
93 protected:
94 virtual void SetUp() OVERRIDE;
97 // Wrappers to differentiate renderers where the the output surface and viewport
98 // have an externally determined size and offset.
99 class GLRendererWithExpandedViewport : public GLRenderer {
100 public:
101 GLRendererWithExpandedViewport(RendererClient* client,
102 const LayerTreeSettings* settings,
103 OutputSurface* output_surface,
104 ResourceProvider* resource_provider,
105 TextureMailboxDeleter* texture_mailbox_deleter,
106 int highp_threshold_min)
107 : GLRenderer(client,
108 settings,
109 output_surface,
110 resource_provider,
111 texture_mailbox_deleter,
112 highp_threshold_min) {}
115 class SoftwareRendererWithExpandedViewport : public SoftwareRenderer {
116 public:
117 SoftwareRendererWithExpandedViewport(RendererClient* client,
118 const LayerTreeSettings* settings,
119 OutputSurface* output_surface,
120 ResourceProvider* resource_provider)
121 : SoftwareRenderer(client, settings, output_surface, resource_provider) {}
124 template<>
125 inline void RendererPixelTest<GLRenderer>::SetUp() {
126 SetUpGLRenderer(false);
129 template<>
130 inline bool RendererPixelTest<GLRenderer>::UseSkiaGPUBackend() const {
131 return false;
134 template<>
135 inline bool RendererPixelTest<GLRenderer>::ExpandedViewport() const {
136 return false;
139 template<>
140 inline void RendererPixelTest<GLRendererWithExpandedViewport>::SetUp() {
141 SetUpGLRenderer(false);
142 ForceExpandedViewport(gfx::Size(50, 50));
143 ForceViewportOffset(gfx::Vector2d(10, 20));
146 template <>
147 inline bool
148 RendererPixelTest<GLRendererWithExpandedViewport>::UseSkiaGPUBackend() const {
149 return false;
152 template <>
153 inline bool
154 RendererPixelTest<GLRendererWithExpandedViewport>::ExpandedViewport() const {
155 return true;
158 template<>
159 inline void RendererPixelTest<SoftwareRenderer>::SetUp() {
160 SetUpSoftwareRenderer();
163 template<>
164 inline bool RendererPixelTest<SoftwareRenderer>::UseSkiaGPUBackend() const {
165 return false;
168 template <>
169 inline bool RendererPixelTest<SoftwareRenderer>::ExpandedViewport() const {
170 return false;
173 template<>
174 inline void RendererPixelTest<SoftwareRendererWithExpandedViewport>::SetUp() {
175 SetUpSoftwareRenderer();
176 ForceExpandedViewport(gfx::Size(50, 50));
177 ForceViewportOffset(gfx::Vector2d(10, 20));
180 template <>
181 inline bool RendererPixelTest<
182 SoftwareRendererWithExpandedViewport>::UseSkiaGPUBackend() const {
183 return false;
186 template <>
187 inline bool RendererPixelTest<
188 SoftwareRendererWithExpandedViewport>::ExpandedViewport() const {
189 return true;
192 typedef RendererPixelTest<GLRenderer> GLRendererPixelTest;
193 typedef RendererPixelTest<SoftwareRenderer> SoftwareRendererPixelTest;
195 } // namespace cc
197 #endif // CC_TEST_PIXEL_TEST_H_