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