Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / cc / test / pixel_test.h
blobbb4c13dd72a185a2e5e6d87de4ecb552a7bbb988
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 {}
66 private:
67 void ReadbackResult(base::Closure quit_run_loop,
68 scoped_ptr<CopyOutputResult> result);
70 bool PixelsMatchReference(const base::FilePath& ref_file,
71 const PixelComparator& comparator);
73 scoped_ptr<gfx::DisableNullDrawGLBindings> enable_pixel_output_;
76 template<typename RendererType>
77 class RendererPixelTest : public PixelTest {
78 public:
79 RendererType* renderer() {
80 return static_cast<RendererType*>(renderer_.get());
83 bool UseSkiaGPUBackend() const;
84 bool ExpandedViewport() const;
86 protected:
87 virtual void SetUp() OVERRIDE;
90 // Wrappers to differentiate renderers where the the output surface and viewport
91 // have an externally determined size and offset.
92 class GLRendererWithExpandedViewport : public GLRenderer {
93 public:
94 GLRendererWithExpandedViewport(RendererClient* client,
95 const LayerTreeSettings* settings,
96 OutputSurface* output_surface,
97 ResourceProvider* resource_provider,
98 TextureMailboxDeleter* texture_mailbox_deleter,
99 int highp_threshold_min)
100 : GLRenderer(client,
101 settings,
102 output_surface,
103 resource_provider,
104 texture_mailbox_deleter,
105 highp_threshold_min) {}
108 class SoftwareRendererWithExpandedViewport : public SoftwareRenderer {
109 public:
110 SoftwareRendererWithExpandedViewport(RendererClient* client,
111 const LayerTreeSettings* settings,
112 OutputSurface* output_surface,
113 ResourceProvider* resource_provider)
114 : SoftwareRenderer(client, settings, output_surface, resource_provider) {}
117 template<>
118 inline void RendererPixelTest<GLRenderer>::SetUp() {
119 SetUpGLRenderer(false);
122 template<>
123 inline bool RendererPixelTest<GLRenderer>::UseSkiaGPUBackend() const {
124 return false;
127 template<>
128 inline bool RendererPixelTest<GLRenderer>::ExpandedViewport() const {
129 return false;
132 template<>
133 inline void RendererPixelTest<GLRendererWithExpandedViewport>::SetUp() {
134 SetUpGLRenderer(false);
135 ForceExpandedViewport(gfx::Size(50, 50));
136 ForceViewportOffset(gfx::Vector2d(10, 20));
139 template <>
140 inline bool
141 RendererPixelTest<GLRendererWithExpandedViewport>::UseSkiaGPUBackend() const {
142 return false;
145 template <>
146 inline bool
147 RendererPixelTest<GLRendererWithExpandedViewport>::ExpandedViewport() const {
148 return true;
151 template<>
152 inline void RendererPixelTest<SoftwareRenderer>::SetUp() {
153 SetUpSoftwareRenderer();
156 template<>
157 inline bool RendererPixelTest<SoftwareRenderer>::UseSkiaGPUBackend() const {
158 return false;
161 template <>
162 inline bool RendererPixelTest<SoftwareRenderer>::ExpandedViewport() const {
163 return false;
166 template<>
167 inline void RendererPixelTest<SoftwareRendererWithExpandedViewport>::SetUp() {
168 SetUpSoftwareRenderer();
169 ForceExpandedViewport(gfx::Size(50, 50));
170 ForceViewportOffset(gfx::Vector2d(10, 20));
173 template <>
174 inline bool RendererPixelTest<
175 SoftwareRendererWithExpandedViewport>::UseSkiaGPUBackend() const {
176 return false;
179 template <>
180 inline bool RendererPixelTest<
181 SoftwareRendererWithExpandedViewport>::ExpandedViewport() const {
182 return true;
185 typedef RendererPixelTest<GLRenderer> GLRendererPixelTest;
186 typedef RendererPixelTest<SoftwareRenderer> SoftwareRendererPixelTest;
188 } // namespace cc
190 #endif // CC_TEST_PIXEL_TEST_H_