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_
18 class CopyOutputResult
;
20 class FakeOutputSurfaceClient
;
22 class ResourceProvider
;
23 class SoftwareRenderer
;
24 class TestGpuMemoryBufferManager
;
25 class TestSharedBitmapManager
;
27 class PixelTest
: public testing::Test
, RendererClient
{
32 bool RunPixelTest(RenderPassList
* pass_list
,
33 const base::FilePath
& ref_file
,
34 const PixelComparator
& comparator
);
36 bool RunPixelTestWithReadbackTarget(
37 RenderPassList
* pass_list
,
39 const base::FilePath
& ref_file
,
40 const PixelComparator
& comparator
);
42 bool RunPixelTestWithReadbackTargetAndArea(RenderPassList
* pass_list
,
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
{}
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
{
88 RendererType
* renderer() {
89 return static_cast<RendererType
*>(renderer_
.get());
92 bool UseSkiaGPUBackend() const;
93 bool ExpandedViewport() const;
96 void SetUp() override
;
99 // Wrappers to differentiate renderers where the the output surface and viewport
100 // have an externally determined size and offset.
101 class GLRendererWithExpandedViewport
: public GLRenderer
{
103 GLRendererWithExpandedViewport(RendererClient
* client
,
104 const RendererSettings
* settings
,
105 OutputSurface
* output_surface
,
106 ResourceProvider
* resource_provider
,
107 TextureMailboxDeleter
* texture_mailbox_deleter
,
108 int highp_threshold_min
)
113 texture_mailbox_deleter
,
114 highp_threshold_min
) {}
117 class SoftwareRendererWithExpandedViewport
: public SoftwareRenderer
{
119 SoftwareRendererWithExpandedViewport(RendererClient
* client
,
120 const RendererSettings
* settings
,
121 OutputSurface
* output_surface
,
122 ResourceProvider
* resource_provider
)
123 : SoftwareRenderer(client
, settings
, output_surface
, resource_provider
) {}
126 class GLRendererWithFlippedSurface
: public GLRenderer
{
128 GLRendererWithFlippedSurface(RendererClient
* client
,
129 const RendererSettings
* settings
,
130 OutputSurface
* output_surface
,
131 ResourceProvider
* resource_provider
,
132 TextureMailboxDeleter
* texture_mailbox_deleter
,
133 int highp_threshold_min
)
138 texture_mailbox_deleter
,
139 highp_threshold_min
) {}
143 inline void RendererPixelTest
<GLRenderer
>::SetUp() {
144 SetUpGLRenderer(false, false);
148 inline bool RendererPixelTest
<GLRenderer
>::UseSkiaGPUBackend() const {
153 inline bool RendererPixelTest
<GLRenderer
>::ExpandedViewport() const {
158 inline void RendererPixelTest
<GLRendererWithExpandedViewport
>::SetUp() {
159 SetUpGLRenderer(false, false);
160 ForceExpandedViewport(gfx::Size(50, 50));
161 ForceViewportOffset(gfx::Vector2d(10, 20));
166 RendererPixelTest
<GLRendererWithExpandedViewport
>::UseSkiaGPUBackend() const {
172 RendererPixelTest
<GLRendererWithExpandedViewport
>::ExpandedViewport() const {
177 inline void RendererPixelTest
<GLRendererWithFlippedSurface
>::SetUp() {
178 SetUpGLRenderer(false, true);
182 inline bool RendererPixelTest
<GLRendererWithFlippedSurface
>::UseSkiaGPUBackend()
188 inline bool RendererPixelTest
<GLRendererWithFlippedSurface
>::ExpandedViewport()
194 inline void RendererPixelTest
<SoftwareRenderer
>::SetUp() {
195 SetUpSoftwareRenderer();
199 inline bool RendererPixelTest
<SoftwareRenderer
>::UseSkiaGPUBackend() const {
204 inline bool RendererPixelTest
<SoftwareRenderer
>::ExpandedViewport() const {
209 inline void RendererPixelTest
<SoftwareRendererWithExpandedViewport
>::SetUp() {
210 SetUpSoftwareRenderer();
211 ForceExpandedViewport(gfx::Size(50, 50));
212 ForceViewportOffset(gfx::Vector2d(10, 20));
216 inline bool RendererPixelTest
<
217 SoftwareRendererWithExpandedViewport
>::UseSkiaGPUBackend() const {
222 inline bool RendererPixelTest
<
223 SoftwareRendererWithExpandedViewport
>::ExpandedViewport() const {
227 typedef RendererPixelTest
<GLRenderer
> GLRendererPixelTest
;
228 typedef RendererPixelTest
<SoftwareRenderer
> SoftwareRendererPixelTest
;
232 #endif // CC_TEST_PIXEL_TEST_H_