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