// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "base/files/file_util.h" #include "cc/output/gl_renderer.h" #include "cc/output/software_renderer.h" #include "cc/quads/render_pass.h" #include "cc/test/pixel_comparator.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/gfx/geometry/size.h" #include "ui/gl/gl_implementation.h" #ifndef CC_TEST_PIXEL_TEST_H_ #define CC_TEST_PIXEL_TEST_H_ namespace cc { class CopyOutputResult; class DirectRenderer; class FakeOutputSurfaceClient; class OutputSurface; class ResourceProvider; class SoftwareRenderer; class TestGpuMemoryBufferManager; class TestSharedBitmapManager; class PixelTest : public testing::Test, RendererClient { protected: PixelTest(); virtual ~PixelTest(); bool RunPixelTest(RenderPassList* pass_list, const base::FilePath& ref_file, const PixelComparator& comparator); bool RunPixelTestWithReadbackTarget( RenderPassList* pass_list, RenderPass* target, const base::FilePath& ref_file, const PixelComparator& comparator); bool RunPixelTestWithReadbackTargetAndArea(RenderPassList* pass_list, RenderPass* target, const base::FilePath& ref_file, const PixelComparator& comparator, const gfx::Rect* copy_rect); LayerTreeSettings settings_; gfx::Size device_viewport_size_; bool disable_picture_quad_image_filtering_; class PixelTestRendererClient; scoped_ptr output_surface_client_; scoped_ptr output_surface_; scoped_ptr shared_bitmap_manager_; scoped_ptr gpu_memory_buffer_manager_; scoped_ptr main_thread_task_runner_; scoped_ptr resource_provider_; scoped_ptr texture_mailbox_deleter_; scoped_ptr renderer_; scoped_ptr result_bitmap_; gfx::Vector2d external_device_viewport_offset_; gfx::Rect external_device_clip_rect_; void SetUpGLRenderer(bool use_skia_gpu_backend, bool flipped_output_surface); void SetUpSoftwareRenderer(); void ForceExpandedViewport(const gfx::Size& surface_expansion); void ForceViewportOffset(const gfx::Vector2d& viewport_offset); void ForceDeviceClip(const gfx::Rect& clip); void EnableExternalStencilTest(); // RendererClient implementation. void SetFullRootLayerDamage() override {} private: void ReadbackResult(base::Closure quit_run_loop, scoped_ptr result); bool PixelsMatchReference(const base::FilePath& ref_file, const PixelComparator& comparator); scoped_ptr enable_pixel_output_; }; template class RendererPixelTest : public PixelTest { public: RendererType* renderer() { return static_cast(renderer_.get()); } bool UseSkiaGPUBackend() const; bool ExpandedViewport() const; protected: virtual void SetUp() override; }; // Wrappers to differentiate renderers where the the output surface and viewport // have an externally determined size and offset. class GLRendererWithExpandedViewport : public GLRenderer { public: GLRendererWithExpandedViewport(RendererClient* client, const LayerTreeSettings* settings, OutputSurface* output_surface, ResourceProvider* resource_provider, TextureMailboxDeleter* texture_mailbox_deleter, int highp_threshold_min) : GLRenderer(client, settings, output_surface, resource_provider, texture_mailbox_deleter, highp_threshold_min) {} }; class SoftwareRendererWithExpandedViewport : public SoftwareRenderer { public: SoftwareRendererWithExpandedViewport(RendererClient* client, const LayerTreeSettings* settings, OutputSurface* output_surface, ResourceProvider* resource_provider) : SoftwareRenderer(client, settings, output_surface, resource_provider) {} }; class GLRendererWithFlippedSurface : public GLRenderer { public: GLRendererWithFlippedSurface(RendererClient* client, const LayerTreeSettings* settings, OutputSurface* output_surface, ResourceProvider* resource_provider, TextureMailboxDeleter* texture_mailbox_deleter, int highp_threshold_min) : GLRenderer(client, settings, output_surface, resource_provider, texture_mailbox_deleter, highp_threshold_min) {} }; template<> inline void RendererPixelTest::SetUp() { SetUpGLRenderer(false, false); } template<> inline bool RendererPixelTest::UseSkiaGPUBackend() const { return false; } template<> inline bool RendererPixelTest::ExpandedViewport() const { return false; } template<> inline void RendererPixelTest::SetUp() { SetUpGLRenderer(false, false); ForceExpandedViewport(gfx::Size(50, 50)); ForceViewportOffset(gfx::Vector2d(10, 20)); } template <> inline bool RendererPixelTest::UseSkiaGPUBackend() const { return false; } template <> inline bool RendererPixelTest::ExpandedViewport() const { return true; } template <> inline void RendererPixelTest::SetUp() { SetUpGLRenderer(false, true); } template <> inline bool RendererPixelTest::UseSkiaGPUBackend() const { return false; } template <> inline bool RendererPixelTest::ExpandedViewport() const { return true; } template <> inline void RendererPixelTest::SetUp() { SetUpSoftwareRenderer(); } template<> inline bool RendererPixelTest::UseSkiaGPUBackend() const { return false; } template <> inline bool RendererPixelTest::ExpandedViewport() const { return false; } template<> inline void RendererPixelTest::SetUp() { SetUpSoftwareRenderer(); ForceExpandedViewport(gfx::Size(50, 50)); ForceViewportOffset(gfx::Vector2d(10, 20)); } template <> inline bool RendererPixelTest< SoftwareRendererWithExpandedViewport>::UseSkiaGPUBackend() const { return false; } template <> inline bool RendererPixelTest< SoftwareRendererWithExpandedViewport>::ExpandedViewport() const { return true; } typedef RendererPixelTest GLRendererPixelTest; typedef RendererPixelTest SoftwareRendererPixelTest; } // namespace cc #endif // CC_TEST_PIXEL_TEST_H_