Update V8 to version 4.6.62.
[chromium-blink-merge.git] / cc / test / pixel_test.h
blob08bad36932889f364be924095b51a28ef07a7422
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 "cc/trees/layer_tree_settings.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/gfx/geometry/size.h"
13 #include "ui/gl/gl_implementation.h"
15 #ifndef CC_TEST_PIXEL_TEST_H_
16 #define CC_TEST_PIXEL_TEST_H_
18 namespace cc {
19 class CopyOutputResult;
20 class DirectRenderer;
21 class FakeOutputSurfaceClient;
22 class OutputSurface;
23 class ResourceProvider;
24 class SoftwareRenderer;
25 class TestGpuMemoryBufferManager;
26 class TestSharedBitmapManager;
28 class PixelTest : public testing::Test, RendererClient {
29 protected:
30 PixelTest();
31 ~PixelTest() override;
33 bool RunPixelTest(RenderPassList* pass_list,
34 const base::FilePath& ref_file,
35 const PixelComparator& comparator);
37 bool RunPixelTestWithReadbackTarget(
38 RenderPassList* pass_list,
39 RenderPass* target,
40 const base::FilePath& ref_file,
41 const PixelComparator& comparator);
43 bool RunPixelTestWithReadbackTargetAndArea(RenderPassList* pass_list,
44 RenderPass* target,
45 const base::FilePath& ref_file,
46 const PixelComparator& comparator,
47 const gfx::Rect* copy_rect);
49 LayerTreeSettings settings_;
50 gfx::Size device_viewport_size_;
51 bool disable_picture_quad_image_filtering_;
52 class PixelTestRendererClient;
53 scoped_ptr<FakeOutputSurfaceClient> output_surface_client_;
54 scoped_ptr<OutputSurface> output_surface_;
55 scoped_ptr<TestSharedBitmapManager> shared_bitmap_manager_;
56 scoped_ptr<TestGpuMemoryBufferManager> gpu_memory_buffer_manager_;
57 scoped_ptr<BlockingTaskRunner> main_thread_task_runner_;
58 scoped_ptr<ResourceProvider> resource_provider_;
59 scoped_ptr<TextureMailboxDeleter> texture_mailbox_deleter_;
60 scoped_ptr<DirectRenderer> renderer_;
61 scoped_ptr<SkBitmap> result_bitmap_;
62 gfx::Vector2d external_device_viewport_offset_;
63 gfx::Rect external_device_clip_rect_;
65 void SetUpGLRenderer(bool use_skia_gpu_backend, bool flipped_output_surface);
66 void SetUpSoftwareRenderer();
68 void ForceExpandedViewport(const gfx::Size& surface_expansion);
69 void ForceViewportOffset(const gfx::Vector2d& viewport_offset);
70 void ForceDeviceClip(const gfx::Rect& clip);
71 void EnableExternalStencilTest();
73 // RendererClient implementation.
74 void SetFullRootLayerDamage() override {}
76 private:
77 void ReadbackResult(base::Closure quit_run_loop,
78 scoped_ptr<CopyOutputResult> result);
80 bool PixelsMatchReference(const base::FilePath& ref_file,
81 const PixelComparator& comparator);
83 scoped_ptr<gfx::DisableNullDrawGLBindings> enable_pixel_output_;
86 template<typename RendererType>
87 class RendererPixelTest : public PixelTest {
88 public:
89 RendererType* renderer() {
90 return static_cast<RendererType*>(renderer_.get());
93 protected:
94 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 RendererSettings* 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 RendererSettings* settings,
119 OutputSurface* output_surface,
120 ResourceProvider* resource_provider)
121 : SoftwareRenderer(client, settings, output_surface, resource_provider) {}
124 class GLRendererWithFlippedSurface : public GLRenderer {
125 public:
126 GLRendererWithFlippedSurface(RendererClient* client,
127 const RendererSettings* settings,
128 OutputSurface* output_surface,
129 ResourceProvider* resource_provider,
130 TextureMailboxDeleter* texture_mailbox_deleter,
131 int highp_threshold_min)
132 : GLRenderer(client,
133 settings,
134 output_surface,
135 resource_provider,
136 texture_mailbox_deleter,
137 highp_threshold_min) {}
140 template<>
141 inline void RendererPixelTest<GLRenderer>::SetUp() {
142 SetUpGLRenderer(false, false);
145 template<>
146 inline void RendererPixelTest<GLRendererWithExpandedViewport>::SetUp() {
147 SetUpGLRenderer(false, false);
148 ForceExpandedViewport(gfx::Size(50, 50));
149 ForceViewportOffset(gfx::Vector2d(10, 20));
152 template <>
153 inline void RendererPixelTest<GLRendererWithFlippedSurface>::SetUp() {
154 SetUpGLRenderer(false, true);
157 template <>
158 inline void RendererPixelTest<SoftwareRenderer>::SetUp() {
159 SetUpSoftwareRenderer();
162 template<>
163 inline void RendererPixelTest<SoftwareRendererWithExpandedViewport>::SetUp() {
164 SetUpSoftwareRenderer();
165 ForceExpandedViewport(gfx::Size(50, 50));
166 ForceViewportOffset(gfx::Vector2d(10, 20));
169 typedef RendererPixelTest<GLRenderer> GLRendererPixelTest;
170 typedef RendererPixelTest<SoftwareRenderer> SoftwareRendererPixelTest;
172 } // namespace cc
174 #endif // CC_TEST_PIXEL_TEST_H_