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