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

Side by Side Diff: cc/output/gl_renderer.cc

Issue 93663004: [#2] Pass gfx structs by const ref (gfx::Rect, gfx::RectF) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase to ToT, fix builds on non-linux platforms! Created 6 years, 11 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/gl_renderer.h ('k') | cc/output/gl_renderer_unittest.cc » ('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 2010 The Chromium Authors. All rights reserved. 1 // Copyright 2010 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/gl_renderer.h" 5 #include "cc/output/gl_renderer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 2046 matching lines...) Expand 10 before | Expand all | Expand 10 after
2057 QuadRectTransform(&quad_rect_matrix, draw_transform, quad_rect); 2057 QuadRectTransform(&quad_rect_matrix, draw_transform, quad_rect);
2058 static float gl_matrix[16]; 2058 static float gl_matrix[16];
2059 ToGLMatrix(&gl_matrix[0], frame->projection_matrix * quad_rect_matrix); 2059 ToGLMatrix(&gl_matrix[0], frame->projection_matrix * quad_rect_matrix);
2060 GLC(gl_, gl_->UniformMatrix4fv(matrix_location, 1, false, &gl_matrix[0])); 2060 GLC(gl_, gl_->UniformMatrix4fv(matrix_location, 1, false, &gl_matrix[0]));
2061 2061
2062 GLC(gl_, gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0)); 2062 GLC(gl_, gl_->DrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0));
2063 } 2063 }
2064 2064
2065 void GLRenderer::CopyTextureToFramebuffer(const DrawingFrame* frame, 2065 void GLRenderer::CopyTextureToFramebuffer(const DrawingFrame* frame,
2066 int texture_id, 2066 int texture_id,
2067 gfx::Rect rect, 2067 const gfx::Rect& rect,
2068 const gfx::Transform& draw_matrix, 2068 const gfx::Transform& draw_matrix,
2069 bool flip_vertically) { 2069 bool flip_vertically) {
2070 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( 2070 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
2071 gl_, &highp_threshold_cache_, highp_threshold_min_, rect.bottom_right()); 2071 gl_, &highp_threshold_cache_, highp_threshold_min_, rect.bottom_right());
2072 2072
2073 const RenderPassProgram* program = GetRenderPassProgram(tex_coord_precision); 2073 const RenderPassProgram* program = GetRenderPassProgram(tex_coord_precision);
2074 SetUseProgram(program->program()); 2074 SetUseProgram(program->program());
2075 2075
2076 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0)); 2076 GLC(gl_, gl_->Uniform1i(program->fragment_shader().sampler_location(), 0));
2077 2077
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
2167 } 2167 }
2168 2168
2169 void GLRenderer::EnsureBackbuffer() { 2169 void GLRenderer::EnsureBackbuffer() {
2170 if (!is_backbuffer_discarded_) 2170 if (!is_backbuffer_discarded_)
2171 return; 2171 return;
2172 2172
2173 output_surface_->EnsureBackbuffer(); 2173 output_surface_->EnsureBackbuffer();
2174 is_backbuffer_discarded_ = false; 2174 is_backbuffer_discarded_ = false;
2175 } 2175 }
2176 2176
2177 void GLRenderer::GetFramebufferPixels(void* pixels, gfx::Rect rect) { 2177 void GLRenderer::GetFramebufferPixels(void* pixels, const gfx::Rect& rect) {
2178 if (!pixels || rect.IsEmpty()) 2178 if (!pixels || rect.IsEmpty())
2179 return; 2179 return;
2180 2180
2181 // This function assumes that it is reading the root frame buffer. 2181 // This function assumes that it is reading the root frame buffer.
2182 DCHECK(!current_framebuffer_lock_); 2182 DCHECK(!current_framebuffer_lock_);
2183 2183
2184 scoped_ptr<PendingAsyncReadPixels> pending_read(new PendingAsyncReadPixels); 2184 scoped_ptr<PendingAsyncReadPixels> pending_read(new PendingAsyncReadPixels);
2185 pending_async_read_pixels_.insert(pending_async_read_pixels_.begin(), 2185 pending_async_read_pixels_.insert(pending_async_read_pixels_.begin(),
2186 pending_read.Pass()); 2186 pending_read.Pass());
2187 2187
2188 // This is a syncronous call since the callback is null. 2188 // This is a syncronous call since the callback is null.
2189 gfx::Rect window_rect = MoveFromDrawToWindowSpace(rect); 2189 gfx::Rect window_rect = MoveFromDrawToWindowSpace(rect);
2190 DoGetFramebufferPixels(static_cast<uint8*>(pixels), 2190 DoGetFramebufferPixels(static_cast<uint8*>(pixels),
2191 window_rect, 2191 window_rect,
2192 AsyncGetFramebufferPixelsCleanupCallback()); 2192 AsyncGetFramebufferPixelsCleanupCallback());
2193 } 2193 }
2194 2194
2195 void GLRenderer::GetFramebufferPixelsAsync( 2195 void GLRenderer::GetFramebufferPixelsAsync(
2196 gfx::Rect rect, 2196 const gfx::Rect& rect,
2197 scoped_ptr<CopyOutputRequest> request) { 2197 scoped_ptr<CopyOutputRequest> request) {
2198 DCHECK(!request->IsEmpty()); 2198 DCHECK(!request->IsEmpty());
2199 if (request->IsEmpty()) 2199 if (request->IsEmpty())
2200 return; 2200 return;
2201 if (rect.IsEmpty()) 2201 if (rect.IsEmpty())
2202 return; 2202 return;
2203 2203
2204 gfx::Rect window_rect = MoveFromDrawToWindowSpace(rect); 2204 gfx::Rect window_rect = MoveFromDrawToWindowSpace(rect);
2205 2205
2206 if (!request->force_bitmap_result()) { 2206 if (!request->force_bitmap_result()) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
2284 pending_read->copy_request = request.Pass(); 2284 pending_read->copy_request = request.Pass();
2285 pending_async_read_pixels_.insert(pending_async_read_pixels_.begin(), 2285 pending_async_read_pixels_.insert(pending_async_read_pixels_.begin(),
2286 pending_read.Pass()); 2286 pending_read.Pass());
2287 2287
2288 // This is an asyncronous call since the callback is not null. 2288 // This is an asyncronous call since the callback is not null.
2289 DoGetFramebufferPixels(pixels, window_rect, cleanup_callback); 2289 DoGetFramebufferPixels(pixels, window_rect, cleanup_callback);
2290 } 2290 }
2291 2291
2292 void GLRenderer::DoGetFramebufferPixels( 2292 void GLRenderer::DoGetFramebufferPixels(
2293 uint8* dest_pixels, 2293 uint8* dest_pixels,
2294 gfx::Rect window_rect, 2294 const gfx::Rect& window_rect,
2295 const AsyncGetFramebufferPixelsCleanupCallback& cleanup_callback) { 2295 const AsyncGetFramebufferPixelsCleanupCallback& cleanup_callback) {
2296 DCHECK_GE(window_rect.x(), 0); 2296 DCHECK_GE(window_rect.x(), 0);
2297 DCHECK_GE(window_rect.y(), 0); 2297 DCHECK_GE(window_rect.y(), 0);
2298 DCHECK_LE(window_rect.right(), current_surface_size_.width()); 2298 DCHECK_LE(window_rect.right(), current_surface_size_.width());
2299 DCHECK_LE(window_rect.bottom(), current_surface_size_.height()); 2299 DCHECK_LE(window_rect.bottom(), current_surface_size_.height());
2300 2300
2301 bool is_async = !cleanup_callback.is_null(); 2301 bool is_async = !cleanup_callback.is_null();
2302 2302
2303 bool do_workaround = NeedsIOSurfaceReadbackWorkaround(); 2303 bool do_workaround = NeedsIOSurfaceReadbackWorkaround();
2304 2304
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
2467 bool success) { 2467 bool success) {
2468 DCHECK(request->force_bitmap_result()); 2468 DCHECK(request->force_bitmap_result());
2469 2469
2470 lock.reset(); 2470 lock.reset();
2471 if (success) 2471 if (success)
2472 request->SendBitmapResult(bitmap.Pass()); 2472 request->SendBitmapResult(bitmap.Pass());
2473 } 2473 }
2474 2474
2475 void GLRenderer::GetFramebufferTexture(unsigned texture_id, 2475 void GLRenderer::GetFramebufferTexture(unsigned texture_id,
2476 ResourceFormat texture_format, 2476 ResourceFormat texture_format,
2477 gfx::Rect window_rect) { 2477 const gfx::Rect& window_rect) {
2478 DCHECK(texture_id); 2478 DCHECK(texture_id);
2479 DCHECK_GE(window_rect.x(), 0); 2479 DCHECK_GE(window_rect.x(), 0);
2480 DCHECK_GE(window_rect.y(), 0); 2480 DCHECK_GE(window_rect.y(), 0);
2481 DCHECK_LE(window_rect.right(), current_surface_size_.width()); 2481 DCHECK_LE(window_rect.right(), current_surface_size_.width());
2482 DCHECK_LE(window_rect.bottom(), current_surface_size_.height()); 2482 DCHECK_LE(window_rect.bottom(), current_surface_size_.height());
2483 2483
2484 GLC(gl_, gl_->BindTexture(GL_TEXTURE_2D, texture_id)); 2484 GLC(gl_, gl_->BindTexture(GL_TEXTURE_2D, texture_id));
2485 GLC(gl_, 2485 GLC(gl_,
2486 gl_->CopyTexImage2D(GL_TEXTURE_2D, 2486 gl_->CopyTexImage2D(GL_TEXTURE_2D,
2487 0, 2487 0,
2488 GLDataFormat(texture_format), 2488 GLDataFormat(texture_format),
2489 window_rect.x(), 2489 window_rect.x(),
2490 window_rect.y(), 2490 window_rect.y(),
2491 window_rect.width(), 2491 window_rect.width(),
2492 window_rect.height(), 2492 window_rect.height(),
2493 0)); 2493 0));
2494 GLC(gl_, gl_->BindTexture(GL_TEXTURE_2D, 0)); 2494 GLC(gl_, gl_->BindTexture(GL_TEXTURE_2D, 0));
2495 } 2495 }
2496 2496
2497 bool GLRenderer::UseScopedTexture(DrawingFrame* frame, 2497 bool GLRenderer::UseScopedTexture(DrawingFrame* frame,
2498 const ScopedResource* texture, 2498 const ScopedResource* texture,
2499 gfx::Rect viewport_rect) { 2499 const gfx::Rect& viewport_rect) {
2500 DCHECK(texture->id()); 2500 DCHECK(texture->id());
2501 frame->current_render_pass = NULL; 2501 frame->current_render_pass = NULL;
2502 frame->current_texture = texture; 2502 frame->current_texture = texture;
2503 2503
2504 return BindFramebufferToTexture(frame, texture, viewport_rect); 2504 return BindFramebufferToTexture(frame, texture, viewport_rect);
2505 } 2505 }
2506 2506
2507 void GLRenderer::BindFramebufferToOutputSurface(DrawingFrame* frame) { 2507 void GLRenderer::BindFramebufferToOutputSurface(DrawingFrame* frame) {
2508 current_framebuffer_lock_.reset(); 2508 current_framebuffer_lock_.reset();
2509 output_surface_->BindFramebuffer(); 2509 output_surface_->BindFramebuffer();
2510 2510
2511 if (output_surface_->HasExternalStencilTest()) { 2511 if (output_surface_->HasExternalStencilTest()) {
2512 SetStencilEnabled(true); 2512 SetStencilEnabled(true);
2513 GLC(gl_, gl_->StencilFunc(GL_EQUAL, 1, 1)); 2513 GLC(gl_, gl_->StencilFunc(GL_EQUAL, 1, 1));
2514 } else { 2514 } else {
2515 SetStencilEnabled(false); 2515 SetStencilEnabled(false);
2516 } 2516 }
2517 } 2517 }
2518 2518
2519 bool GLRenderer::BindFramebufferToTexture(DrawingFrame* frame, 2519 bool GLRenderer::BindFramebufferToTexture(DrawingFrame* frame,
2520 const ScopedResource* texture, 2520 const ScopedResource* texture,
2521 gfx::Rect target_rect) { 2521 const gfx::Rect& target_rect) {
2522 DCHECK(texture->id()); 2522 DCHECK(texture->id());
2523 2523
2524 current_framebuffer_lock_.reset(); 2524 current_framebuffer_lock_.reset();
2525 2525
2526 SetStencilEnabled(false); 2526 SetStencilEnabled(false);
2527 GLC(gl_, gl_->BindFramebuffer(GL_FRAMEBUFFER, offscreen_framebuffer_id_)); 2527 GLC(gl_, gl_->BindFramebuffer(GL_FRAMEBUFFER, offscreen_framebuffer_id_));
2528 current_framebuffer_lock_ = 2528 current_framebuffer_lock_ =
2529 make_scoped_ptr(new ResourceProvider::ScopedWriteLockGL( 2529 make_scoped_ptr(new ResourceProvider::ScopedWriteLockGL(
2530 resource_provider_, texture->id())); 2530 resource_provider_, texture->id()));
2531 unsigned texture_id = current_framebuffer_lock_->texture_id(); 2531 unsigned texture_id = current_framebuffer_lock_->texture_id();
2532 GLC(gl_, 2532 GLC(gl_,
2533 gl_->FramebufferTexture2D( 2533 gl_->FramebufferTexture2D(
2534 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture_id, 0)); 2534 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture_id, 0));
2535 2535
2536 DCHECK(gl_->CheckFramebufferStatus(GL_FRAMEBUFFER) == 2536 DCHECK(gl_->CheckFramebufferStatus(GL_FRAMEBUFFER) ==
2537 GL_FRAMEBUFFER_COMPLETE || 2537 GL_FRAMEBUFFER_COMPLETE ||
2538 IsContextLost()); 2538 IsContextLost());
2539 2539
2540 InitializeViewport( 2540 InitializeViewport(
2541 frame, target_rect, gfx::Rect(target_rect.size()), target_rect.size()); 2541 frame, target_rect, gfx::Rect(target_rect.size()), target_rect.size());
2542 return true; 2542 return true;
2543 } 2543 }
2544 2544
2545 void GLRenderer::SetScissorTestRect(gfx::Rect scissor_rect) { 2545 void GLRenderer::SetScissorTestRect(const gfx::Rect& scissor_rect) {
2546 EnsureScissorTestEnabled(); 2546 EnsureScissorTestEnabled();
2547 2547
2548 // Don't unnecessarily ask the context to change the scissor, because it 2548 // Don't unnecessarily ask the context to change the scissor, because it
2549 // may cause undesired GPU pipeline flushes. 2549 // may cause undesired GPU pipeline flushes.
2550 if (scissor_rect == scissor_rect_ && !scissor_rect_needs_reset_) 2550 if (scissor_rect == scissor_rect_ && !scissor_rect_needs_reset_)
2551 return; 2551 return;
2552 2552
2553 scissor_rect_ = scissor_rect; 2553 scissor_rect_ = scissor_rect;
2554 FlushTextureQuadCache(); 2554 FlushTextureQuadCache();
2555 GLC(gl_, 2555 GLC(gl_,
2556 gl_->Scissor(scissor_rect.x(), 2556 gl_->Scissor(scissor_rect.x(),
2557 scissor_rect.y(), 2557 scissor_rect.y(),
2558 scissor_rect.width(), 2558 scissor_rect.width(),
2559 scissor_rect.height())); 2559 scissor_rect.height()));
2560 2560
2561 scissor_rect_needs_reset_ = false; 2561 scissor_rect_needs_reset_ = false;
2562 } 2562 }
2563 2563
2564 void GLRenderer::SetDrawViewport(gfx::Rect window_space_viewport) { 2564 void GLRenderer::SetDrawViewport(const gfx::Rect& window_space_viewport) {
2565 viewport_ = window_space_viewport; 2565 viewport_ = window_space_viewport;
2566 GLC(gl_, 2566 GLC(gl_,
2567 gl_->Viewport(window_space_viewport.x(), 2567 gl_->Viewport(window_space_viewport.x(),
2568 window_space_viewport.y(), 2568 window_space_viewport.y(),
2569 window_space_viewport.width(), 2569 window_space_viewport.width(),
2570 window_space_viewport.height())); 2570 window_space_viewport.height()));
2571 } 2571 }
2572 2572
2573 void GLRenderer::InitializeSharedObjects() { 2573 void GLRenderer::InitializeSharedObjects() {
2574 TRACE_EVENT0("cc", "GLRenderer::InitializeSharedObjects"); 2574 TRACE_EVENT0("cc", "GLRenderer::InitializeSharedObjects");
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
3008 is_scissor_enabled_ = false; 3008 is_scissor_enabled_ = false;
3009 GLC(gl_, gl_->Disable(GL_SCISSOR_TEST)); 3009 GLC(gl_, gl_->Disable(GL_SCISSOR_TEST));
3010 scissor_rect_needs_reset_ = true; 3010 scissor_rect_needs_reset_ = true;
3011 } 3011 }
3012 3012
3013 bool GLRenderer::IsContextLost() { 3013 bool GLRenderer::IsContextLost() {
3014 return output_surface_->context_provider()->IsContextLost(); 3014 return output_surface_->context_provider()->IsContextLost();
3015 } 3015 }
3016 3016
3017 } // namespace cc 3017 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/gl_renderer.h ('k') | cc/output/gl_renderer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698