blob: 0835cdca94b5d55443fbc87d6e02fbd561f27e27 [file] [log] [blame]
[email protected]a7252f12013-03-15 04:57:341// 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.
4
5#include "base/file_util.h"
[email protected]bec084292013-05-21 21:31:446#include "cc/output/gl_renderer.h"
[email protected]f224cc92013-06-06 23:23:327#include "cc/output/software_renderer.h"
[email protected]18a70192013-04-26 16:18:258#include "cc/quads/render_pass.h"
[email protected]ca435682013-03-29 04:09:479#include "cc/test/pixel_comparator.h"
[email protected]a7252f12013-03-15 04:57:3410#include "testing/gtest/include/gtest/gtest.h"
11#include "ui/gfx/size.h"
12
13#ifndef CC_TEST_PIXEL_TEST_H_
14#define CC_TEST_PIXEL_TEST_H_
15
16namespace cc {
[email protected]63894582013-06-18 18:24:2417class CopyOutputResult;
[email protected]598067a02013-04-29 20:35:0718class DirectRenderer;
[email protected]59fee302013-12-10 17:53:3019class FakeOutputSurfaceClient;
[email protected]a7252f12013-03-15 04:57:3420class OutputSurface;
21class ResourceProvider;
[email protected]59fee302013-12-10 17:53:3022class SoftwareRenderer;
[email protected]a7252f12013-03-15 04:57:3423
[email protected]59fee302013-12-10 17:53:3024class PixelTest : public testing::Test, RendererClient {
[email protected]a7252f12013-03-15 04:57:3425 protected:
26 PixelTest();
27 virtual ~PixelTest();
28
[email protected]b5174d712013-08-28 08:10:4329 enum OffscreenContextOption {
30 NoOffscreenContext,
31 WithOffscreenContext
32 };
33
[email protected]18a70192013-04-26 16:18:2534 bool RunPixelTest(RenderPassList* pass_list,
[email protected]b5174d712013-08-28 08:10:4335 OffscreenContextOption provide_offscreen_context,
[email protected]18a70192013-04-26 16:18:2536 const base::FilePath& ref_file,
37 const PixelComparator& comparator);
[email protected]a7252f12013-03-15 04:57:3438
[email protected]b5174d712013-08-28 08:10:4339 bool RunPixelTestWithReadbackTarget(
40 RenderPassList* pass_list,
41 RenderPass* target,
42 OffscreenContextOption provide_offscreen_context,
43 const base::FilePath& ref_file,
44 const PixelComparator& comparator);
[email protected]6bec38a32013-05-08 23:52:1445
[email protected]573e8e32013-09-09 17:24:3246 LayerTreeSettings settings_;
[email protected]a7252f12013-03-15 04:57:3447 gfx::Size device_viewport_size_;
[email protected]251699b2013-10-09 00:21:2648 bool disable_picture_quad_image_filtering_;
[email protected]f224cc92013-06-06 23:23:3249 class PixelTestRendererClient;
[email protected]59fee302013-12-10 17:53:3050 scoped_ptr<FakeOutputSurfaceClient> output_surface_client_;
[email protected]a7252f12013-03-15 04:57:3451 scoped_ptr<OutputSurface> output_surface_;
52 scoped_ptr<ResourceProvider> resource_provider_;
[email protected]ea468c6c2013-09-10 08:25:1153 scoped_ptr<TextureMailboxDeleter> texture_mailbox_deleter_;
[email protected]598067a02013-04-29 20:35:0754 scoped_ptr<DirectRenderer> renderer_;
[email protected]18a70192013-04-26 16:18:2555 scoped_ptr<SkBitmap> result_bitmap_;
[email protected]59fee302013-12-10 17:53:3056 gfx::Vector2d external_device_viewport_offset_;
57 gfx::Rect external_device_clip_rect_;
[email protected]18a70192013-04-26 16:18:2558
[email protected]bec084292013-05-21 21:31:4459 void SetUpGLRenderer(bool use_skia_gpu_backend);
[email protected]598067a02013-04-29 20:35:0760 void SetUpSoftwareRenderer();
61
[email protected]59fee302013-12-10 17:53:3062 void ForceExpandedViewport(gfx::Size surface_expansion);
63 void ForceViewportOffset(gfx::Vector2d viewport_offset);
[email protected]54af03522013-09-05 00:43:2864 void ForceDeviceClip(gfx::Rect clip);
[email protected]c32a1962013-07-30 19:41:1765 void EnableExternalStencilTest();
[email protected]f224cc92013-06-06 23:23:3266
[email protected]59fee302013-12-10 17:53:3067 // RendererClient implementation.
68 virtual void SetFullRootLayerDamage() OVERRIDE {}
69
[email protected]18a70192013-04-26 16:18:2570 private:
[email protected]63894582013-06-18 18:24:2471 void ReadbackResult(base::Closure quit_run_loop,
72 scoped_ptr<CopyOutputResult> result);
[email protected]18a70192013-04-26 16:18:2573
74 bool PixelsMatchReference(const base::FilePath& ref_file,
75 const PixelComparator& comparator);
[email protected]a7252f12013-03-15 04:57:3476};
77
[email protected]598067a02013-04-29 20:35:0778template<typename RendererType>
79class RendererPixelTest : public PixelTest {
80 public:
81 RendererType* renderer() {
82 return static_cast<RendererType*>(renderer_.get());
83 }
84
[email protected]bec084292013-05-21 21:31:4485 bool UseSkiaGPUBackend() const;
[email protected]f224cc92013-06-06 23:23:3286 bool ExpandedViewport() const;
[email protected]bec084292013-05-21 21:31:4487
[email protected]598067a02013-04-29 20:35:0788 protected:
89 virtual void SetUp() OVERRIDE;
90};
91
[email protected]f224cc92013-06-06 23:23:3292// Wrappers to differentiate renderers where the the output surface and viewport
93// have an externally determined size and offset.
94class GLRendererWithExpandedViewport : public GLRenderer {
95 public:
96 GLRendererWithExpandedViewport(RendererClient* client,
[email protected]573e8e32013-09-09 17:24:3297 const LayerTreeSettings* settings,
98 OutputSurface* output_surface,
99 ResourceProvider* resource_provider,
[email protected]ea468c6c2013-09-10 08:25:11100 TextureMailboxDeleter* texture_mailbox_deleter,
[email protected]573e8e32013-09-09 17:24:32101 int highp_threshold_min)
[email protected]f224cc92013-06-06 23:23:32102 : GLRenderer(client,
[email protected]573e8e32013-09-09 17:24:32103 settings,
[email protected]f224cc92013-06-06 23:23:32104 output_surface,
105 resource_provider,
[email protected]ea468c6c2013-09-10 08:25:11106 texture_mailbox_deleter,
[email protected]f224cc92013-06-06 23:23:32107 highp_threshold_min) {}
108};
109
110class SoftwareRendererWithExpandedViewport : public SoftwareRenderer {
111 public:
112 SoftwareRendererWithExpandedViewport(RendererClient* client,
[email protected]573e8e32013-09-09 17:24:32113 const LayerTreeSettings* settings,
114 OutputSurface* output_surface,
115 ResourceProvider* resource_provider)
116 : SoftwareRenderer(client, settings, output_surface, resource_provider) {}
[email protected]f224cc92013-06-06 23:23:32117};
118
[email protected]598067a02013-04-29 20:35:07119template<>
120inline void RendererPixelTest<GLRenderer>::SetUp() {
[email protected]bec084292013-05-21 21:31:44121 SetUpGLRenderer(false);
[email protected]bec084292013-05-21 21:31:44122}
123
124template<>
125inline bool RendererPixelTest<GLRenderer>::UseSkiaGPUBackend() const {
126 return false;
127}
128
129template<>
[email protected]f224cc92013-06-06 23:23:32130inline bool RendererPixelTest<GLRenderer>::ExpandedViewport() const {
131 return false;
132}
133
134template<>
[email protected]f224cc92013-06-06 23:23:32135inline void RendererPixelTest<GLRendererWithExpandedViewport>::SetUp() {
136 SetUpGLRenderer(false);
[email protected]59fee302013-12-10 17:53:30137 ForceExpandedViewport(gfx::Size(50, 50));
138 ForceViewportOffset(gfx::Vector2d(10, 20));
[email protected]f224cc92013-06-06 23:23:32139}
140
141template <>
142inline bool
143RendererPixelTest<GLRendererWithExpandedViewport>::UseSkiaGPUBackend() const {
144 return false;
145}
146
147template <>
148inline bool
149RendererPixelTest<GLRendererWithExpandedViewport>::ExpandedViewport() const {
150 return true;
151}
152
[email protected]598067a02013-04-29 20:35:07153template<>
154inline void RendererPixelTest<SoftwareRenderer>::SetUp() {
155 SetUpSoftwareRenderer();
156}
157
[email protected]bec084292013-05-21 21:31:44158template<>
159inline bool RendererPixelTest<SoftwareRenderer>::UseSkiaGPUBackend() const {
160 return false;
161}
162
[email protected]f224cc92013-06-06 23:23:32163template <>
164inline bool RendererPixelTest<SoftwareRenderer>::ExpandedViewport() const {
165 return false;
166}
167
168template<>
169inline void RendererPixelTest<SoftwareRendererWithExpandedViewport>::SetUp() {
170 SetUpSoftwareRenderer();
[email protected]59fee302013-12-10 17:53:30171 ForceExpandedViewport(gfx::Size(50, 50));
172 ForceViewportOffset(gfx::Vector2d(10, 20));
[email protected]f224cc92013-06-06 23:23:32173}
174
175template <>
176inline bool RendererPixelTest<
177 SoftwareRendererWithExpandedViewport>::UseSkiaGPUBackend() const {
178 return false;
179}
180
181template <>
182inline bool RendererPixelTest<
183 SoftwareRendererWithExpandedViewport>::ExpandedViewport() const {
184 return true;
185}
186
[email protected]598067a02013-04-29 20:35:07187typedef RendererPixelTest<GLRenderer> GLRendererPixelTest;
[email protected]598067a02013-04-29 20:35:07188typedef RendererPixelTest<SoftwareRenderer> SoftwareRendererPixelTest;
189
[email protected]a7252f12013-03-15 04:57:34190} // namespace cc
191
192#endif // CC_TEST_PIXEL_TEST_H_