blob: 2ddfd0492ad9068b32dc219f972658170777c79b [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"
[email protected]fe18c772014-02-22 08:08:2312#include "ui/gl/gl_implementation.h"
[email protected]a7252f12013-03-15 04:57:3413
14#ifndef CC_TEST_PIXEL_TEST_H_
15#define CC_TEST_PIXEL_TEST_H_
16
17namespace cc {
[email protected]63894582013-06-18 18:24:2418class CopyOutputResult;
[email protected]598067a02013-04-29 20:35:0719class DirectRenderer;
[email protected]59fee302013-12-10 17:53:3020class FakeOutputSurfaceClient;
[email protected]a7252f12013-03-15 04:57:3421class OutputSurface;
22class ResourceProvider;
[email protected]59fee302013-12-10 17:53:3023class SoftwareRenderer;
[email protected]4e2eb352014-03-20 17:25:4524class SharedBitmapManager;
[email protected]a7252f12013-03-15 04:57:3425
[email protected]59fee302013-12-10 17:53:3026class PixelTest : public testing::Test, RendererClient {
[email protected]a7252f12013-03-15 04:57:3427 protected:
28 PixelTest();
29 virtual ~PixelTest();
30
[email protected]18a70192013-04-26 16:18:2531 bool RunPixelTest(RenderPassList* pass_list,
[email protected]18a70192013-04-26 16:18:2532 const base::FilePath& ref_file,
33 const PixelComparator& comparator);
[email protected]a7252f12013-03-15 04:57:3434
[email protected]b5174d712013-08-28 08:10:4335 bool RunPixelTestWithReadbackTarget(
36 RenderPassList* pass_list,
37 RenderPass* target,
[email protected]b5174d712013-08-28 08:10:4338 const base::FilePath& ref_file,
39 const PixelComparator& comparator);
[email protected]6bec38a32013-05-08 23:52:1440
[email protected]573e8e32013-09-09 17:24:3241 LayerTreeSettings settings_;
[email protected]a7252f12013-03-15 04:57:3442 gfx::Size device_viewport_size_;
[email protected]251699b2013-10-09 00:21:2643 bool disable_picture_quad_image_filtering_;
[email protected]f224cc92013-06-06 23:23:3244 class PixelTestRendererClient;
[email protected]59fee302013-12-10 17:53:3045 scoped_ptr<FakeOutputSurfaceClient> output_surface_client_;
[email protected]a7252f12013-03-15 04:57:3446 scoped_ptr<OutputSurface> output_surface_;
[email protected]4e2eb352014-03-20 17:25:4547 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_;
skyostil3976a3f2014-09-04 22:07:2348 scoped_ptr<BlockingTaskRunner> main_thread_task_runner_;
[email protected]a7252f12013-03-15 04:57:3449 scoped_ptr<ResourceProvider> resource_provider_;
[email protected]ea468c6c2013-09-10 08:25:1150 scoped_ptr<TextureMailboxDeleter> texture_mailbox_deleter_;
[email protected]598067a02013-04-29 20:35:0751 scoped_ptr<DirectRenderer> renderer_;
[email protected]18a70192013-04-26 16:18:2552 scoped_ptr<SkBitmap> result_bitmap_;
[email protected]59fee302013-12-10 17:53:3053 gfx::Vector2d external_device_viewport_offset_;
54 gfx::Rect external_device_clip_rect_;
[email protected]18a70192013-04-26 16:18:2555
[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]64348ea2014-01-29 22:58:2659 void ForceExpandedViewport(const gfx::Size& surface_expansion);
[email protected]243e4f12014-02-05 09:18:4260 void ForceViewportOffset(const gfx::Vector2d& viewport_offset);
[email protected]0023fc72014-01-10 20:05:0661 void ForceDeviceClip(const gfx::Rect& clip);
[email protected]c32a1962013-07-30 19:41:1762 void EnableExternalStencilTest();
[email protected]f224cc92013-06-06 23:23:3263
[email protected]59fee302013-12-10 17:53:3064 // RendererClient implementation.
65 virtual void SetFullRootLayerDamage() OVERRIDE {}
[email protected]59fee302013-12-10 17:53:3066
[email protected]18a70192013-04-26 16:18:2567 private:
[email protected]63894582013-06-18 18:24:2468 void ReadbackResult(base::Closure quit_run_loop,
69 scoped_ptr<CopyOutputResult> result);
[email protected]18a70192013-04-26 16:18:2570
71 bool PixelsMatchReference(const base::FilePath& ref_file,
72 const PixelComparator& comparator);
[email protected]fe18c772014-02-22 08:08:2373
74 scoped_ptr<gfx::DisableNullDrawGLBindings> enable_pixel_output_;
[email protected]a7252f12013-03-15 04:57:3475};
76
[email protected]598067a02013-04-29 20:35:0777template<typename RendererType>
78class RendererPixelTest : public PixelTest {
79 public:
80 RendererType* renderer() {
81 return static_cast<RendererType*>(renderer_.get());
82 }
83
[email protected]bec084292013-05-21 21:31:4484 bool UseSkiaGPUBackend() const;
[email protected]f224cc92013-06-06 23:23:3285 bool ExpandedViewport() const;
[email protected]bec084292013-05-21 21:31:4486
[email protected]598067a02013-04-29 20:35:0787 protected:
88 virtual void SetUp() OVERRIDE;
89};
90
[email protected]f224cc92013-06-06 23:23:3291// Wrappers to differentiate renderers where the the output surface and viewport
92// have an externally determined size and offset.
93class GLRendererWithExpandedViewport : public GLRenderer {
94 public:
95 GLRendererWithExpandedViewport(RendererClient* client,
[email protected]573e8e32013-09-09 17:24:3296 const LayerTreeSettings* settings,
97 OutputSurface* output_surface,
98 ResourceProvider* resource_provider,
[email protected]ea468c6c2013-09-10 08:25:1199 TextureMailboxDeleter* texture_mailbox_deleter,
[email protected]573e8e32013-09-09 17:24:32100 int highp_threshold_min)
[email protected]f224cc92013-06-06 23:23:32101 : GLRenderer(client,
[email protected]573e8e32013-09-09 17:24:32102 settings,
[email protected]f224cc92013-06-06 23:23:32103 output_surface,
104 resource_provider,
[email protected]ea468c6c2013-09-10 08:25:11105 texture_mailbox_deleter,
[email protected]f224cc92013-06-06 23:23:32106 highp_threshold_min) {}
107};
108
109class SoftwareRendererWithExpandedViewport : public SoftwareRenderer {
110 public:
111 SoftwareRendererWithExpandedViewport(RendererClient* client,
[email protected]573e8e32013-09-09 17:24:32112 const LayerTreeSettings* settings,
113 OutputSurface* output_surface,
114 ResourceProvider* resource_provider)
115 : SoftwareRenderer(client, settings, output_surface, resource_provider) {}
[email protected]f224cc92013-06-06 23:23:32116};
117
[email protected]598067a02013-04-29 20:35:07118template<>
119inline void RendererPixelTest<GLRenderer>::SetUp() {
[email protected]bec084292013-05-21 21:31:44120 SetUpGLRenderer(false);
[email protected]bec084292013-05-21 21:31:44121}
122
123template<>
124inline bool RendererPixelTest<GLRenderer>::UseSkiaGPUBackend() const {
125 return false;
126}
127
128template<>
[email protected]f224cc92013-06-06 23:23:32129inline bool RendererPixelTest<GLRenderer>::ExpandedViewport() const {
130 return false;
131}
132
133template<>
[email protected]f224cc92013-06-06 23:23:32134inline void RendererPixelTest<GLRendererWithExpandedViewport>::SetUp() {
135 SetUpGLRenderer(false);
[email protected]59fee302013-12-10 17:53:30136 ForceExpandedViewport(gfx::Size(50, 50));
137 ForceViewportOffset(gfx::Vector2d(10, 20));
[email protected]f224cc92013-06-06 23:23:32138}
139
140template <>
141inline bool
142RendererPixelTest<GLRendererWithExpandedViewport>::UseSkiaGPUBackend() const {
143 return false;
144}
145
146template <>
147inline bool
148RendererPixelTest<GLRendererWithExpandedViewport>::ExpandedViewport() const {
149 return true;
150}
151
[email protected]598067a02013-04-29 20:35:07152template<>
153inline void RendererPixelTest<SoftwareRenderer>::SetUp() {
154 SetUpSoftwareRenderer();
155}
156
[email protected]bec084292013-05-21 21:31:44157template<>
158inline bool RendererPixelTest<SoftwareRenderer>::UseSkiaGPUBackend() const {
159 return false;
160}
161
[email protected]f224cc92013-06-06 23:23:32162template <>
163inline bool RendererPixelTest<SoftwareRenderer>::ExpandedViewport() const {
164 return false;
165}
166
167template<>
168inline void RendererPixelTest<SoftwareRendererWithExpandedViewport>::SetUp() {
169 SetUpSoftwareRenderer();
[email protected]59fee302013-12-10 17:53:30170 ForceExpandedViewport(gfx::Size(50, 50));
171 ForceViewportOffset(gfx::Vector2d(10, 20));
[email protected]f224cc92013-06-06 23:23:32172}
173
174template <>
175inline bool RendererPixelTest<
176 SoftwareRendererWithExpandedViewport>::UseSkiaGPUBackend() const {
177 return false;
178}
179
180template <>
181inline bool RendererPixelTest<
182 SoftwareRendererWithExpandedViewport>::ExpandedViewport() const {
183 return true;
184}
185
[email protected]598067a02013-04-29 20:35:07186typedef RendererPixelTest<GLRenderer> GLRendererPixelTest;
187typedef RendererPixelTest<SoftwareRenderer> SoftwareRendererPixelTest;
188
[email protected]a7252f12013-03-15 04:57:34189} // namespace cc
190
191#endif // CC_TEST_PIXEL_TEST_H_