[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] | 59fee30 | 2013-12-10 17:53:30 | [diff] [blame^] | 19 | class FakeOutputSurfaceClient; |
[email protected] | a7252f1 | 2013-03-15 04:57:34 | [diff] [blame] | 20 | class OutputSurface; |
| 21 | class ResourceProvider; |
[email protected] | 59fee30 | 2013-12-10 17:53:30 | [diff] [blame^] | 22 | class SoftwareRenderer; |
[email protected] | a7252f1 | 2013-03-15 04:57:34 | [diff] [blame] | 23 | |
[email protected] | 59fee30 | 2013-12-10 17:53:30 | [diff] [blame^] | 24 | class PixelTest : public testing::Test, RendererClient { |
[email protected] | a7252f1 | 2013-03-15 04:57:34 | [diff] [blame] | 25 | protected: |
| 26 | PixelTest(); |
| 27 | virtual ~PixelTest(); |
| 28 | |
[email protected] | b5174d71 | 2013-08-28 08:10:43 | [diff] [blame] | 29 | enum OffscreenContextOption { |
| 30 | NoOffscreenContext, |
| 31 | WithOffscreenContext |
| 32 | }; |
| 33 | |
[email protected] | 18a7019 | 2013-04-26 16:18:25 | [diff] [blame] | 34 | bool RunPixelTest(RenderPassList* pass_list, |
[email protected] | b5174d71 | 2013-08-28 08:10:43 | [diff] [blame] | 35 | OffscreenContextOption provide_offscreen_context, |
[email protected] | 18a7019 | 2013-04-26 16:18:25 | [diff] [blame] | 36 | const base::FilePath& ref_file, |
| 37 | const PixelComparator& comparator); |
[email protected] | a7252f1 | 2013-03-15 04:57:34 | [diff] [blame] | 38 | |
[email protected] | b5174d71 | 2013-08-28 08:10:43 | [diff] [blame] | 39 | 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] | 6bec38a3 | 2013-05-08 23:52:14 | [diff] [blame] | 45 | |
[email protected] | 573e8e3 | 2013-09-09 17:24:32 | [diff] [blame] | 46 | LayerTreeSettings settings_; |
[email protected] | a7252f1 | 2013-03-15 04:57:34 | [diff] [blame] | 47 | gfx::Size device_viewport_size_; |
[email protected] | 251699b | 2013-10-09 00:21:26 | [diff] [blame] | 48 | bool disable_picture_quad_image_filtering_; |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 49 | class PixelTestRendererClient; |
[email protected] | 59fee30 | 2013-12-10 17:53:30 | [diff] [blame^] | 50 | scoped_ptr<FakeOutputSurfaceClient> output_surface_client_; |
[email protected] | a7252f1 | 2013-03-15 04:57:34 | [diff] [blame] | 51 | scoped_ptr<OutputSurface> output_surface_; |
| 52 | scoped_ptr<ResourceProvider> resource_provider_; |
[email protected] | ea468c6c | 2013-09-10 08:25:11 | [diff] [blame] | 53 | scoped_ptr<TextureMailboxDeleter> texture_mailbox_deleter_; |
[email protected] | 598067a0 | 2013-04-29 20:35:07 | [diff] [blame] | 54 | scoped_ptr<DirectRenderer> renderer_; |
[email protected] | 18a7019 | 2013-04-26 16:18:25 | [diff] [blame] | 55 | scoped_ptr<SkBitmap> result_bitmap_; |
[email protected] | 59fee30 | 2013-12-10 17:53:30 | [diff] [blame^] | 56 | gfx::Vector2d external_device_viewport_offset_; |
| 57 | gfx::Rect external_device_clip_rect_; |
[email protected] | 18a7019 | 2013-04-26 16:18:25 | [diff] [blame] | 58 | |
[email protected] | bec08429 | 2013-05-21 21:31:44 | [diff] [blame] | 59 | void SetUpGLRenderer(bool use_skia_gpu_backend); |
[email protected] | 598067a0 | 2013-04-29 20:35:07 | [diff] [blame] | 60 | void SetUpSoftwareRenderer(); |
| 61 | |
[email protected] | 59fee30 | 2013-12-10 17:53:30 | [diff] [blame^] | 62 | void ForceExpandedViewport(gfx::Size surface_expansion); |
| 63 | void ForceViewportOffset(gfx::Vector2d viewport_offset); |
[email protected] | 54af0352 | 2013-09-05 00:43:28 | [diff] [blame] | 64 | void ForceDeviceClip(gfx::Rect clip); |
[email protected] | c32a196 | 2013-07-30 19:41:17 | [diff] [blame] | 65 | void EnableExternalStencilTest(); |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 66 | |
[email protected] | 59fee30 | 2013-12-10 17:53:30 | [diff] [blame^] | 67 | // RendererClient implementation. |
| 68 | virtual void SetFullRootLayerDamage() OVERRIDE {} |
| 69 | |
[email protected] | 18a7019 | 2013-04-26 16:18:25 | [diff] [blame] | 70 | private: |
[email protected] | 6389458 | 2013-06-18 18:24:24 | [diff] [blame] | 71 | void ReadbackResult(base::Closure quit_run_loop, |
| 72 | scoped_ptr<CopyOutputResult> result); |
[email protected] | 18a7019 | 2013-04-26 16:18:25 | [diff] [blame] | 73 | |
| 74 | bool PixelsMatchReference(const base::FilePath& ref_file, |
| 75 | const PixelComparator& comparator); |
[email protected] | a7252f1 | 2013-03-15 04:57:34 | [diff] [blame] | 76 | }; |
| 77 | |
[email protected] | 598067a0 | 2013-04-29 20:35:07 | [diff] [blame] | 78 | template<typename RendererType> |
| 79 | class RendererPixelTest : public PixelTest { |
| 80 | public: |
| 81 | RendererType* renderer() { |
| 82 | return static_cast<RendererType*>(renderer_.get()); |
| 83 | } |
| 84 | |
[email protected] | bec08429 | 2013-05-21 21:31:44 | [diff] [blame] | 85 | bool UseSkiaGPUBackend() const; |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 86 | bool ExpandedViewport() const; |
[email protected] | bec08429 | 2013-05-21 21:31:44 | [diff] [blame] | 87 | |
[email protected] | 598067a0 | 2013-04-29 20:35:07 | [diff] [blame] | 88 | protected: |
| 89 | virtual void SetUp() OVERRIDE; |
| 90 | }; |
| 91 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 92 | // Wrappers to differentiate renderers where the the output surface and viewport |
| 93 | // have an externally determined size and offset. |
| 94 | class GLRendererWithExpandedViewport : public GLRenderer { |
| 95 | public: |
| 96 | GLRendererWithExpandedViewport(RendererClient* client, |
[email protected] | 573e8e3 | 2013-09-09 17:24:32 | [diff] [blame] | 97 | const LayerTreeSettings* settings, |
| 98 | OutputSurface* output_surface, |
| 99 | ResourceProvider* resource_provider, |
[email protected] | ea468c6c | 2013-09-10 08:25:11 | [diff] [blame] | 100 | TextureMailboxDeleter* texture_mailbox_deleter, |
[email protected] | 573e8e3 | 2013-09-09 17:24:32 | [diff] [blame] | 101 | int highp_threshold_min) |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 102 | : GLRenderer(client, |
[email protected] | 573e8e3 | 2013-09-09 17:24:32 | [diff] [blame] | 103 | settings, |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 104 | output_surface, |
| 105 | resource_provider, |
[email protected] | ea468c6c | 2013-09-10 08:25:11 | [diff] [blame] | 106 | texture_mailbox_deleter, |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 107 | highp_threshold_min) {} |
| 108 | }; |
| 109 | |
| 110 | class SoftwareRendererWithExpandedViewport : public SoftwareRenderer { |
| 111 | public: |
| 112 | SoftwareRendererWithExpandedViewport(RendererClient* client, |
[email protected] | 573e8e3 | 2013-09-09 17:24:32 | [diff] [blame] | 113 | const LayerTreeSettings* settings, |
| 114 | OutputSurface* output_surface, |
| 115 | ResourceProvider* resource_provider) |
| 116 | : SoftwareRenderer(client, settings, output_surface, resource_provider) {} |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 117 | }; |
| 118 | |
[email protected] | 598067a0 | 2013-04-29 20:35:07 | [diff] [blame] | 119 | template<> |
| 120 | inline void RendererPixelTest<GLRenderer>::SetUp() { |
[email protected] | bec08429 | 2013-05-21 21:31:44 | [diff] [blame] | 121 | SetUpGLRenderer(false); |
[email protected] | bec08429 | 2013-05-21 21:31:44 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | template<> |
| 125 | inline bool RendererPixelTest<GLRenderer>::UseSkiaGPUBackend() const { |
| 126 | return false; |
| 127 | } |
| 128 | |
| 129 | template<> |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 130 | inline bool RendererPixelTest<GLRenderer>::ExpandedViewport() const { |
| 131 | return false; |
| 132 | } |
| 133 | |
| 134 | template<> |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 135 | inline void RendererPixelTest<GLRendererWithExpandedViewport>::SetUp() { |
| 136 | SetUpGLRenderer(false); |
[email protected] | 59fee30 | 2013-12-10 17:53:30 | [diff] [blame^] | 137 | ForceExpandedViewport(gfx::Size(50, 50)); |
| 138 | ForceViewportOffset(gfx::Vector2d(10, 20)); |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | template <> |
| 142 | inline bool |
| 143 | RendererPixelTest<GLRendererWithExpandedViewport>::UseSkiaGPUBackend() const { |
| 144 | return false; |
| 145 | } |
| 146 | |
| 147 | template <> |
| 148 | inline bool |
| 149 | RendererPixelTest<GLRendererWithExpandedViewport>::ExpandedViewport() const { |
| 150 | return true; |
| 151 | } |
| 152 | |
[email protected] | 598067a0 | 2013-04-29 20:35:07 | [diff] [blame] | 153 | template<> |
| 154 | inline void RendererPixelTest<SoftwareRenderer>::SetUp() { |
| 155 | SetUpSoftwareRenderer(); |
| 156 | } |
| 157 | |
[email protected] | bec08429 | 2013-05-21 21:31:44 | [diff] [blame] | 158 | template<> |
| 159 | inline bool RendererPixelTest<SoftwareRenderer>::UseSkiaGPUBackend() const { |
| 160 | return false; |
| 161 | } |
| 162 | |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 163 | template <> |
| 164 | inline bool RendererPixelTest<SoftwareRenderer>::ExpandedViewport() const { |
| 165 | return false; |
| 166 | } |
| 167 | |
| 168 | template<> |
| 169 | inline void RendererPixelTest<SoftwareRendererWithExpandedViewport>::SetUp() { |
| 170 | SetUpSoftwareRenderer(); |
[email protected] | 59fee30 | 2013-12-10 17:53:30 | [diff] [blame^] | 171 | ForceExpandedViewport(gfx::Size(50, 50)); |
| 172 | ForceViewportOffset(gfx::Vector2d(10, 20)); |
[email protected] | f224cc9 | 2013-06-06 23:23:32 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | template <> |
| 176 | inline bool RendererPixelTest< |
| 177 | SoftwareRendererWithExpandedViewport>::UseSkiaGPUBackend() const { |
| 178 | return false; |
| 179 | } |
| 180 | |
| 181 | template <> |
| 182 | inline bool RendererPixelTest< |
| 183 | SoftwareRendererWithExpandedViewport>::ExpandedViewport() const { |
| 184 | return true; |
| 185 | } |
| 186 | |
[email protected] | 598067a0 | 2013-04-29 20:35:07 | [diff] [blame] | 187 | typedef RendererPixelTest<GLRenderer> GLRendererPixelTest; |
[email protected] | 598067a0 | 2013-04-29 20:35:07 | [diff] [blame] | 188 | typedef RendererPixelTest<SoftwareRenderer> SoftwareRendererPixelTest; |
| 189 | |
[email protected] | a7252f1 | 2013-03-15 04:57:34 | [diff] [blame] | 190 | } // namespace cc |
| 191 | |
| 192 | #endif // CC_TEST_PIXEL_TEST_H_ |