[email protected] | a7252f1 | 2013-03-15 04:57:34 | [diff] [blame] | 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. |
| 4 | |
| 5 | #include "base/file_util.h" |
[email protected] | bec08429 | 2013-05-21 21:31:44 | [diff] [blame] | 6 | #include "cc/output/gl_renderer.h" |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 7 | #include "cc/output/software_renderer.h" |
[email protected] | 18a7019 | 2013-04-26 16:18:25 | [diff] [blame] | 8 | #include "cc/quads/render_pass.h" |
[email protected] | ca43568 | 2013-03-29 04:09:47 | [diff] [blame] | 9 | #include "cc/test/pixel_comparator.h" |
[email protected] | a7252f1 | 2013-03-15 04:57:34 | [diff] [blame] | 10 | #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 | |
| 16 | namespace cc { |
[email protected] | 6389458 | 2013-06-18 18:24:24 | [diff] [blame] | 17 | class CopyOutputResult; |
[email protected] | 598067a0 | 2013-04-29 20:35:07 | [diff] [blame] | 18 | class DirectRenderer; |
[email protected] | 598067a0 | 2013-04-29 20:35:07 | [diff] [blame] | 19 | class SoftwareRenderer; |
[email protected] | a7252f1 | 2013-03-15 04:57:34 | [diff] [blame] | 20 | class OutputSurface; |
| 21 | class ResourceProvider; |
| 22 | |
| 23 | class PixelTest : public testing::Test { |
| 24 | protected: |
| 25 | PixelTest(); |
| 26 | virtual ~PixelTest(); |
| 27 | |
[email protected] | b5174d71 | 2013-08-28 08:10:43 | [diff] [blame^] | 28 | enum OffscreenContextOption { |
| 29 | NoOffscreenContext, |
| 30 | WithOffscreenContext |
| 31 | }; |
| 32 | |
[email protected] | 18a7019 | 2013-04-26 16:18:25 | [diff] [blame] | 33 | bool RunPixelTest(RenderPassList* pass_list, |
[email protected] | b5174d71 | 2013-08-28 08:10:43 | [diff] [blame^] | 34 | OffscreenContextOption provide_offscreen_context, |
[email protected] | 18a7019 | 2013-04-26 16:18:25 | [diff] [blame] | 35 | const base::FilePath& ref_file, |
| 36 | const PixelComparator& comparator); |
[email protected] | a7252f1 | 2013-03-15 04:57:34 | [diff] [blame] | 37 | |
[email protected] | b5174d71 | 2013-08-28 08:10:43 | [diff] [blame^] | 38 | 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] | 6bec38a3 | 2013-05-08 23:52:14 | [diff] [blame] | 44 | |
[email protected] | a7252f1 | 2013-03-15 04:57:34 | [diff] [blame] | 45 | gfx::Size device_viewport_size_; |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 46 | class PixelTestRendererClient; |
[email protected] | a7252f1 | 2013-03-15 04:57:34 | [diff] [blame] | 47 | scoped_ptr<OutputSurface> output_surface_; |
| 48 | scoped_ptr<ResourceProvider> resource_provider_; |
[email protected] | a7252f1 | 2013-03-15 04:57:34 | [diff] [blame] | 49 | scoped_ptr<PixelTestRendererClient> fake_client_; |
[email protected] | 598067a0 | 2013-04-29 20:35:07 | [diff] [blame] | 50 | scoped_ptr<DirectRenderer> renderer_; |
[email protected] | 18a7019 | 2013-04-26 16:18:25 | [diff] [blame] | 51 | scoped_ptr<SkBitmap> result_bitmap_; |
| 52 | |
[email protected] | bec08429 | 2013-05-21 21:31:44 | [diff] [blame] | 53 | void SetUpGLRenderer(bool use_skia_gpu_backend); |
[email protected] | 598067a0 | 2013-04-29 20:35:07 | [diff] [blame] | 54 | void SetUpSoftwareRenderer(); |
| 55 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 56 | void ForceExpandedViewport(gfx::Size surface_expansion, |
| 57 | gfx::Vector2d viewport_offset); |
[email protected] | c32a196 | 2013-07-30 19:41:17 | [diff] [blame] | 58 | void EnableExternalStencilTest(); |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 59 | |
[email protected] | 18a7019 | 2013-04-26 16:18:25 | [diff] [blame] | 60 | private: |
[email protected] | 6389458 | 2013-06-18 18:24:24 | [diff] [blame] | 61 | void ReadbackResult(base::Closure quit_run_loop, |
| 62 | scoped_ptr<CopyOutputResult> result); |
[email protected] | 18a7019 | 2013-04-26 16:18:25 | [diff] [blame] | 63 | |
| 64 | bool PixelsMatchReference(const base::FilePath& ref_file, |
| 65 | const PixelComparator& comparator); |
[email protected] | a7252f1 | 2013-03-15 04:57:34 | [diff] [blame] | 66 | }; |
| 67 | |
[email protected] | 598067a0 | 2013-04-29 20:35:07 | [diff] [blame] | 68 | template<typename RendererType> |
| 69 | class RendererPixelTest : public PixelTest { |
| 70 | public: |
| 71 | RendererType* renderer() { |
| 72 | return static_cast<RendererType*>(renderer_.get()); |
| 73 | } |
| 74 | |
[email protected] | bec08429 | 2013-05-21 21:31:44 | [diff] [blame] | 75 | bool UseSkiaGPUBackend() const; |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 76 | bool ExpandedViewport() const; |
[email protected] | bec08429 | 2013-05-21 21:31:44 | [diff] [blame] | 77 | |
[email protected] | 598067a0 | 2013-04-29 20:35:07 | [diff] [blame] | 78 | protected: |
| 79 | virtual void SetUp() OVERRIDE; |
| 80 | }; |
| 81 | |
[email protected] | bec08429 | 2013-05-21 21:31:44 | [diff] [blame] | 82 | // A simple wrapper to differentiate a renderer that should use ganesh |
| 83 | // and one that shouldn't in templates. |
| 84 | class 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] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 96 | // Wrappers to differentiate renderers where the the output surface and viewport |
| 97 | // have an externally determined size and offset. |
| 98 | class 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 | |
| 110 | class 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] | 598067a0 | 2013-04-29 20:35:07 | [diff] [blame] | 121 | template<> |
| 122 | inline void RendererPixelTest<GLRenderer>::SetUp() { |
[email protected] | bec08429 | 2013-05-21 21:31:44 | [diff] [blame] | 123 | SetUpGLRenderer(false); |
| 124 | DCHECK(!renderer()->CanUseSkiaGPUBackend()); |
| 125 | } |
| 126 | |
| 127 | template<> |
| 128 | inline bool RendererPixelTest<GLRenderer>::UseSkiaGPUBackend() const { |
| 129 | return false; |
| 130 | } |
| 131 | |
| 132 | template<> |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 133 | inline bool RendererPixelTest<GLRenderer>::ExpandedViewport() const { |
| 134 | return false; |
| 135 | } |
| 136 | |
| 137 | template<> |
[email protected] | bec08429 | 2013-05-21 21:31:44 | [diff] [blame] | 138 | inline void RendererPixelTest<GLRendererWithSkiaGPUBackend>::SetUp() { |
| 139 | SetUpGLRenderer(true); |
| 140 | DCHECK(renderer()->CanUseSkiaGPUBackend()); |
| 141 | } |
| 142 | |
| 143 | template <> |
| 144 | inline bool |
| 145 | RendererPixelTest<GLRendererWithSkiaGPUBackend>::UseSkiaGPUBackend() const { |
| 146 | return true; |
[email protected] | 598067a0 | 2013-04-29 20:35:07 | [diff] [blame] | 147 | } |
| 148 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 149 | template <> |
| 150 | inline bool RendererPixelTest<GLRendererWithSkiaGPUBackend>::ExpandedViewport() |
| 151 | const { |
| 152 | return false; |
| 153 | } |
| 154 | |
| 155 | template<> |
| 156 | inline void RendererPixelTest<GLRendererWithExpandedViewport>::SetUp() { |
| 157 | SetUpGLRenderer(false); |
| 158 | ForceExpandedViewport(gfx::Size(50, 50), gfx::Vector2d(10, 20)); |
| 159 | } |
| 160 | |
| 161 | template <> |
| 162 | inline bool |
| 163 | RendererPixelTest<GLRendererWithExpandedViewport>::UseSkiaGPUBackend() const { |
| 164 | return false; |
| 165 | } |
| 166 | |
| 167 | template <> |
| 168 | inline bool |
| 169 | RendererPixelTest<GLRendererWithExpandedViewport>::ExpandedViewport() const { |
| 170 | return true; |
| 171 | } |
| 172 | |
[email protected] | 598067a0 | 2013-04-29 20:35:07 | [diff] [blame] | 173 | template<> |
| 174 | inline void RendererPixelTest<SoftwareRenderer>::SetUp() { |
| 175 | SetUpSoftwareRenderer(); |
| 176 | } |
| 177 | |
[email protected] | bec08429 | 2013-05-21 21:31:44 | [diff] [blame] | 178 | template<> |
| 179 | inline bool RendererPixelTest<SoftwareRenderer>::UseSkiaGPUBackend() const { |
| 180 | return false; |
| 181 | } |
| 182 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 183 | template <> |
| 184 | inline bool RendererPixelTest<SoftwareRenderer>::ExpandedViewport() const { |
| 185 | return false; |
| 186 | } |
| 187 | |
| 188 | template<> |
| 189 | inline void RendererPixelTest<SoftwareRendererWithExpandedViewport>::SetUp() { |
| 190 | SetUpSoftwareRenderer(); |
| 191 | ForceExpandedViewport(gfx::Size(50, 50), gfx::Vector2d(10, 20)); |
| 192 | } |
| 193 | |
| 194 | template <> |
| 195 | inline bool RendererPixelTest< |
| 196 | SoftwareRendererWithExpandedViewport>::UseSkiaGPUBackend() const { |
| 197 | return false; |
| 198 | } |
| 199 | |
| 200 | template <> |
| 201 | inline bool RendererPixelTest< |
| 202 | SoftwareRendererWithExpandedViewport>::ExpandedViewport() const { |
| 203 | return true; |
| 204 | } |
| 205 | |
[email protected] | 598067a0 | 2013-04-29 20:35:07 | [diff] [blame] | 206 | typedef RendererPixelTest<GLRenderer> GLRendererPixelTest; |
[email protected] | bec08429 | 2013-05-21 21:31:44 | [diff] [blame] | 207 | typedef RendererPixelTest<GLRendererWithSkiaGPUBackend> |
| 208 | GLRendererSkiaGPUBackendPixelTest; |
[email protected] | 598067a0 | 2013-04-29 20:35:07 | [diff] [blame] | 209 | typedef RendererPixelTest<SoftwareRenderer> SoftwareRendererPixelTest; |
| 210 | |
[email protected] | a7252f1 | 2013-03-15 04:57:34 | [diff] [blame] | 211 | } // namespace cc |
| 212 | |
| 213 | #endif // CC_TEST_PIXEL_TEST_H_ |