blob: e3476bf94554da0e50a2eacef8d55b34665f906b [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]a7252f12013-03-15 04:57:3445 gfx::Size device_viewport_size_;
[email protected]f224cc92013-06-06 23:23:3246 class PixelTestRendererClient;
[email protected]a7252f12013-03-15 04:57:3447 scoped_ptr<OutputSurface> output_surface_;
48 scoped_ptr<ResourceProvider> resource_provider_;
[email protected]a7252f12013-03-15 04:57:3449 scoped_ptr<PixelTestRendererClient> fake_client_;
[email protected]598067a02013-04-29 20:35:0750 scoped_ptr<DirectRenderer> renderer_;
[email protected]18a70192013-04-26 16:18:2551 scoped_ptr<SkBitmap> result_bitmap_;
52
[email protected]bec084292013-05-21 21:31:4453 void SetUpGLRenderer(bool use_skia_gpu_backend);
[email protected]598067a02013-04-29 20:35:0754 void SetUpSoftwareRenderer();
55
[email protected]f224cc92013-06-06 23:23:3256 void ForceExpandedViewport(gfx::Size surface_expansion,
57 gfx::Vector2d viewport_offset);
[email protected]c32a1962013-07-30 19:41:1758 void EnableExternalStencilTest();
[email protected]f224cc92013-06-06 23:23:3259
[email protected]18a70192013-04-26 16:18:2560 private:
[email protected]63894582013-06-18 18:24:2461 void ReadbackResult(base::Closure quit_run_loop,
62 scoped_ptr<CopyOutputResult> result);
[email protected]18a70192013-04-26 16:18:2563
64 bool PixelsMatchReference(const base::FilePath& ref_file,
65 const PixelComparator& comparator);
[email protected]a7252f12013-03-15 04:57:3466};
67
[email protected]598067a02013-04-29 20:35:0768template<typename RendererType>
69class RendererPixelTest : public PixelTest {
70 public:
71 RendererType* renderer() {
72 return static_cast<RendererType*>(renderer_.get());
73 }
74
[email protected]bec084292013-05-21 21:31:4475 bool UseSkiaGPUBackend() const;
[email protected]f224cc92013-06-06 23:23:3276 bool ExpandedViewport() const;
[email protected]bec084292013-05-21 21:31:4477
[email protected]598067a02013-04-29 20:35:0778 protected:
79 virtual void SetUp() OVERRIDE;
80};
81
[email protected]bec084292013-05-21 21:31:4482// A simple wrapper to differentiate a renderer that should use ganesh
83// and one that shouldn't in templates.
84class GLRendererWithSkiaGPUBackend : public GLRenderer {
85 public:
86 GLRendererWithSkiaGPUBackend(RendererClient* client,
87 OutputSurface* output_surface,
88 ResourceProvider* resource_provider,
89 int highp_threshold_min)
90 : GLRenderer(client,
91 output_surface,
92 resource_provider,
93 highp_threshold_min) {}
94};
95
[email protected]f224cc92013-06-06 23:23:3296// Wrappers to differentiate renderers where the the output surface and viewport
97// have an externally determined size and offset.
98class GLRendererWithExpandedViewport : public GLRenderer {
99 public:
100 GLRendererWithExpandedViewport(RendererClient* client,
101 OutputSurface* output_surface,
102 ResourceProvider* resource_provider,
103 int highp_threshold_min)
104 : GLRenderer(client,
105 output_surface,
106 resource_provider,
107 highp_threshold_min) {}
108};
109
110class SoftwareRendererWithExpandedViewport : public SoftwareRenderer {
111 public:
112 SoftwareRendererWithExpandedViewport(RendererClient* client,
113 OutputSurface* output_surface,
114 ResourceProvider* resource_provider)
115 : SoftwareRenderer(client,
116 output_surface,
117 resource_provider) {}
118};
119
120
[email protected]598067a02013-04-29 20:35:07121template<>
122inline void RendererPixelTest<GLRenderer>::SetUp() {
[email protected]bec084292013-05-21 21:31:44123 SetUpGLRenderer(false);
124 DCHECK(!renderer()->CanUseSkiaGPUBackend());
125}
126
127template<>
128inline bool RendererPixelTest<GLRenderer>::UseSkiaGPUBackend() const {
129 return false;
130}
131
132template<>
[email protected]f224cc92013-06-06 23:23:32133inline bool RendererPixelTest<GLRenderer>::ExpandedViewport() const {
134 return false;
135}
136
137template<>
[email protected]bec084292013-05-21 21:31:44138inline void RendererPixelTest<GLRendererWithSkiaGPUBackend>::SetUp() {
139 SetUpGLRenderer(true);
140 DCHECK(renderer()->CanUseSkiaGPUBackend());
141}
142
143template <>
144inline bool
145RendererPixelTest<GLRendererWithSkiaGPUBackend>::UseSkiaGPUBackend() const {
146 return true;
[email protected]598067a02013-04-29 20:35:07147}
148
[email protected]f224cc92013-06-06 23:23:32149template <>
150inline bool RendererPixelTest<GLRendererWithSkiaGPUBackend>::ExpandedViewport()
151 const {
152 return false;
153}
154
155template<>
156inline void RendererPixelTest<GLRendererWithExpandedViewport>::SetUp() {
157 SetUpGLRenderer(false);
158 ForceExpandedViewport(gfx::Size(50, 50), gfx::Vector2d(10, 20));
159}
160
161template <>
162inline bool
163RendererPixelTest<GLRendererWithExpandedViewport>::UseSkiaGPUBackend() const {
164 return false;
165}
166
167template <>
168inline bool
169RendererPixelTest<GLRendererWithExpandedViewport>::ExpandedViewport() const {
170 return true;
171}
172
[email protected]598067a02013-04-29 20:35:07173template<>
174inline void RendererPixelTest<SoftwareRenderer>::SetUp() {
175 SetUpSoftwareRenderer();
176}
177
[email protected]bec084292013-05-21 21:31:44178template<>
179inline bool RendererPixelTest<SoftwareRenderer>::UseSkiaGPUBackend() const {
180 return false;
181}
182
[email protected]f224cc92013-06-06 23:23:32183template <>
184inline bool RendererPixelTest<SoftwareRenderer>::ExpandedViewport() const {
185 return false;
186}
187
188template<>
189inline void RendererPixelTest<SoftwareRendererWithExpandedViewport>::SetUp() {
190 SetUpSoftwareRenderer();
191 ForceExpandedViewport(gfx::Size(50, 50), gfx::Vector2d(10, 20));
192}
193
194template <>
195inline bool RendererPixelTest<
196 SoftwareRendererWithExpandedViewport>::UseSkiaGPUBackend() const {
197 return false;
198}
199
200template <>
201inline bool RendererPixelTest<
202 SoftwareRendererWithExpandedViewport>::ExpandedViewport() const {
203 return true;
204}
205
[email protected]598067a02013-04-29 20:35:07206typedef RendererPixelTest<GLRenderer> GLRendererPixelTest;
[email protected]bec084292013-05-21 21:31:44207typedef RendererPixelTest<GLRendererWithSkiaGPUBackend>
208 GLRendererSkiaGPUBackendPixelTest;
[email protected]598067a02013-04-29 20:35:07209typedef RendererPixelTest<SoftwareRenderer> SoftwareRendererPixelTest;
210
[email protected]a7252f12013-03-15 04:57:34211} // namespace cc
212
213#endif // CC_TEST_PIXEL_TEST_H_