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

Side by Side Diff: cc/output/direct_renderer.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
« no previous file with comments | « cc/output/direct_renderer.h ('k') | cc/output/gl_renderer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/output/direct_renderer.h" 5 #include "cc/output/direct_renderer.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 // static 72 // static
73 void DirectRenderer::QuadRectTransform(gfx::Transform* quad_rect_transform, 73 void DirectRenderer::QuadRectTransform(gfx::Transform* quad_rect_transform,
74 const gfx::Transform& quad_transform, 74 const gfx::Transform& quad_transform,
75 const gfx::RectF& quad_rect) { 75 const gfx::RectF& quad_rect) {
76 *quad_rect_transform = quad_transform; 76 *quad_rect_transform = quad_transform;
77 quad_rect_transform->Translate(0.5 * quad_rect.width() + quad_rect.x(), 77 quad_rect_transform->Translate(0.5 * quad_rect.width() + quad_rect.x(),
78 0.5 * quad_rect.height() + quad_rect.y()); 78 0.5 * quad_rect.height() + quad_rect.y());
79 quad_rect_transform->Scale(quad_rect.width(), quad_rect.height()); 79 quad_rect_transform->Scale(quad_rect.width(), quad_rect.height());
80 } 80 }
81 81
82 // static 82 void DirectRenderer::InitializeViewport(DrawingFrame* frame,
83 void DirectRenderer::InitializeMatrices(DrawingFrame* frame,
84 gfx::Rect draw_rect, 83 gfx::Rect draw_rect,
84 gfx::Rect viewport_rect,
85 gfx::Size surface_size,
85 bool flip_y) { 86 bool flip_y) {
87 DCHECK_GE(viewport_rect.x(), 0);
88 DCHECK_GE(viewport_rect.y(), 0);
89 DCHECK_LE(viewport_rect.right(), surface_size.width());
90 DCHECK_LE(viewport_rect.bottom(), surface_size.height());
86 if (flip_y) { 91 if (flip_y) {
87 frame->projection_matrix = OrthoProjectionMatrix(draw_rect.x(), 92 frame->projection_matrix = OrthoProjectionMatrix(draw_rect.x(),
88 draw_rect.right(), 93 draw_rect.right(),
89 draw_rect.bottom(), 94 draw_rect.bottom(),
90 draw_rect.y()); 95 draw_rect.y());
91 } else { 96 } else {
92 frame->projection_matrix = OrthoProjectionMatrix(draw_rect.x(), 97 frame->projection_matrix = OrthoProjectionMatrix(draw_rect.x(),
93 draw_rect.right(), 98 draw_rect.right(),
94 draw_rect.y(), 99 draw_rect.y(),
95 draw_rect.bottom()); 100 draw_rect.bottom());
96 } 101 }
97 frame->window_matrix = 102
98 window_matrix(0, 0, draw_rect.width(), draw_rect.height()); 103 gfx::Rect window_rect = viewport_rect;
104 if (flip_y)
105 window_rect.set_y(surface_size.height() - viewport_rect.bottom());
106 frame->window_matrix = window_matrix(window_rect.x(),
107 window_rect.y(),
108 window_rect.width(),
109 window_rect.height());
110 SetDrawViewport(window_rect);
111
99 frame->flipped_y = flip_y; 112 frame->flipped_y = flip_y;
113
114 current_draw_rect_ = draw_rect;
115 current_viewport_rect_ = viewport_rect;
116 current_surface_size_ = surface_size;
100 } 117 }
101 118
102 // static 119 gfx::Rect DirectRenderer::MoveFromDrawToWindowSpace(
103 gfx::Rect DirectRenderer::MoveScissorToWindowSpace( 120 const gfx::RectF& draw_rect, bool flip_y) const {
104 const DrawingFrame* frame, const gfx::RectF& scissor_rect) { 121 gfx::Rect window_rect = gfx::ToEnclosingRect(draw_rect);
105 gfx::Rect scissor_rect_in_canvas_space = gfx::ToEnclosingRect(scissor_rect); 122 window_rect -= current_draw_rect_.OffsetFromOrigin();
106 // The scissor coordinates must be supplied in viewport space so we need to 123 window_rect += current_viewport_rect_.OffsetFromOrigin();
107 // offset by the relative position of the top left corner of the current 124 if (flip_y)
108 // render pass. 125 window_rect.set_y(current_surface_size_.height() - window_rect.bottom());
109 gfx::Rect framebuffer_output_rect = frame->current_render_pass->output_rect; 126 return window_rect;
110 scissor_rect_in_canvas_space.set_x(
111 scissor_rect_in_canvas_space.x() - framebuffer_output_rect.x());
112 if (frame->flipped_y && !frame->current_texture) {
113 scissor_rect_in_canvas_space.set_y(
114 framebuffer_output_rect.height() -
115 (scissor_rect_in_canvas_space.bottom() - framebuffer_output_rect.y()));
116 } else {
117 scissor_rect_in_canvas_space.set_y(
118 scissor_rect_in_canvas_space.y() - framebuffer_output_rect.y());
119 }
120 return scissor_rect_in_canvas_space;
121 } 127 }
122 128
123 DirectRenderer::DirectRenderer(RendererClient* client, 129 DirectRenderer::DirectRenderer(RendererClient* client,
130 OutputSurface* output_surface,
124 ResourceProvider* resource_provider) 131 ResourceProvider* resource_provider)
125 : Renderer(client), 132 : Renderer(client),
133 output_surface_(output_surface),
126 resource_provider_(resource_provider) {} 134 resource_provider_(resource_provider) {}
127 135
128 DirectRenderer::~DirectRenderer() {} 136 DirectRenderer::~DirectRenderer() {}
129 137
130 bool DirectRenderer::CanReadPixels() const { return true; } 138 bool DirectRenderer::CanReadPixels() const { return true; }
131 139
132 void DirectRenderer::SetEnlargePassTextureAmountForTesting( 140 void DirectRenderer::SetEnlargePassTextureAmountForTesting(
133 gfx::Vector2d amount) { 141 gfx::Vector2d amount) {
134 enlarge_pass_texture_amount_ = amount; 142 enlarge_pass_texture_amount_ = amount;
135 } 143 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 render_passes_in_draw_order->size()); 198 render_passes_in_draw_order->size());
191 199
192 const RenderPass* root_render_pass = render_passes_in_draw_order->back(); 200 const RenderPass* root_render_pass = render_passes_in_draw_order->back();
193 DCHECK(root_render_pass); 201 DCHECK(root_render_pass);
194 202
195 DrawingFrame frame; 203 DrawingFrame frame;
196 frame.root_render_pass = root_render_pass; 204 frame.root_render_pass = root_render_pass;
197 frame.root_damage_rect = 205 frame.root_damage_rect =
198 Capabilities().using_partial_swap && client_->AllowPartialSwap() ? 206 Capabilities().using_partial_swap && client_->AllowPartialSwap() ?
199 root_render_pass->damage_rect : root_render_pass->output_rect; 207 root_render_pass->damage_rect : root_render_pass->output_rect;
200 frame.root_damage_rect.Intersect(gfx::Rect(ViewportSize())); 208 frame.root_damage_rect.Intersect(gfx::Rect(client_->DeviceViewport().size()));
209
210 // Only reshape when we know we are going to draw. Otherwise, the reshape
211 // can leave the window at the wrong size if we never draw and the proper
212 // viewport size is never set.
213 output_surface_->Reshape(client_->DeviceViewport().size(),
214 client_->DeviceScaleFactor());
piman 2013/06/10 22:41:43 Note: this change triggered crbug.com/248213 becau
aelias_OOO_until_Jul13 2013/06/10 22:49:10 Sorry about that. This is probably due to the ord
201 215
202 BeginDrawingFrame(&frame); 216 BeginDrawingFrame(&frame);
203 for (size_t i = 0; i < render_passes_in_draw_order->size(); ++i) { 217 for (size_t i = 0; i < render_passes_in_draw_order->size(); ++i) {
204 RenderPass* pass = render_passes_in_draw_order->at(i); 218 RenderPass* pass = render_passes_in_draw_order->at(i);
205 DrawRenderPass(&frame, pass); 219 DrawRenderPass(&frame, pass);
206 220
207 for (ScopedPtrVector<CopyOutputRequest>::iterator it = 221 for (ScopedPtrVector<CopyOutputRequest>::iterator it =
208 pass->copy_requests.begin(); 222 pass->copy_requests.begin();
209 it != pass->copy_requests.end(); 223 it != pass->copy_requests.end();
210 ++it) { 224 ++it) {
(...skipping 27 matching lines...) Expand all
238 render_pass_scissor.Intersect(damage_rect_in_render_pass_space); 252 render_pass_scissor.Intersect(damage_rect_in_render_pass_space);
239 } 253 }
240 254
241 return render_pass_scissor; 255 return render_pass_scissor;
242 } 256 }
243 257
244 void DirectRenderer::SetScissorStateForQuad(const DrawingFrame* frame, 258 void DirectRenderer::SetScissorStateForQuad(const DrawingFrame* frame,
245 const DrawQuad& quad) { 259 const DrawQuad& quad) {
246 if (quad.isClipped()) { 260 if (quad.isClipped()) {
247 gfx::RectF quad_scissor_rect = quad.clipRect(); 261 gfx::RectF quad_scissor_rect = quad.clipRect();
248 SetScissorTestRect(MoveScissorToWindowSpace(frame, quad_scissor_rect)); 262 SetScissorTestRect(
263 MoveFromDrawToWindowSpace(quad_scissor_rect, frame->flipped_y));
249 } else { 264 } else {
250 EnsureScissorTestDisabled(); 265 EnsureScissorTestDisabled();
251 } 266 }
252 } 267 }
253 268
254 void DirectRenderer::SetScissorStateForQuadWithRenderPassScissor( 269 void DirectRenderer::SetScissorStateForQuadWithRenderPassScissor(
255 const DrawingFrame* frame, 270 const DrawingFrame* frame,
256 const DrawQuad& quad, 271 const DrawQuad& quad,
257 const gfx::RectF& render_pass_scissor, 272 const gfx::RectF& render_pass_scissor,
258 bool* should_skip_quad) { 273 bool* should_skip_quad) {
259 gfx::RectF quad_scissor_rect = render_pass_scissor; 274 gfx::RectF quad_scissor_rect = render_pass_scissor;
260 275
261 if (quad.isClipped()) 276 if (quad.isClipped())
262 quad_scissor_rect.Intersect(quad.clipRect()); 277 quad_scissor_rect.Intersect(quad.clipRect());
263 278
264 if (quad_scissor_rect.IsEmpty()) { 279 if (quad_scissor_rect.IsEmpty()) {
265 *should_skip_quad = true; 280 *should_skip_quad = true;
266 return; 281 return;
267 } 282 }
268 283
269 *should_skip_quad = false; 284 *should_skip_quad = false;
270 SetScissorTestRect(MoveScissorToWindowSpace(frame, quad_scissor_rect)); 285 SetScissorTestRect(
286 MoveFromDrawToWindowSpace(quad_scissor_rect, frame->flipped_y));
271 } 287 }
272 288
273 void DirectRenderer::FinishDrawingQuadList() {} 289 void DirectRenderer::FinishDrawingQuadList() {}
274 290
275 void DirectRenderer::DrawRenderPass(DrawingFrame* frame, 291 void DirectRenderer::DrawRenderPass(DrawingFrame* frame,
276 const RenderPass* render_pass) { 292 const RenderPass* render_pass) {
277 TRACE_EVENT0("cc", "DirectRenderer::DrawRenderPass"); 293 TRACE_EVENT0("cc", "DirectRenderer::DrawRenderPass");
278 if (!UseRenderPass(frame, render_pass)) 294 if (!UseRenderPass(frame, render_pass))
279 return; 295 return;
280 296
281 bool using_scissor_as_optimization = 297 bool using_scissor_as_optimization =
282 Capabilities().using_partial_swap && client_->AllowPartialSwap(); 298 Capabilities().using_partial_swap && client_->AllowPartialSwap();
283 gfx::RectF render_pass_scissor; 299 gfx::RectF render_pass_scissor;
284 300
285 if (using_scissor_as_optimization) { 301 if (using_scissor_as_optimization) {
286 render_pass_scissor = ComputeScissorRectForRenderPass(frame); 302 render_pass_scissor = ComputeScissorRectForRenderPass(frame);
287 SetScissorTestRect(MoveScissorToWindowSpace(frame, render_pass_scissor)); 303 SetScissorTestRect(
304 MoveFromDrawToWindowSpace(render_pass_scissor, frame->flipped_y));
288 } 305 }
289 306
290 if (frame->current_render_pass != frame->root_render_pass || 307 if (frame->current_render_pass != frame->root_render_pass ||
291 client_->ShouldClearRootRenderPass()) { 308 client_->ShouldClearRootRenderPass()) {
292 if (!using_scissor_as_optimization) 309 if (!using_scissor_as_optimization)
293 EnsureScissorTestDisabled(); 310 EnsureScissorTestDisabled();
294 ClearFramebuffer(frame); 311 ClearFramebuffer(frame);
295 } 312 }
296 313
297 const QuadList& quad_list = render_pass->quad_list; 314 const QuadList& quad_list = render_pass->quad_list;
(...skipping 22 matching lines...) Expand all
320 } 337 }
321 } 338 }
322 339
323 bool DirectRenderer::UseRenderPass(DrawingFrame* frame, 340 bool DirectRenderer::UseRenderPass(DrawingFrame* frame,
324 const RenderPass* render_pass) { 341 const RenderPass* render_pass) {
325 frame->current_render_pass = render_pass; 342 frame->current_render_pass = render_pass;
326 frame->current_texture = NULL; 343 frame->current_texture = NULL;
327 344
328 if (render_pass == frame->root_render_pass) { 345 if (render_pass == frame->root_render_pass) {
329 BindFramebufferToOutputSurface(frame); 346 BindFramebufferToOutputSurface(frame);
330 InitializeMatrices(frame, render_pass->output_rect, FlippedFramebuffer()); 347 InitializeViewport(frame,
331 SetDrawViewportSize(render_pass->output_rect.size()); 348 render_pass->output_rect,
349 client_->DeviceViewport(),
350 output_surface_->SurfaceSize(),
351 FlippedFramebuffer());
332 return true; 352 return true;
333 } 353 }
334 354
335 if (!resource_provider_) 355 if (!resource_provider_)
336 return false; 356 return false;
337 357
338 CachedResource* texture = render_pass_textures_.get(render_pass->id); 358 CachedResource* texture = render_pass_textures_.get(render_pass->id);
339 DCHECK(texture); 359 DCHECK(texture);
340 360
341 gfx::Size size = RenderPassTextureSize(render_pass); 361 gfx::Size size = RenderPassTextureSize(render_pass);
(...skipping 21 matching lines...) Expand all
363 gfx::Size DirectRenderer::RenderPassTextureSize(const RenderPass* render_pass) { 383 gfx::Size DirectRenderer::RenderPassTextureSize(const RenderPass* render_pass) {
364 return render_pass->output_rect.size(); 384 return render_pass->output_rect.size();
365 } 385 }
366 386
367 // static 387 // static
368 GLenum DirectRenderer::RenderPassTextureFormat(const RenderPass* render_pass) { 388 GLenum DirectRenderer::RenderPassTextureFormat(const RenderPass* render_pass) {
369 return GL_RGBA; 389 return GL_RGBA;
370 } 390 }
371 391
372 } // namespace cc 392 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/direct_renderer.h ('k') | cc/output/gl_renderer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698