| OLD | NEW |
| 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 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 int top, right, bottom, left; | 655 int top, right, bottom, left; |
| 656 filters.GetOutsets(&top, &right, &bottom, &left); | 656 filters.GetOutsets(&top, &right, &bottom, &left); |
| 657 window_rect.Inset(-left, -top, -right, -bottom); | 657 window_rect.Inset(-left, -top, -right, -bottom); |
| 658 | 658 |
| 659 window_rect.Intersect( | 659 window_rect.Intersect( |
| 660 MoveFromDrawToWindowSpace(frame->current_render_pass->output_rect)); | 660 MoveFromDrawToWindowSpace(frame->current_render_pass->output_rect)); |
| 661 | 661 |
| 662 scoped_ptr<ScopedResource> device_background_texture = | 662 scoped_ptr<ScopedResource> device_background_texture = |
| 663 ScopedResource::create(resource_provider_); | 663 ScopedResource::create(resource_provider_); |
| 664 if (!device_background_texture->Allocate(window_rect.size(), | 664 if (!device_background_texture->Allocate(window_rect.size(), |
| 665 GL_RGB, | 665 ResourceProvider::TextureUsageAny, |
| 666 ResourceProvider::TextureUsageAny)) { | 666 ResourceProvider::RGBA_8888)) { |
| 667 return scoped_ptr<ScopedResource>(); | 667 return scoped_ptr<ScopedResource>(); |
| 668 } else { | 668 } else { |
| 669 ResourceProvider::ScopedWriteLockGL lock(resource_provider_, | 669 ResourceProvider::ScopedWriteLockGL lock(resource_provider_, |
| 670 device_background_texture->id()); | 670 device_background_texture->id()); |
| 671 GetFramebufferTexture(lock.texture_id(), | 671 GetFramebufferTexture(lock.texture_id(), |
| 672 device_background_texture->format(), | 672 device_background_texture->format(), |
| 673 window_rect); | 673 window_rect); |
| 674 } | 674 } |
| 675 | 675 |
| 676 SkBitmap filtered_device_background = | 676 SkBitmap filtered_device_background = |
| 677 ApplyFilters(this, | 677 ApplyFilters(this, |
| 678 frame->offscreen_context_provider, | 678 frame->offscreen_context_provider, |
| 679 filters, | 679 filters, |
| 680 device_background_texture.get()); | 680 device_background_texture.get()); |
| 681 if (!filtered_device_background.getTexture()) | 681 if (!filtered_device_background.getTexture()) |
| 682 return scoped_ptr<ScopedResource>(); | 682 return scoped_ptr<ScopedResource>(); |
| 683 | 683 |
| 684 GrTexture* texture = | 684 GrTexture* texture = |
| 685 reinterpret_cast<GrTexture*>(filtered_device_background.getTexture()); | 685 reinterpret_cast<GrTexture*>(filtered_device_background.getTexture()); |
| 686 int filtered_device_background_texture_id = texture->getTextureHandle(); | 686 int filtered_device_background_texture_id = texture->getTextureHandle(); |
| 687 | 687 |
| 688 scoped_ptr<ScopedResource> background_texture = | 688 scoped_ptr<ScopedResource> background_texture = |
| 689 ScopedResource::create(resource_provider_); | 689 ScopedResource::create(resource_provider_); |
| 690 if (!background_texture->Allocate(quad->rect.size(), | 690 if (!background_texture->Allocate(quad->rect.size(), |
| 691 GL_RGBA, | 691 ResourceProvider::TextureUsageFramebuffer, |
| 692 ResourceProvider::TextureUsageFramebuffer)) | 692 ResourceProvider::RGBA_8888)) |
| 693 return scoped_ptr<ScopedResource>(); | 693 return scoped_ptr<ScopedResource>(); |
| 694 | 694 |
| 695 const RenderPass* target_render_pass = frame->current_render_pass; | 695 const RenderPass* target_render_pass = frame->current_render_pass; |
| 696 bool using_background_texture = | 696 bool using_background_texture = |
| 697 UseScopedTexture(frame, background_texture.get(), quad->rect); | 697 UseScopedTexture(frame, background_texture.get(), quad->rect); |
| 698 | 698 |
| 699 if (using_background_texture) { | 699 if (using_background_texture) { |
| 700 // Copy the readback pixels from device to the background texture for the | 700 // Copy the readback pixels from device to the background texture for the |
| 701 // surface. | 701 // surface. |
| 702 gfx::Transform device_to_framebuffer_transform; | 702 gfx::Transform device_to_framebuffer_transform; |
| (...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1704 SkBitmap::kARGB_8888_Config, | 1704 SkBitmap::kARGB_8888_Config, |
| 1705 quad->texture_size.width(), | 1705 quad->texture_size.width(), |
| 1706 quad->texture_size.height()); | 1706 quad->texture_size.height()); |
| 1707 on_demand_tile_raster_bitmap_.allocPixels(); | 1707 on_demand_tile_raster_bitmap_.allocPixels(); |
| 1708 | 1708 |
| 1709 if (on_demand_tile_raster_resource_id_) | 1709 if (on_demand_tile_raster_resource_id_) |
| 1710 resource_provider_->DeleteResource(on_demand_tile_raster_resource_id_); | 1710 resource_provider_->DeleteResource(on_demand_tile_raster_resource_id_); |
| 1711 | 1711 |
| 1712 on_demand_tile_raster_resource_id_ = resource_provider_->CreateGLTexture( | 1712 on_demand_tile_raster_resource_id_ = resource_provider_->CreateGLTexture( |
| 1713 quad->texture_size, | 1713 quad->texture_size, |
| 1714 GL_RGBA, | |
| 1715 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, | 1714 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, |
| 1716 GL_CLAMP_TO_EDGE, | 1715 GL_CLAMP_TO_EDGE, |
| 1717 ResourceProvider::TextureUsageAny); | 1716 ResourceProvider::TextureUsageAny, |
| 1717 settings_->use_rgba_4444_textures |
| 1718 ? ResourceProvider::RGBA_4444 : ResourceProvider::RGBA_8888); |
| 1718 } | 1719 } |
| 1719 | 1720 |
| 1720 SkBitmapDevice device(on_demand_tile_raster_bitmap_); | 1721 SkBitmapDevice device(on_demand_tile_raster_bitmap_); |
| 1721 SkCanvas canvas(&device); | 1722 SkCanvas canvas(&device); |
| 1722 | 1723 |
| 1723 quad->picture_pile->RasterToBitmap(&canvas, quad->content_rect, | 1724 quad->picture_pile->RasterToBitmap(&canvas, quad->content_rect, |
| 1724 quad->contents_scale, NULL); | 1725 quad->contents_scale, NULL); |
| 1725 | 1726 |
| 1727 const uint8_t* bitmap_pixels = NULL; |
| 1728 if (settings_->use_rgba_4444_textures) { |
| 1729 on_demand_tile_raster_bitmap_.copyTo( |
| 1730 &on_demand_tile_raster_bitmap_4444_, SkBitmap::kARGB_4444_Config); |
| 1731 bitmap_pixels = reinterpret_cast<uint8_t*>( |
| 1732 on_demand_tile_raster_bitmap_4444_.getPixels()); |
| 1733 } else { |
| 1734 bitmap_pixels = reinterpret_cast<uint8_t*>( |
| 1735 on_demand_tile_raster_bitmap_.getPixels()); |
| 1736 } |
| 1737 |
| 1726 resource_provider_->SetPixels( | 1738 resource_provider_->SetPixels( |
| 1727 on_demand_tile_raster_resource_id_, | 1739 on_demand_tile_raster_resource_id_, |
| 1728 reinterpret_cast<uint8_t*>(on_demand_tile_raster_bitmap_.getPixels()), | 1740 bitmap_pixels, |
| 1729 gfx::Rect(quad->texture_size), | 1741 gfx::Rect(quad->texture_size), |
| 1730 gfx::Rect(quad->texture_size), | 1742 gfx::Rect(quad->texture_size), |
| 1731 gfx::Vector2d()); | 1743 gfx::Vector2d()); |
| 1732 | 1744 |
| 1733 DrawContentQuad(frame, quad, on_demand_tile_raster_resource_id_); | 1745 DrawContentQuad(frame, quad, on_demand_tile_raster_resource_id_); |
| 1734 } | 1746 } |
| 1735 | 1747 |
| 1736 struct TextureProgramBinding { | 1748 struct TextureProgramBinding { |
| 1737 template <class Program> | 1749 template <class Program> |
| 1738 void Set(Program* program, WebKit::WebGraphicsContext3D* context) { | 1750 void Set(Program* program, WebKit::WebGraphicsContext3D* context) { |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2207 unsigned int texture_id = context_->createTexture(); | 2219 unsigned int texture_id = context_->createTexture(); |
| 2208 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, texture_id)); | 2220 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, texture_id)); |
| 2209 GLC(context_, context_->texParameteri( | 2221 GLC(context_, context_->texParameteri( |
| 2210 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); | 2222 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); |
| 2211 GLC(context_, context_->texParameteri( | 2223 GLC(context_, context_->texParameteri( |
| 2212 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); | 2224 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); |
| 2213 GLC(context_, context_->texParameteri( | 2225 GLC(context_, context_->texParameteri( |
| 2214 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); | 2226 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); |
| 2215 GLC(context_, context_->texParameteri( | 2227 GLC(context_, context_->texParameteri( |
| 2216 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); | 2228 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); |
| 2217 GetFramebufferTexture(texture_id, GL_RGBA, window_rect); | 2229 GetFramebufferTexture(texture_id, ResourceProvider::RGBA_8888, window_rect); |
| 2218 | 2230 |
| 2219 gpu::Mailbox mailbox; | 2231 gpu::Mailbox mailbox; |
| 2220 unsigned sync_point = 0; | 2232 unsigned sync_point = 0; |
| 2221 GLC(context_, context_->genMailboxCHROMIUM(mailbox.name)); | 2233 GLC(context_, context_->genMailboxCHROMIUM(mailbox.name)); |
| 2222 if (mailbox.IsZero()) { | 2234 if (mailbox.IsZero()) { |
| 2223 context_->deleteTexture(texture_id); | 2235 context_->deleteTexture(texture_id); |
| 2224 request->SendEmptyResult(); | 2236 request->SendEmptyResult(); |
| 2225 return; | 2237 return; |
| 2226 } | 2238 } |
| 2227 | 2239 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2299 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); | 2311 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); |
| 2300 GLC(context_, context_->texParameteri( | 2312 GLC(context_, context_->texParameteri( |
| 2301 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); | 2313 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); |
| 2302 GLC(context_, context_->texParameteri( | 2314 GLC(context_, context_->texParameteri( |
| 2303 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); | 2315 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); |
| 2304 GLC(context_, context_->texParameteri( | 2316 GLC(context_, context_->texParameteri( |
| 2305 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); | 2317 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); |
| 2306 // Copy the contents of the current (IOSurface-backed) framebuffer into a | 2318 // Copy the contents of the current (IOSurface-backed) framebuffer into a |
| 2307 // temporary texture. | 2319 // temporary texture. |
| 2308 GetFramebufferTexture(temporary_texture, | 2320 GetFramebufferTexture(temporary_texture, |
| 2309 GL_RGBA, | 2321 ResourceProvider::RGBA_8888, |
| 2310 gfx::Rect(current_surface_size_)); | 2322 gfx::Rect(current_surface_size_)); |
| 2311 temporary_fbo = context_->createFramebuffer(); | 2323 temporary_fbo = context_->createFramebuffer(); |
| 2312 // Attach this texture to an FBO, and perform the readback from that FBO. | 2324 // Attach this texture to an FBO, and perform the readback from that FBO. |
| 2313 GLC(context_, context_->bindFramebuffer(GL_FRAMEBUFFER, temporary_fbo)); | 2325 GLC(context_, context_->bindFramebuffer(GL_FRAMEBUFFER, temporary_fbo)); |
| 2314 GLC(context_, context_->framebufferTexture2D(GL_FRAMEBUFFER, | 2326 GLC(context_, context_->framebufferTexture2D(GL_FRAMEBUFFER, |
| 2315 GL_COLOR_ATTACHMENT0, | 2327 GL_COLOR_ATTACHMENT0, |
| 2316 GL_TEXTURE_2D, | 2328 GL_TEXTURE_2D, |
| 2317 temporary_texture, | 2329 temporary_texture, |
| 2318 0)); | 2330 0)); |
| 2319 | 2331 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2449 scoped_ptr<SkAutoLockPixels> lock, | 2461 scoped_ptr<SkAutoLockPixels> lock, |
| 2450 scoped_ptr<CopyOutputRequest> request, | 2462 scoped_ptr<CopyOutputRequest> request, |
| 2451 bool success) { | 2463 bool success) { |
| 2452 DCHECK(request->force_bitmap_result()); | 2464 DCHECK(request->force_bitmap_result()); |
| 2453 | 2465 |
| 2454 lock.reset(); | 2466 lock.reset(); |
| 2455 if (success) | 2467 if (success) |
| 2456 request->SendBitmapResult(bitmap.Pass()); | 2468 request->SendBitmapResult(bitmap.Pass()); |
| 2457 } | 2469 } |
| 2458 | 2470 |
| 2459 void GLRenderer::GetFramebufferTexture(unsigned texture_id, | 2471 void GLRenderer::GetFramebufferTexture( |
| 2460 unsigned texture_format, | 2472 unsigned texture_id, |
| 2461 gfx::Rect window_rect) { | 2473 ResourceProvider::Format texture_format, |
| 2474 gfx::Rect window_rect) { |
| 2462 DCHECK(texture_id); | 2475 DCHECK(texture_id); |
| 2463 DCHECK_GE(window_rect.x(), 0); | 2476 DCHECK_GE(window_rect.x(), 0); |
| 2464 DCHECK_GE(window_rect.y(), 0); | 2477 DCHECK_GE(window_rect.y(), 0); |
| 2465 DCHECK_LE(window_rect.right(), current_surface_size_.width()); | 2478 DCHECK_LE(window_rect.right(), current_surface_size_.width()); |
| 2466 DCHECK_LE(window_rect.bottom(), current_surface_size_.height()); | 2479 DCHECK_LE(window_rect.bottom(), current_surface_size_.height()); |
| 2467 | 2480 |
| 2468 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, texture_id)); | 2481 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, texture_id)); |
| 2469 GLC(context_, | 2482 GLC(context_, |
| 2470 context_->copyTexImage2D(GL_TEXTURE_2D, | 2483 context_->copyTexImage2D( |
| 2471 0, | 2484 GL_TEXTURE_2D, |
| 2472 texture_format, | 2485 0, |
| 2473 window_rect.x(), | 2486 ResourceProvider::GetGLDataFormat(texture_format), |
| 2474 window_rect.y(), | 2487 window_rect.x(), |
| 2475 window_rect.width(), | 2488 window_rect.y(), |
| 2476 window_rect.height(), | 2489 window_rect.width(), |
| 2477 0)); | 2490 window_rect.height(), |
| 2491 0)); |
| 2478 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, 0)); | 2492 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, 0)); |
| 2479 } | 2493 } |
| 2480 | 2494 |
| 2481 bool GLRenderer::UseScopedTexture(DrawingFrame* frame, | 2495 bool GLRenderer::UseScopedTexture(DrawingFrame* frame, |
| 2482 const ScopedResource* texture, | 2496 const ScopedResource* texture, |
| 2483 gfx::Rect viewport_rect) { | 2497 gfx::Rect viewport_rect) { |
| 2484 DCHECK(texture->id()); | 2498 DCHECK(texture->id()); |
| 2485 frame->current_render_pass = NULL; | 2499 frame->current_render_pass = NULL; |
| 2486 frame->current_texture = texture; | 2500 frame->current_texture = texture; |
| 2487 | 2501 |
| (...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3140 return; | 3154 return; |
| 3141 offscreen_context_labelled_ = true; | 3155 offscreen_context_labelled_ = true; |
| 3142 std::string unique_context_name = base::StringPrintf( | 3156 std::string unique_context_name = base::StringPrintf( |
| 3143 "%s-Offscreen-%p", settings_->compositor_name.c_str(), context_); | 3157 "%s-Offscreen-%p", settings_->compositor_name.c_str(), context_); |
| 3144 offscreen_context_provider->Context3d() | 3158 offscreen_context_provider->Context3d() |
| 3145 ->pushGroupMarkerEXT(unique_context_name.c_str()); | 3159 ->pushGroupMarkerEXT(unique_context_name.c_str()); |
| 3146 } | 3160 } |
| 3147 | 3161 |
| 3148 | 3162 |
| 3149 } // namespace cc | 3163 } // namespace cc |
| OLD | NEW |