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

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: Add 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 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // static
83 void DirectRenderer::InitializeMatrices(DrawingFrame* frame, 83 void DirectRenderer::InitializeMatrices(DrawingFrame* frame,
84 gfx::Rect draw_rect, 84 gfx::Rect draw_rect,
85 gfx::Rect window_rect,
85 bool flip_y) { 86 bool flip_y) {
86 if (flip_y) { 87 if (flip_y) {
87 frame->projection_matrix = OrthoProjectionMatrix(draw_rect.x(), 88 frame->projection_matrix = OrthoProjectionMatrix(draw_rect.x(),
88 draw_rect.right(), 89 draw_rect.right(),
89 draw_rect.bottom(), 90 draw_rect.bottom(),
90 draw_rect.y()); 91 draw_rect.y());
91 } else { 92 } else {
92 frame->projection_matrix = OrthoProjectionMatrix(draw_rect.x(), 93 frame->projection_matrix = OrthoProjectionMatrix(draw_rect.x(),
93 draw_rect.right(), 94 draw_rect.right(),
94 draw_rect.y(), 95 draw_rect.y(),
95 draw_rect.bottom()); 96 draw_rect.bottom());
96 } 97 }
97 frame->window_matrix = 98
98 window_matrix(0, 0, draw_rect.width(), draw_rect.height()); 99 frame->window_matrix = window_matrix(window_rect.x(),
100 window_rect.y(),
101 window_rect.width(),
102 window_rect.height());
99 frame->flipped_y = flip_y; 103 frame->flipped_y = flip_y;
100 } 104 }
101 105
102 // static
103 gfx::Rect DirectRenderer::MoveScissorToWindowSpace( 106 gfx::Rect DirectRenderer::MoveScissorToWindowSpace(
104 const DrawingFrame* frame, const gfx::RectF& scissor_rect) { 107 const DrawingFrame* frame, const gfx::RectF& scissor_rect) {
105 gfx::Rect scissor_rect_in_canvas_space = gfx::ToEnclosingRect(scissor_rect); 108 gfx::Rect scissor_rect_in_canvas_space = gfx::ToEnclosingRect(scissor_rect);
106 // The scissor coordinates must be supplied in viewport space so we need to 109 // The scissor coordinates must be supplied in window space so we need to
107 // offset by the relative position of the top left corner of the current 110 // offset by the relative position of the top left corner of the current
108 // render pass. 111 // render pass.
109 gfx::Rect framebuffer_output_rect = frame->current_render_pass->output_rect; 112 gfx::Rect framebuffer_output_rect = frame->current_render_pass->output_rect;
113 if (!frame->current_texture) {
114 framebuffer_output_rect = gfx::Rect(output_surface_->SurfaceSize());
115 scissor_rect_in_canvas_space.Offset(client_->DeviceViewport().x(),
116 client_->DeviceViewport().y());
117 }
110 scissor_rect_in_canvas_space.set_x( 118 scissor_rect_in_canvas_space.set_x(
111 scissor_rect_in_canvas_space.x() - framebuffer_output_rect.x()); 119 scissor_rect_in_canvas_space.x() - framebuffer_output_rect.x());
112 if (frame->flipped_y && !frame->current_texture) { 120 if (frame->flipped_y && !frame->current_texture) {
113 scissor_rect_in_canvas_space.set_y( 121 scissor_rect_in_canvas_space.set_y(
114 framebuffer_output_rect.height() - 122 framebuffer_output_rect.height() -
115 (scissor_rect_in_canvas_space.bottom() - framebuffer_output_rect.y())); 123 (scissor_rect_in_canvas_space.bottom() - framebuffer_output_rect.y()));
116 } else { 124 } else {
117 scissor_rect_in_canvas_space.set_y( 125 scissor_rect_in_canvas_space.set_y(
118 scissor_rect_in_canvas_space.y() - framebuffer_output_rect.y()); 126 scissor_rect_in_canvas_space.y() - framebuffer_output_rect.y());
119 } 127 }
120 return scissor_rect_in_canvas_space; 128 return scissor_rect_in_canvas_space;
121 } 129 }
122 130
123 DirectRenderer::DirectRenderer(RendererClient* client, 131 DirectRenderer::DirectRenderer(RendererClient* client,
132 OutputSurface* output_surface,
124 ResourceProvider* resource_provider) 133 ResourceProvider* resource_provider)
125 : Renderer(client), 134 : Renderer(client),
135 output_surface_(output_surface),
126 resource_provider_(resource_provider) {} 136 resource_provider_(resource_provider) {}
127 137
128 DirectRenderer::~DirectRenderer() {} 138 DirectRenderer::~DirectRenderer() {}
129 139
130 bool DirectRenderer::CanReadPixels() const { return true; } 140 bool DirectRenderer::CanReadPixels() const { return true; }
131 141
132 void DirectRenderer::SetEnlargePassTextureAmountForTesting( 142 void DirectRenderer::SetEnlargePassTextureAmountForTesting(
133 gfx::Vector2d amount) { 143 gfx::Vector2d amount) {
134 enlarge_pass_texture_amount_ = amount; 144 enlarge_pass_texture_amount_ = amount;
135 } 145 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 render_passes_in_draw_order->size()); 200 render_passes_in_draw_order->size());
191 201
192 const RenderPass* root_render_pass = render_passes_in_draw_order->back(); 202 const RenderPass* root_render_pass = render_passes_in_draw_order->back();
193 DCHECK(root_render_pass); 203 DCHECK(root_render_pass);
194 204
195 DrawingFrame frame; 205 DrawingFrame frame;
196 frame.root_render_pass = root_render_pass; 206 frame.root_render_pass = root_render_pass;
197 frame.root_damage_rect = 207 frame.root_damage_rect =
198 Capabilities().using_partial_swap && client_->AllowPartialSwap() ? 208 Capabilities().using_partial_swap && client_->AllowPartialSwap() ?
199 root_render_pass->damage_rect : root_render_pass->output_rect; 209 root_render_pass->damage_rect : root_render_pass->output_rect;
200 frame.root_damage_rect.Intersect(gfx::Rect(ViewportSize())); 210 frame.root_damage_rect.Intersect(gfx::Rect(client_->DeviceViewport().size()));
211
212 // Only reshape when we know we are going to draw. Otherwise, the reshape
213 // can leave the window at the wrong size if we never draw and the proper
214 // viewport size is never set.
215 output_surface_->Reshape(client_->DeviceViewport().size(),
enne (OOO) 2013/06/04 17:26:03 Should this only happen if the device viewport has
aelias_OOO_until_Jul13 2013/06/04 17:54:20 I added a check within OutputSurface itself not to
216 client_->DeviceScaleFactor());
201 217
202 BeginDrawingFrame(&frame); 218 BeginDrawingFrame(&frame);
203 for (size_t i = 0; i < render_passes_in_draw_order->size(); ++i) { 219 for (size_t i = 0; i < render_passes_in_draw_order->size(); ++i) {
204 RenderPass* pass = render_passes_in_draw_order->at(i); 220 RenderPass* pass = render_passes_in_draw_order->at(i);
205 DrawRenderPass(&frame, pass); 221 DrawRenderPass(&frame, pass);
206 222
207 for (ScopedPtrVector<CopyOutputRequest>::iterator it = 223 for (ScopedPtrVector<CopyOutputRequest>::iterator it =
208 pass->copy_requests.begin(); 224 pass->copy_requests.begin();
209 it != pass->copy_requests.end(); 225 it != pass->copy_requests.end();
210 ++it) { 226 ++it) {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 } 336 }
321 } 337 }
322 338
323 bool DirectRenderer::UseRenderPass(DrawingFrame* frame, 339 bool DirectRenderer::UseRenderPass(DrawingFrame* frame,
324 const RenderPass* render_pass) { 340 const RenderPass* render_pass) {
325 frame->current_render_pass = render_pass; 341 frame->current_render_pass = render_pass;
326 frame->current_texture = NULL; 342 frame->current_texture = NULL;
327 343
328 if (render_pass == frame->root_render_pass) { 344 if (render_pass == frame->root_render_pass) {
329 BindFramebufferToOutputSurface(frame); 345 BindFramebufferToOutputSurface(frame);
330 InitializeMatrices(frame, render_pass->output_rect, FlippedFramebuffer()); 346 gfx::Rect viewport = client_->DeviceViewport();
331 SetDrawViewportSize(render_pass->output_rect.size()); 347 if (FlippedFramebuffer())
348 viewport.set_y(output_surface_->SurfaceSize().height() -
349 viewport.bottom());
350 InitializeMatrices(
351 frame,
352 render_pass->output_rect,
353 viewport,
354 FlippedFramebuffer());
355 SetDrawViewport(viewport);
332 return true; 356 return true;
333 } 357 }
334 358
335 if (!resource_provider_) 359 if (!resource_provider_)
336 return false; 360 return false;
337 361
338 CachedResource* texture = render_pass_textures_.get(render_pass->id); 362 CachedResource* texture = render_pass_textures_.get(render_pass->id);
339 DCHECK(texture); 363 DCHECK(texture);
340 364
341 gfx::Size size = RenderPassTextureSize(render_pass); 365 gfx::Size size = RenderPassTextureSize(render_pass);
(...skipping 21 matching lines...) Expand all
363 gfx::Size DirectRenderer::RenderPassTextureSize(const RenderPass* render_pass) { 387 gfx::Size DirectRenderer::RenderPassTextureSize(const RenderPass* render_pass) {
364 return render_pass->output_rect.size(); 388 return render_pass->output_rect.size();
365 } 389 }
366 390
367 // static 391 // static
368 GLenum DirectRenderer::RenderPassTextureFormat(const RenderPass* render_pass) { 392 GLenum DirectRenderer::RenderPassTextureFormat(const RenderPass* render_pass) {
369 return GL_RGBA; 393 return GL_RGBA;
370 } 394 }
371 395
372 } // namespace cc 396 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698