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