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 16namespace cc { 17class CopyOutputResult; 18class DirectRenderer; 19class SoftwareRenderer; 20class OutputSurface; 21class ResourceProvider; 22 23class 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 61template<typename RendererType> 62class 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. 77class 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. 91class 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 103class 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 114template<> 115inline void RendererPixelTest<GLRenderer>::SetUp() { 116 SetUpGLRenderer(false); 117 DCHECK(!renderer()->CanUseSkiaGPUBackend()); 118} 119 120template<> 121inline bool RendererPixelTest<GLRenderer>::UseSkiaGPUBackend() const { 122 return false; 123} 124 125template<> 126inline bool RendererPixelTest<GLRenderer>::ExpandedViewport() const { 127 return false; 128} 129 130template<> 131inline void RendererPixelTest<GLRendererWithSkiaGPUBackend>::SetUp() { 132 SetUpGLRenderer(true); 133 DCHECK(renderer()->CanUseSkiaGPUBackend()); 134} 135 136template <> 137inline bool 138RendererPixelTest<GLRendererWithSkiaGPUBackend>::UseSkiaGPUBackend() const { 139 return true; 140} 141 142template <> 143inline bool RendererPixelTest<GLRendererWithSkiaGPUBackend>::ExpandedViewport() 144 const { 145 return false; 146} 147 148template<> 149inline void RendererPixelTest<GLRendererWithExpandedViewport>::SetUp() { 150 SetUpGLRenderer(false); 151 ForceExpandedViewport(gfx::Size(50, 50), gfx::Vector2d(10, 20)); 152} 153 154template <> 155inline bool 156RendererPixelTest<GLRendererWithExpandedViewport>::UseSkiaGPUBackend() const { 157 return false; 158} 159 160template <> 161inline bool 162RendererPixelTest<GLRendererWithExpandedViewport>::ExpandedViewport() const { 163 return true; 164} 165 166template<> 167inline void RendererPixelTest<SoftwareRenderer>::SetUp() { 168 SetUpSoftwareRenderer(); 169} 170 171template<> 172inline bool RendererPixelTest<SoftwareRenderer>::UseSkiaGPUBackend() const { 173 return false; 174} 175 176template <> 177inline bool RendererPixelTest<SoftwareRenderer>::ExpandedViewport() const { 178 return false; 179} 180 181template<> 182inline void RendererPixelTest<SoftwareRendererWithExpandedViewport>::SetUp() { 183 SetUpSoftwareRenderer(); 184 ForceExpandedViewport(gfx::Size(50, 50), gfx::Vector2d(10, 20)); 185} 186 187template <> 188inline bool RendererPixelTest< 189 SoftwareRendererWithExpandedViewport>::UseSkiaGPUBackend() const { 190 return false; 191} 192 193template <> 194inline bool RendererPixelTest< 195 SoftwareRendererWithExpandedViewport>::ExpandedViewport() const { 196 return true; 197} 198 199typedef RendererPixelTest<GLRenderer> GLRendererPixelTest; 200typedef RendererPixelTest<GLRendererWithSkiaGPUBackend> 201 GLRendererSkiaGPUBackendPixelTest; 202typedef RendererPixelTest<SoftwareRenderer> SoftwareRendererPixelTest; 203 204} // namespace cc 205 206#endif // CC_TEST_PIXEL_TEST_H_ 207