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" 6 #include "cc/output/gl_renderer.h" 7 #include "cc/output/software_renderer.h" 8 #include "cc/quads/render_pass.h" 9 #include "cc/test/pixel_comparator.h" 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 { 17 class CopyOutputResult; 18 class DirectRenderer; 19 class SoftwareRenderer; 20 class OutputSurface; 21 class ResourceProvider; 22 23 class PixelTest : public testing::Test { 24 protected: 25 PixelTest(); 26 virtual ~PixelTest(); 27 28 bool RunPixelTest(RenderPassList* pass_list, 29 const base::FilePath& ref_file, 30 const PixelComparator& comparator); 31 32 bool RunPixelTestWithReadbackTarget(RenderPassList* pass_list, 33 RenderPass* target, 34 const base::FilePath& ref_file, 35 const PixelComparator& comparator); 36 37 gfx::Size device_viewport_size_; 38 bool disable_picture_quad_image_filtering_; 39 class PixelTestRendererClient; 40 scoped_ptr<OutputSurface> output_surface_; 41 scoped_ptr<ResourceProvider> resource_provider_; 42 scoped_ptr<PixelTestRendererClient> fake_client_; 43 scoped_ptr<DirectRenderer> renderer_; 44 scoped_ptr<SkBitmap> result_bitmap_; 45 46 void SetUpGLRenderer(bool use_skia_gpu_backend); 47 void SetUpSoftwareRenderer(); 48 49 void ForceExpandedViewport(gfx::Size surface_expansion, 50 gfx::Vector2d viewport_offset); 51 void EnableExternalStencilTest(); 52 53 private: 54 void ReadbackResult(base::Closure quit_run_loop, 55 scoped_ptr<CopyOutputResult> result); 56 57 bool PixelsMatchReference(const base::FilePath& ref_file, 58 const PixelComparator& comparator); 59 }; 60 61 template<typename RendererType> 62 class RendererPixelTest : public PixelTest { 63 public: 64 RendererType* renderer() { 65 return static_cast<RendererType*>(renderer_.get()); 66 } 67 68 bool UseSkiaGPUBackend() const; 69 bool ExpandedViewport() const; 70 71 protected: 72 virtual void SetUp() OVERRIDE; 73 }; 74 75 // A simple wrapper to differentiate a renderer that should use ganesh 76 // and one that shouldn't in templates. 77 class GLRendererWithSkiaGPUBackend : public GLRenderer { 78 public: 79 GLRendererWithSkiaGPUBackend(RendererClient* client, 80 OutputSurface* output_surface, 81 ResourceProvider* resource_provider, 82 int highp_threshold_min) 83 : GLRenderer(client, 84 output_surface, 85 resource_provider, 86 highp_threshold_min) {} 87 }; 88 89 // Wrappers to differentiate renderers where the the output surface and viewport 90 // have an externally determined size and offset. 91 class GLRendererWithExpandedViewport : public GLRenderer { 92 public: 93 GLRendererWithExpandedViewport(RendererClient* client, 94 OutputSurface* output_surface, 95 ResourceProvider* resource_provider, 96 int highp_threshold_min) 97 : GLRenderer(client, 98 output_surface, 99 resource_provider, 100 highp_threshold_min) {} 101 }; 102 103 class SoftwareRendererWithExpandedViewport : public SoftwareRenderer { 104 public: 105 SoftwareRendererWithExpandedViewport(RendererClient* client, 106 OutputSurface* output_surface, 107 ResourceProvider* resource_provider) 108 : SoftwareRenderer(client, 109 output_surface, 110 resource_provider) {} 111 }; 112 113 114 template<> 115 inline void RendererPixelTest<GLRenderer>::SetUp() { 116 SetUpGLRenderer(false); 117 DCHECK(!renderer()->CanUseSkiaGPUBackend()); 118 } 119 120 template<> 121 inline bool RendererPixelTest<GLRenderer>::UseSkiaGPUBackend() const { 122 return false; 123 } 124 125 template<> 126 inline bool RendererPixelTest<GLRenderer>::ExpandedViewport() const { 127 return false; 128 } 129 130 template<> 131 inline void RendererPixelTest<GLRendererWithSkiaGPUBackend>::SetUp() { 132 SetUpGLRenderer(true); 133 DCHECK(renderer()->CanUseSkiaGPUBackend()); 134 } 135 136 template <> 137 inline bool 138 RendererPixelTest<GLRendererWithSkiaGPUBackend>::UseSkiaGPUBackend() const { 139 return true; 140 } 141 142 template <> 143 inline bool RendererPixelTest<GLRendererWithSkiaGPUBackend>::ExpandedViewport() 144 const { 145 return false; 146 } 147 148 template<> 149 inline void RendererPixelTest<GLRendererWithExpandedViewport>::SetUp() { 150 SetUpGLRenderer(false); 151 ForceExpandedViewport(gfx::Size(50, 50), gfx::Vector2d(10, 20)); 152 } 153 154 template <> 155 inline bool 156 RendererPixelTest<GLRendererWithExpandedViewport>::UseSkiaGPUBackend() const { 157 return false; 158 } 159 160 template <> 161 inline bool 162 RendererPixelTest<GLRendererWithExpandedViewport>::ExpandedViewport() const { 163 return true; 164 } 165 166 template<> 167 inline void RendererPixelTest<SoftwareRenderer>::SetUp() { 168 SetUpSoftwareRenderer(); 169 } 170 171 template<> 172 inline bool RendererPixelTest<SoftwareRenderer>::UseSkiaGPUBackend() const { 173 return false; 174 } 175 176 template <> 177 inline bool RendererPixelTest<SoftwareRenderer>::ExpandedViewport() const { 178 return false; 179 } 180 181 template<> 182 inline void RendererPixelTest<SoftwareRendererWithExpandedViewport>::SetUp() { 183 SetUpSoftwareRenderer(); 184 ForceExpandedViewport(gfx::Size(50, 50), gfx::Vector2d(10, 20)); 185 } 186 187 template <> 188 inline bool RendererPixelTest< 189 SoftwareRendererWithExpandedViewport>::UseSkiaGPUBackend() const { 190 return false; 191 } 192 193 template <> 194 inline bool RendererPixelTest< 195 SoftwareRendererWithExpandedViewport>::ExpandedViewport() const { 196 return true; 197 } 198 199 typedef RendererPixelTest<GLRenderer> GLRendererPixelTest; 200 typedef RendererPixelTest<GLRendererWithSkiaGPUBackend> 201 GLRendererSkiaGPUBackendPixelTest; 202 typedef RendererPixelTest<SoftwareRenderer> SoftwareRendererPixelTest; 203 204 } // namespace cc 205 206 #endif // CC_TEST_PIXEL_TEST_H_ 207