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"
13 #ifndef CC_TEST_PIXEL_TEST_H_
14 #define CC_TEST_PIXEL_TEST_H_
17 class CopyOutputResult;
19 class FakeOutputSurfaceClient;
21 class ResourceProvider;
22 class SoftwareRenderer;
24 class PixelTest : public testing::Test, RendererClient {
29 enum OffscreenContextOption {
34 bool RunPixelTest(RenderPassList* pass_list,
35 OffscreenContextOption provide_offscreen_context,
36 const base::FilePath& ref_file,
37 const PixelComparator& comparator);
39 bool RunPixelTestWithReadbackTarget(
40 RenderPassList* pass_list,
42 OffscreenContextOption provide_offscreen_context,
43 const base::FilePath& ref_file,
44 const PixelComparator& comparator);
46 LayerTreeSettings settings_;
47 gfx::Size device_viewport_size_;
48 bool disable_picture_quad_image_filtering_;
49 class PixelTestRendererClient;
50 scoped_ptr<FakeOutputSurfaceClient> output_surface_client_;
51 scoped_ptr<OutputSurface> output_surface_;
52 scoped_ptr<ResourceProvider> resource_provider_;
53 scoped_ptr<TextureMailboxDeleter> texture_mailbox_deleter_;
54 scoped_ptr<DirectRenderer> renderer_;
55 scoped_ptr<SkBitmap> result_bitmap_;
56 gfx::Vector2d external_device_viewport_offset_;
57 gfx::Rect external_device_clip_rect_;
59 void SetUpGLRenderer(bool use_skia_gpu_backend);
60 void SetUpSoftwareRenderer();
62 void ForceExpandedViewport(const gfx::Size& surface_expansion);
63 void ForceViewportOffset(const gfx::Vector2d& viewport_offset);
64 void ForceDeviceClip(const gfx::Rect& clip);
65 void EnableExternalStencilTest();
67 // RendererClient implementation.
68 virtual void SetFullRootLayerDamage() OVERRIDE {}
71 void ReadbackResult(base::Closure quit_run_loop,
72 scoped_ptr<CopyOutputResult> result);
74 bool PixelsMatchReference(const base::FilePath& ref_file,
75 const PixelComparator& comparator);
78 template<typename RendererType>
79 class RendererPixelTest : public PixelTest {
81 RendererType* renderer() {
82 return static_cast<RendererType*>(renderer_.get());
85 bool UseSkiaGPUBackend() const;
86 bool ExpandedViewport() const;
89 virtual void SetUp() OVERRIDE;
92 // Wrappers to differentiate renderers where the the output surface and viewport
93 // have an externally determined size and offset.
94 class GLRendererWithExpandedViewport : public GLRenderer {
96 GLRendererWithExpandedViewport(RendererClient* client,
97 const LayerTreeSettings* settings,
98 OutputSurface* output_surface,
99 ResourceProvider* resource_provider,
100 TextureMailboxDeleter* texture_mailbox_deleter,
101 int highp_threshold_min)
106 texture_mailbox_deleter,
107 highp_threshold_min) {}
110 class SoftwareRendererWithExpandedViewport : public SoftwareRenderer {
112 SoftwareRendererWithExpandedViewport(RendererClient* client,
113 const LayerTreeSettings* settings,
114 OutputSurface* output_surface,
115 ResourceProvider* resource_provider)
116 : SoftwareRenderer(client, settings, output_surface, resource_provider) {}
120 inline void RendererPixelTest<GLRenderer>::SetUp() {
121 SetUpGLRenderer(false);
125 inline bool RendererPixelTest<GLRenderer>::UseSkiaGPUBackend() const {
130 inline bool RendererPixelTest<GLRenderer>::ExpandedViewport() const {
135 inline void RendererPixelTest<GLRendererWithExpandedViewport>::SetUp() {
136 SetUpGLRenderer(false);
137 ForceExpandedViewport(gfx::Size(50, 50));
138 ForceViewportOffset(gfx::Vector2d(10, 20));
143 RendererPixelTest<GLRendererWithExpandedViewport>::UseSkiaGPUBackend() const {
149 RendererPixelTest<GLRendererWithExpandedViewport>::ExpandedViewport() const {
154 inline void RendererPixelTest<SoftwareRenderer>::SetUp() {
155 SetUpSoftwareRenderer();
159 inline bool RendererPixelTest<SoftwareRenderer>::UseSkiaGPUBackend() const {
164 inline bool RendererPixelTest<SoftwareRenderer>::ExpandedViewport() const {
169 inline void RendererPixelTest<SoftwareRendererWithExpandedViewport>::SetUp() {
170 SetUpSoftwareRenderer();
171 ForceExpandedViewport(gfx::Size(50, 50));
172 ForceViewportOffset(gfx::Vector2d(10, 20));
176 inline bool RendererPixelTest<
177 SoftwareRendererWithExpandedViewport>::UseSkiaGPUBackend() const {
182 inline bool RendererPixelTest<
183 SoftwareRendererWithExpandedViewport>::ExpandedViewport() const {
187 typedef RendererPixelTest<GLRenderer> GLRendererPixelTest;
188 typedef RendererPixelTest<SoftwareRenderer> SoftwareRendererPixelTest;
192 #endif // CC_TEST_PIXEL_TEST_H_