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_
18 class CopyOutputResult
;
20 class FakeOutputSurfaceClient
;
22 class ResourceProvider
;
23 class SoftwareRenderer
;
24 class SharedBitmapManager
;
26 class PixelTest
: public testing::Test
, RendererClient
{
31 enum OffscreenContextOption
{
36 bool RunPixelTest(RenderPassList
* pass_list
,
37 OffscreenContextOption provide_offscreen_context
,
38 const base::FilePath
& ref_file
,
39 const PixelComparator
& comparator
);
41 bool RunPixelTestWithReadbackTarget(
42 RenderPassList
* pass_list
,
44 OffscreenContextOption provide_offscreen_context
,
45 const base::FilePath
& ref_file
,
46 const PixelComparator
& comparator
);
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
<SharedBitmapManager
> shared_bitmap_manager_
;
55 scoped_ptr
<ResourceProvider
> resource_provider_
;
56 scoped_ptr
<TextureMailboxDeleter
> texture_mailbox_deleter_
;
57 scoped_ptr
<DirectRenderer
> renderer_
;
58 scoped_ptr
<SkBitmap
> result_bitmap_
;
59 gfx::Vector2d external_device_viewport_offset_
;
60 gfx::Rect external_device_clip_rect_
;
62 void SetUpGLRenderer(bool use_skia_gpu_backend
);
63 void SetUpSoftwareRenderer();
65 void ForceExpandedViewport(const gfx::Size
& surface_expansion
);
66 void ForceViewportOffset(const gfx::Vector2d
& viewport_offset
);
67 void ForceDeviceClip(const gfx::Rect
& clip
);
68 void EnableExternalStencilTest();
70 // RendererClient implementation.
71 virtual void SetFullRootLayerDamage() OVERRIDE
{}
74 void ReadbackResult(base::Closure quit_run_loop
,
75 scoped_ptr
<CopyOutputResult
> result
);
77 bool PixelsMatchReference(const base::FilePath
& ref_file
,
78 const PixelComparator
& comparator
);
80 scoped_ptr
<gfx::DisableNullDrawGLBindings
> enable_pixel_output_
;
83 template<typename RendererType
>
84 class RendererPixelTest
: public PixelTest
{
86 RendererType
* renderer() {
87 return static_cast<RendererType
*>(renderer_
.get());
90 bool UseSkiaGPUBackend() const;
91 bool ExpandedViewport() const;
94 virtual void SetUp() OVERRIDE
;
97 // Wrappers to differentiate renderers where the the output surface and viewport
98 // have an externally determined size and offset.
99 class GLRendererWithExpandedViewport
: public GLRenderer
{
101 GLRendererWithExpandedViewport(RendererClient
* client
,
102 const LayerTreeSettings
* settings
,
103 OutputSurface
* output_surface
,
104 ResourceProvider
* resource_provider
,
105 TextureMailboxDeleter
* texture_mailbox_deleter
,
106 int highp_threshold_min
)
111 texture_mailbox_deleter
,
112 highp_threshold_min
) {}
115 class SoftwareRendererWithExpandedViewport
: public SoftwareRenderer
{
117 SoftwareRendererWithExpandedViewport(RendererClient
* client
,
118 const LayerTreeSettings
* settings
,
119 OutputSurface
* output_surface
,
120 ResourceProvider
* resource_provider
)
121 : SoftwareRenderer(client
, settings
, output_surface
, resource_provider
) {}
125 inline void RendererPixelTest
<GLRenderer
>::SetUp() {
126 SetUpGLRenderer(false);
130 inline bool RendererPixelTest
<GLRenderer
>::UseSkiaGPUBackend() const {
135 inline bool RendererPixelTest
<GLRenderer
>::ExpandedViewport() const {
140 inline void RendererPixelTest
<GLRendererWithExpandedViewport
>::SetUp() {
141 SetUpGLRenderer(false);
142 ForceExpandedViewport(gfx::Size(50, 50));
143 ForceViewportOffset(gfx::Vector2d(10, 20));
148 RendererPixelTest
<GLRendererWithExpandedViewport
>::UseSkiaGPUBackend() const {
154 RendererPixelTest
<GLRendererWithExpandedViewport
>::ExpandedViewport() const {
159 inline void RendererPixelTest
<SoftwareRenderer
>::SetUp() {
160 SetUpSoftwareRenderer();
164 inline bool RendererPixelTest
<SoftwareRenderer
>::UseSkiaGPUBackend() const {
169 inline bool RendererPixelTest
<SoftwareRenderer
>::ExpandedViewport() const {
174 inline void RendererPixelTest
<SoftwareRendererWithExpandedViewport
>::SetUp() {
175 SetUpSoftwareRenderer();
176 ForceExpandedViewport(gfx::Size(50, 50));
177 ForceViewportOffset(gfx::Vector2d(10, 20));
181 inline bool RendererPixelTest
<
182 SoftwareRendererWithExpandedViewport
>::UseSkiaGPUBackend() const {
187 inline bool RendererPixelTest
<
188 SoftwareRendererWithExpandedViewport
>::ExpandedViewport() const {
192 typedef RendererPixelTest
<GLRenderer
> GLRendererPixelTest
;
193 typedef RendererPixelTest
<SoftwareRenderer
> SoftwareRendererPixelTest
;
197 #endif // CC_TEST_PIXEL_TEST_H_