blob: 6885096864849abb03e4eb16c2cc0b65d9748cbf [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]598067a02013-04-29 20:35:0719class SoftwareRenderer;
[email protected]a7252f12013-03-15 04:57:3420class OutputSurface;
21class ResourceProvider;
22
23class PixelTest : public testing::Test {
24 protected:
25 PixelTest();
26 virtual ~PixelTest();
27
[email protected]b5174d712013-08-28 08:10:4328 enum OffscreenContextOption {
29 NoOffscreenContext,
30 WithOffscreenContext
31 };
32
[email protected]18a70192013-04-26 16:18:2533 bool RunPixelTest(RenderPassList* pass_list,
[email protected]b5174d712013-08-28 08:10:4334 OffscreenContextOption provide_offscreen_context,
[email protected]18a70192013-04-26 16:18:2535 const base::FilePath& ref_file,
36 const PixelComparator& comparator);
[email protected]a7252f12013-03-15 04:57:3437
[email protected]b5174d712013-08-28 08:10:4338 bool RunPixelTestWithReadbackTarget(
39 RenderPassList* pass_list,
40 RenderPass* target,
41 OffscreenContextOption provide_offscreen_context,
42 const base::FilePath& ref_file,
43 const PixelComparator& comparator);
[email protected]6bec38a32013-05-08 23:52:1444
[email protected]573e8e32013-09-09 17:24:3245 LayerTreeSettings settings_;
[email protected]a7252f12013-03-15 04:57:3446 gfx::Size device_viewport_size_;
[email protected]251699b2013-10-09 00:21:2647 bool disable_picture_quad_image_filtering_;
[email protected]f224cc92013-06-06 23:23:3248 class PixelTestRendererClient;
[email protected]a7252f12013-03-15 04:57:3449 scoped_ptr<OutputSurface> output_surface_;
50 scoped_ptr<ResourceProvider> resource_provider_;
[email protected]ea468c6c2013-09-10 08:25:1151 scoped_ptr<TextureMailboxDeleter> texture_mailbox_deleter_;
[email protected]a7252f12013-03-15 04:57:3452 scoped_ptr<PixelTestRendererClient> fake_client_;
[email protected]598067a02013-04-29 20:35:0753 scoped_ptr<DirectRenderer> renderer_;
[email protected]18a70192013-04-26 16:18:2554 scoped_ptr<SkBitmap> result_bitmap_;
55
[email protected]bec084292013-05-21 21:31:4456 void SetUpGLRenderer(bool use_skia_gpu_backend);
[email protected]598067a02013-04-29 20:35:0757 void SetUpSoftwareRenderer();
58
[email protected]f224cc92013-06-06 23:23:3259 void ForceExpandedViewport(gfx::Size surface_expansion,
60 gfx::Vector2d viewport_offset);
[email protected]54af03522013-09-05 00:43:2861 void ForceDeviceClip(gfx::Rect clip);
[email protected]c32a1962013-07-30 19:41:1762 void EnableExternalStencilTest();
[email protected]f224cc92013-06-06 23:23:3263
[email protected]18a70192013-04-26 16:18:2564 private:
[email protected]63894582013-06-18 18:24:2465 void ReadbackResult(base::Closure quit_run_loop,
66 scoped_ptr<CopyOutputResult> result);
[email protected]18a70192013-04-26 16:18:2567
68 bool PixelsMatchReference(const base::FilePath& ref_file,
69 const PixelComparator& comparator);
[email protected]a7252f12013-03-15 04:57:3470};
71
[email protected]598067a02013-04-29 20:35:0772template<typename RendererType>
73class RendererPixelTest : public PixelTest {
74 public:
75 RendererType* renderer() {
76 return static_cast<RendererType*>(renderer_.get());
77 }
78
[email protected]bec084292013-05-21 21:31:4479 bool UseSkiaGPUBackend() const;
[email protected]f224cc92013-06-06 23:23:3280 bool ExpandedViewport() const;
[email protected]bec084292013-05-21 21:31:4481
[email protected]598067a02013-04-29 20:35:0782 protected:
83 virtual void SetUp() OVERRIDE;
84};
85
[email protected]f224cc92013-06-06 23:23:3286// Wrappers to differentiate renderers where the the output surface and viewport
87// have an externally determined size and offset.
88class GLRendererWithExpandedViewport : public GLRenderer {
89 public:
90 GLRendererWithExpandedViewport(RendererClient* client,
[email protected]573e8e32013-09-09 17:24:3291 const LayerTreeSettings* settings,
92 OutputSurface* output_surface,
93 ResourceProvider* resource_provider,
[email protected]ea468c6c2013-09-10 08:25:1194 TextureMailboxDeleter* texture_mailbox_deleter,
[email protected]573e8e32013-09-09 17:24:3295 int highp_threshold_min)
[email protected]f224cc92013-06-06 23:23:3296 : GLRenderer(client,
[email protected]573e8e32013-09-09 17:24:3297 settings,
[email protected]f224cc92013-06-06 23:23:3298 output_surface,
99 resource_provider,
[email protected]ea468c6c2013-09-10 08:25:11100 texture_mailbox_deleter,
[email protected]f224cc92013-06-06 23:23:32101 highp_threshold_min) {}
102};
103
104class SoftwareRendererWithExpandedViewport : public SoftwareRenderer {
105 public:
106 SoftwareRendererWithExpandedViewport(RendererClient* client,
[email protected]573e8e32013-09-09 17:24:32107 const LayerTreeSettings* settings,
108 OutputSurface* output_surface,
109 ResourceProvider* resource_provider)
110 : SoftwareRenderer(client, settings, output_surface, resource_provider) {}
[email protected]f224cc92013-06-06 23:23:32111};
112
[email protected]598067a02013-04-29 20:35:07113template<>
114inline void RendererPixelTest<GLRenderer>::SetUp() {
[email protected]bec084292013-05-21 21:31:44115 SetUpGLRenderer(false);
[email protected]bec084292013-05-21 21:31:44116}
117
118template<>
119inline bool RendererPixelTest<GLRenderer>::UseSkiaGPUBackend() const {
120 return false;
121}
122
123template<>
[email protected]f224cc92013-06-06 23:23:32124inline bool RendererPixelTest<GLRenderer>::ExpandedViewport() const {
125 return false;
126}
127
128template<>
[email protected]f224cc92013-06-06 23:23:32129inline void RendererPixelTest<GLRendererWithExpandedViewport>::SetUp() {
130 SetUpGLRenderer(false);
131 ForceExpandedViewport(gfx::Size(50, 50), gfx::Vector2d(10, 20));
132}
133
134template <>
135inline bool
136RendererPixelTest<GLRendererWithExpandedViewport>::UseSkiaGPUBackend() const {
137 return false;
138}
139
140template <>
141inline bool
142RendererPixelTest<GLRendererWithExpandedViewport>::ExpandedViewport() const {
143 return true;
144}
145
[email protected]598067a02013-04-29 20:35:07146template<>
147inline void RendererPixelTest<SoftwareRenderer>::SetUp() {
148 SetUpSoftwareRenderer();
149}
150
[email protected]bec084292013-05-21 21:31:44151template<>
152inline bool RendererPixelTest<SoftwareRenderer>::UseSkiaGPUBackend() const {
153 return false;
154}
155
[email protected]f224cc92013-06-06 23:23:32156template <>
157inline bool RendererPixelTest<SoftwareRenderer>::ExpandedViewport() const {
158 return false;
159}
160
161template<>
162inline void RendererPixelTest<SoftwareRendererWithExpandedViewport>::SetUp() {
163 SetUpSoftwareRenderer();
164 ForceExpandedViewport(gfx::Size(50, 50), gfx::Vector2d(10, 20));
165}
166
167template <>
168inline bool RendererPixelTest<
169 SoftwareRendererWithExpandedViewport>::UseSkiaGPUBackend() const {
170 return false;
171}
172
173template <>
174inline bool RendererPixelTest<
175 SoftwareRendererWithExpandedViewport>::ExpandedViewport() const {
176 return true;
177}
178
[email protected]598067a02013-04-29 20:35:07179typedef RendererPixelTest<GLRenderer> GLRendererPixelTest;
[email protected]598067a02013-04-29 20:35:07180typedef RendererPixelTest<SoftwareRenderer> SoftwareRendererPixelTest;
181
[email protected]a7252f12013-03-15 04:57:34182} // namespace cc
183
184#endif // CC_TEST_PIXEL_TEST_H_