ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / cc / test / pixel_test.h
blob356269939f13682bf3e0c7d38ce3806b7f24fe99
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 ~PixelTest() override;
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 protected:
93 void SetUp() override;
96 // Wrappers to differentiate renderers where the the output surface and viewport
97 // have an externally determined size and offset.
98 class GLRendererWithExpandedViewport : public GLRenderer {
99 public:
100 GLRendererWithExpandedViewport(RendererClient* client,
101 const RendererSettings* settings,
102 OutputSurface* output_surface,
103 ResourceProvider* resource_provider,
104 TextureMailboxDeleter* texture_mailbox_deleter,
105 int highp_threshold_min)
106 : GLRenderer(client,
107 settings,
108 output_surface,
109 resource_provider,
110 texture_mailbox_deleter,
111 highp_threshold_min) {}
114 class SoftwareRendererWithExpandedViewport : public SoftwareRenderer {
115 public:
116 SoftwareRendererWithExpandedViewport(RendererClient* client,
117 const RendererSettings* settings,
118 OutputSurface* output_surface,
119 ResourceProvider* resource_provider)
120 : SoftwareRenderer(client, settings, output_surface, resource_provider) {}
123 class GLRendererWithFlippedSurface : public GLRenderer {
124 public:
125 GLRendererWithFlippedSurface(RendererClient* client,
126 const RendererSettings* settings,
127 OutputSurface* output_surface,
128 ResourceProvider* resource_provider,
129 TextureMailboxDeleter* texture_mailbox_deleter,
130 int highp_threshold_min)
131 : GLRenderer(client,
132 settings,
133 output_surface,
134 resource_provider,
135 texture_mailbox_deleter,
136 highp_threshold_min) {}
139 template<>
140 inline void RendererPixelTest<GLRenderer>::SetUp() {
141 SetUpGLRenderer(false, false);
144 template<>
145 inline void RendererPixelTest<GLRendererWithExpandedViewport>::SetUp() {
146 SetUpGLRenderer(false, false);
147 ForceExpandedViewport(gfx::Size(50, 50));
148 ForceViewportOffset(gfx::Vector2d(10, 20));
151 template <>
152 inline void RendererPixelTest<GLRendererWithFlippedSurface>::SetUp() {
153 SetUpGLRenderer(false, true);
156 template <>
157 inline void RendererPixelTest<SoftwareRenderer>::SetUp() {
158 SetUpSoftwareRenderer();
161 template<>
162 inline void RendererPixelTest<SoftwareRendererWithExpandedViewport>::SetUp() {
163 SetUpSoftwareRenderer();
164 ForceExpandedViewport(gfx::Size(50, 50));
165 ForceViewportOffset(gfx::Vector2d(10, 20));
168 typedef RendererPixelTest<GLRenderer> GLRendererPixelTest;
169 typedef RendererPixelTest<SoftwareRenderer> SoftwareRendererPixelTest;
171 } // namespace cc
173 #endif // CC_TEST_PIXEL_TEST_H_