Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: cc/test/pixel_test.cc

Issue 15579002: Implement transform/clip support for Android WebView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Turn on fuzzy comparator for new SoftwareRenderer tests Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/test/pixel_test.h" 5 #include "cc/test/pixel_test.h"
6 6
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "cc/output/compositor_frame_metadata.h" 9 #include "cc/output/compositor_frame_metadata.h"
10 #include "cc/output/copy_output_request.h" 10 #include "cc/output/copy_output_request.h"
11 #include "cc/output/gl_renderer.h" 11 #include "cc/output/gl_renderer.h"
12 #include "cc/output/output_surface.h" 12 #include "cc/output/output_surface.h"
13 #include "cc/output/software_renderer.h" 13 #include "cc/output/software_renderer.h"
14 #include "cc/resources/resource_provider.h" 14 #include "cc/resources/resource_provider.h"
15 #include "cc/test/paths.h" 15 #include "cc/test/paths.h"
16 #include "cc/test/pixel_test_utils.h" 16 #include "cc/test/pixel_test_utils.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "ui/gl/gl_implementation.h" 18 #include "ui/gl/gl_implementation.h"
19 #include "webkit/common/gpu/context_provider_in_process.h" 19 #include "webkit/common/gpu/context_provider_in_process.h"
20 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl. h" 20 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl. h"
21 21
22 namespace cc { 22 namespace cc {
23 23
24 class PixelTest::PixelTestRendererClient : public RendererClient { 24 class PixelTest::PixelTestRendererClient : public RendererClient {
25 public: 25 public:
26 explicit PixelTestRendererClient(gfx::Size device_viewport_size) 26 explicit PixelTestRendererClient(gfx::Rect device_viewport)
27 : device_viewport_size_(device_viewport_size) {} 27 : device_viewport_(device_viewport) {}
28 28
29 // RendererClient implementation. 29 // RendererClient implementation.
30 virtual gfx::Size DeviceViewportSize() const OVERRIDE { 30 virtual gfx::Rect DeviceViewport() const OVERRIDE {
31 return device_viewport_size_; 31 return device_viewport_ + test_expansion_offset_;
32 } 32 }
33 virtual float DeviceScaleFactor() const OVERRIDE { 33 virtual float DeviceScaleFactor() const OVERRIDE {
34 return 1.f; 34 return 1.f;
35 } 35 }
36 virtual const LayerTreeSettings& Settings() const OVERRIDE { 36 virtual const LayerTreeSettings& Settings() const OVERRIDE {
37 return settings_; 37 return settings_;
38 } 38 }
39 virtual void SetFullRootLayerDamage() OVERRIDE {} 39 virtual void SetFullRootLayerDamage() OVERRIDE {}
40 virtual void SetManagedMemoryPolicy( 40 virtual void SetManagedMemoryPolicy(
41 const ManagedMemoryPolicy& policy) OVERRIDE {} 41 const ManagedMemoryPolicy& policy) OVERRIDE {}
42 virtual void EnforceManagedMemoryPolicy( 42 virtual void EnforceManagedMemoryPolicy(
43 const ManagedMemoryPolicy& policy) OVERRIDE {} 43 const ManagedMemoryPolicy& policy) OVERRIDE {}
44 virtual bool HasImplThread() const OVERRIDE { return false; } 44 virtual bool HasImplThread() const OVERRIDE { return false; }
45 virtual bool ShouldClearRootRenderPass() const OVERRIDE { return true; } 45 virtual bool ShouldClearRootRenderPass() const OVERRIDE { return true; }
46 virtual CompositorFrameMetadata MakeCompositorFrameMetadata() const 46 virtual CompositorFrameMetadata MakeCompositorFrameMetadata() const
47 OVERRIDE { 47 OVERRIDE {
48 return CompositorFrameMetadata(); 48 return CompositorFrameMetadata();
49 } 49 }
50 virtual bool AllowPartialSwap() const OVERRIDE { 50 virtual bool AllowPartialSwap() const OVERRIDE {
51 return true; 51 return true;
52 } 52 }
53 53
54 void SetTestExpansionOffset(gfx::Vector2d test_expansion_offset) {
55 test_expansion_offset_ = test_expansion_offset;
56 }
57
54 private: 58 private:
55 gfx::Size device_viewport_size_; 59 gfx::Rect device_viewport_;
60 gfx::Vector2d test_expansion_offset_;
56 LayerTreeSettings settings_; 61 LayerTreeSettings settings_;
57 }; 62 };
58 63
64 class PixelTest::PixelTestOutputSurface : public OutputSurface {
65 public:
66 explicit PixelTestOutputSurface(
67 scoped_ptr<WebKit::WebGraphicsContext3D> context3d)
68 : OutputSurface(context3d.Pass()) {}
69 explicit PixelTestOutputSurface(
70 scoped_ptr<cc::SoftwareOutputDevice> software_device)
71 : OutputSurface(software_device.Pass()) {}
72 virtual void Reshape(gfx::Size size, float scale_factor) OVERRIDE {
73 OutputSurface::Reshape(
74 gfx::Size(size.width() + test_expansion_size_.width(),
75 size.height() + test_expansion_size_.height()),
76 scale_factor);
77 }
78
79 void SetTestExpansionSize(gfx::Size test_expansion_size) {
80 test_expansion_size_ = test_expansion_size;
81 }
82
83 private:
84 gfx::Size test_expansion_size_;
85 };
86
87 class PixelTestSoftwareOutputDevice : public SoftwareOutputDevice {
88 public:
89 PixelTestSoftwareOutputDevice() {}
90 virtual void Resize(gfx::Size size) OVERRIDE {
91 SoftwareOutputDevice::Resize(
92 gfx::Size(size.width() + test_expansion_size_.width(),
93 size.height() + test_expansion_size_.height()));
94 }
95
96 void SetTestExpansionSize(gfx::Size test_expansion_size) {
97 test_expansion_size_ = test_expansion_size;
98 }
99
100 private:
101 gfx::Size test_expansion_size_;
102 };
103
59 PixelTest::PixelTest() 104 PixelTest::PixelTest()
60 : device_viewport_size_(gfx::Size(200, 200)), 105 : device_viewport_size_(gfx::Size(200, 200)),
61 fake_client_(new PixelTestRendererClient(device_viewport_size_)) {} 106 fake_client_(
107 new PixelTestRendererClient(gfx::Rect(device_viewport_size_))) {}
62 108
63 PixelTest::~PixelTest() {} 109 PixelTest::~PixelTest() {}
64 110
65 bool PixelTest::RunPixelTest(RenderPassList* pass_list, 111 bool PixelTest::RunPixelTest(RenderPassList* pass_list,
66 const base::FilePath& ref_file, 112 const base::FilePath& ref_file,
67 const PixelComparator& comparator) { 113 const PixelComparator& comparator) {
68 return RunPixelTestWithReadbackTarget(pass_list, 114 return RunPixelTestWithReadbackTarget(pass_list,
69 pass_list->back(), 115 pass_list->back(),
70 ref_file, 116 ref_file,
71 comparator); 117 comparator);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 } 164 }
119 165
120 void PixelTest::SetUpGLRenderer(bool use_skia_gpu_backend) { 166 void PixelTest::SetUpGLRenderer(bool use_skia_gpu_backend) {
121 CHECK(fake_client_); 167 CHECK(fake_client_);
122 CHECK(gfx::InitializeGLBindings(gfx::kGLImplementationOSMesaGL)); 168 CHECK(gfx::InitializeGLBindings(gfx::kGLImplementationOSMesaGL));
123 169
124 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; 170 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl;
125 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context3d( 171 scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context3d(
126 WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext( 172 WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext(
127 WebKit::WebGraphicsContext3D::Attributes())); 173 WebKit::WebGraphicsContext3D::Attributes()));
128 output_surface_.reset(new OutputSurface( 174 output_surface_.reset(new PixelTestOutputSurface(
129 context3d.PassAs<WebKit::WebGraphicsContext3D>())); 175 context3d.PassAs<WebKit::WebGraphicsContext3D>()));
130 resource_provider_ = ResourceProvider::Create(output_surface_.get(), 0); 176 resource_provider_ = ResourceProvider::Create(output_surface_.get(), 0);
131 renderer_ = GLRenderer::Create(fake_client_.get(), 177 renderer_ = GLRenderer::Create(fake_client_.get(),
132 output_surface_.get(), 178 output_surface_.get(),
133 resource_provider_.get(), 179 resource_provider_.get(),
134 0, 180 0,
135 use_skia_gpu_backend).PassAs<DirectRenderer>(); 181 use_skia_gpu_backend).PassAs<DirectRenderer>();
136 182
137 scoped_refptr<webkit::gpu::ContextProviderInProcess> offscreen_contexts = 183 scoped_refptr<webkit::gpu::ContextProviderInProcess> offscreen_contexts =
138 webkit::gpu::ContextProviderInProcess::Create(); 184 webkit::gpu::ContextProviderInProcess::Create();
139 ASSERT_TRUE(offscreen_contexts->BindToCurrentThread()); 185 ASSERT_TRUE(offscreen_contexts->BindToCurrentThread());
140 resource_provider_->set_offscreen_context_provider(offscreen_contexts); 186 resource_provider_->set_offscreen_context_provider(offscreen_contexts);
141 } 187 }
142 188
189 void PixelTest::ForceExpandedViewport(gfx::Size surface_expansion,
190 gfx::Vector2d viewport_offset) {
191 static_cast<PixelTestOutputSurface*>(output_surface_.get())
192 ->SetTestExpansionSize(surface_expansion);
193 fake_client_->SetTestExpansionOffset(viewport_offset);
194 SoftwareOutputDevice* device = output_surface_->software_device();
195 if (device) {
196 static_cast<PixelTestSoftwareOutputDevice*>(device)
197 ->SetTestExpansionSize(surface_expansion);
198 }
199 }
200
143 void PixelTest::SetUpSoftwareRenderer() { 201 void PixelTest::SetUpSoftwareRenderer() {
144 CHECK(fake_client_); 202 CHECK(fake_client_);
145 203
146 scoped_ptr<SoftwareOutputDevice> device(new SoftwareOutputDevice()); 204 scoped_ptr<SoftwareOutputDevice> device(new PixelTestSoftwareOutputDevice());
147 output_surface_.reset(new OutputSurface(device.Pass())); 205 output_surface_.reset(new PixelTestOutputSurface(device.Pass()));
148 resource_provider_ = ResourceProvider::Create(output_surface_.get(), 0); 206 resource_provider_ = ResourceProvider::Create(output_surface_.get(), 0);
149 renderer_ = SoftwareRenderer::Create( 207 renderer_ = SoftwareRenderer::Create(
150 fake_client_.get(), 208 fake_client_.get(),
151 output_surface_.get(), 209 output_surface_.get(),
152 resource_provider_.get()).PassAs<DirectRenderer>(); 210 resource_provider_.get()).PassAs<DirectRenderer>();
153 } 211 }
154 212
155 } // namespace cc 213 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698