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/size.h"
12 #include "ui/gl/gl_implementation.h"
14 #ifndef CC_TEST_PIXEL_TEST_H_
15 #define CC_TEST_PIXEL_TEST_H_
18 class CopyOutputResult;
20 class FakeOutputSurfaceClient;
22 class ResourceProvider;
23 class SoftwareRenderer;
24 class SharedBitmapManager;
26 class PixelTest : public testing::Test, RendererClient {
31 bool RunPixelTest(RenderPassList* pass_list,
32 const base::FilePath& ref_file,
33 const PixelComparator& comparator);
35 bool RunPixelTestWithReadbackTarget(
36 RenderPassList* pass_list,
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<BlockingTaskRunner> main_thread_task_runner_;
49 scoped_ptr<ResourceProvider> resource_provider_;
50 scoped_ptr<TextureMailboxDeleter> texture_mailbox_deleter_;
51 scoped_ptr<DirectRenderer> renderer_;
52 scoped_ptr<SkBitmap> result_bitmap_;
53 gfx::Vector2d external_device_viewport_offset_;
54 gfx::Rect external_device_clip_rect_;
56 void SetUpGLRenderer(bool use_skia_gpu_backend);
57 void SetUpSoftwareRenderer();
59 void ForceExpandedViewport(const gfx::Size& surface_expansion);
60 void ForceViewportOffset(const gfx::Vector2d& viewport_offset);
61 void ForceDeviceClip(const gfx::Rect& clip);
62 void EnableExternalStencilTest();
64 // RendererClient implementation.
65 virtual void SetFullRootLayerDamage() OVERRIDE {}
68 void ReadbackResult(base::Closure quit_run_loop,
69 scoped_ptr<CopyOutputResult> result);
71 bool PixelsMatchReference(const base::FilePath& ref_file,
72 const PixelComparator& comparator);
74 scoped_ptr<gfx::DisableNullDrawGLBindings> enable_pixel_output_;
77 template<typename RendererType>
78 class RendererPixelTest : public PixelTest {
80 RendererType* renderer() {
81 return static_cast<RendererType*>(renderer_.get());
84 bool UseSkiaGPUBackend() const;
85 bool ExpandedViewport() const;
88 virtual void SetUp() OVERRIDE;
91 // Wrappers to differentiate renderers where the the output surface and viewport
92 // have an externally determined size and offset.
93 class GLRendererWithExpandedViewport : public GLRenderer {
95 GLRendererWithExpandedViewport(RendererClient* client,
96 const LayerTreeSettings* settings,
97 OutputSurface* output_surface,
98 ResourceProvider* resource_provider,
99 TextureMailboxDeleter* texture_mailbox_deleter,
100 int highp_threshold_min)
105 texture_mailbox_deleter,
106 highp_threshold_min) {}
109 class SoftwareRendererWithExpandedViewport : public SoftwareRenderer {
111 SoftwareRendererWithExpandedViewport(RendererClient* client,
112 const LayerTreeSettings* settings,
113 OutputSurface* output_surface,
114 ResourceProvider* resource_provider)
115 : SoftwareRenderer(client, settings, output_surface, resource_provider) {}
119 inline void RendererPixelTest<GLRenderer>::SetUp() {
120 SetUpGLRenderer(false);
124 inline bool RendererPixelTest<GLRenderer>::UseSkiaGPUBackend() const {
129 inline bool RendererPixelTest<GLRenderer>::ExpandedViewport() const {
134 inline void RendererPixelTest<GLRendererWithExpandedViewport>::SetUp() {
135 SetUpGLRenderer(false);
136 ForceExpandedViewport(gfx::Size(50, 50));
137 ForceViewportOffset(gfx::Vector2d(10, 20));
142 RendererPixelTest<GLRendererWithExpandedViewport>::UseSkiaGPUBackend() const {
148 RendererPixelTest<GLRendererWithExpandedViewport>::ExpandedViewport() const {
153 inline void RendererPixelTest<SoftwareRenderer>::SetUp() {
154 SetUpSoftwareRenderer();
158 inline bool RendererPixelTest<SoftwareRenderer>::UseSkiaGPUBackend() const {
163 inline bool RendererPixelTest<SoftwareRenderer>::ExpandedViewport() const {
168 inline void RendererPixelTest<SoftwareRendererWithExpandedViewport>::SetUp() {
169 SetUpSoftwareRenderer();
170 ForceExpandedViewport(gfx::Size(50, 50));
171 ForceViewportOffset(gfx::Vector2d(10, 20));
175 inline bool RendererPixelTest<
176 SoftwareRendererWithExpandedViewport>::UseSkiaGPUBackend() const {
181 inline bool RendererPixelTest<
182 SoftwareRendererWithExpandedViewport>::ExpandedViewport() const {
186 typedef RendererPixelTest<GLRenderer> GLRendererPixelTest;
187 typedef RendererPixelTest<SoftwareRenderer> SoftwareRendererPixelTest;
191 #endif // CC_TEST_PIXEL_TEST_H_