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
{
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
,
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());
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
{
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
)
110 texture_mailbox_deleter
,
111 highp_threshold_min
) {}
114 class SoftwareRendererWithExpandedViewport
: public SoftwareRenderer
{
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
{
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
)
135 texture_mailbox_deleter
,
136 highp_threshold_min
) {}
140 inline void RendererPixelTest
<GLRenderer
>::SetUp() {
141 SetUpGLRenderer(false, false);
145 inline void RendererPixelTest
<GLRendererWithExpandedViewport
>::SetUp() {
146 SetUpGLRenderer(false, false);
147 ForceExpandedViewport(gfx::Size(50, 50));
148 ForceViewportOffset(gfx::Vector2d(10, 20));
152 inline void RendererPixelTest
<GLRendererWithFlippedSurface
>::SetUp() {
153 SetUpGLRenderer(false, true);
157 inline void RendererPixelTest
<SoftwareRenderer
>::SetUp() {
158 SetUpSoftwareRenderer();
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
;
173 #endif // CC_TEST_PIXEL_TEST_H_