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 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 int top, right, bottom, left; | 646 int top, right, bottom, left; |
647 filters.GetOutsets(&top, &right, &bottom, &left); | 647 filters.GetOutsets(&top, &right, &bottom, &left); |
648 window_rect.Inset(-left, -top, -right, -bottom); | 648 window_rect.Inset(-left, -top, -right, -bottom); |
649 | 649 |
650 window_rect.Intersect( | 650 window_rect.Intersect( |
651 MoveFromDrawToWindowSpace(frame->current_render_pass->output_rect)); | 651 MoveFromDrawToWindowSpace(frame->current_render_pass->output_rect)); |
652 | 652 |
653 scoped_ptr<ScopedResource> device_background_texture = | 653 scoped_ptr<ScopedResource> device_background_texture = |
654 ScopedResource::create(resource_provider_); | 654 ScopedResource::create(resource_provider_); |
655 if (!device_background_texture->Allocate(window_rect.size(), | 655 if (!device_background_texture->Allocate(window_rect.size(), |
656 GL_RGB, | 656 ResourceProvider::TextureUsageAny, |
657 ResourceProvider::TextureUsageAny)) { | 657 RGBA_8888)) { |
658 return scoped_ptr<ScopedResource>(); | 658 return scoped_ptr<ScopedResource>(); |
659 } else { | 659 } else { |
660 ResourceProvider::ScopedWriteLockGL lock(resource_provider_, | 660 ResourceProvider::ScopedWriteLockGL lock(resource_provider_, |
661 device_background_texture->id()); | 661 device_background_texture->id()); |
662 GetFramebufferTexture(lock.texture_id(), | 662 GetFramebufferTexture(lock.texture_id(), |
663 device_background_texture->format(), | 663 device_background_texture->format(), |
664 window_rect); | 664 window_rect); |
665 } | 665 } |
666 | 666 |
667 SkBitmap filtered_device_background = | 667 SkBitmap filtered_device_background = |
668 ApplyFilters(this, | 668 ApplyFilters(this, |
669 frame->offscreen_context_provider, | 669 frame->offscreen_context_provider, |
670 filters, | 670 filters, |
671 device_background_texture.get()); | 671 device_background_texture.get()); |
672 if (!filtered_device_background.getTexture()) | 672 if (!filtered_device_background.getTexture()) |
673 return scoped_ptr<ScopedResource>(); | 673 return scoped_ptr<ScopedResource>(); |
674 | 674 |
675 GrTexture* texture = | 675 GrTexture* texture = |
676 reinterpret_cast<GrTexture*>(filtered_device_background.getTexture()); | 676 reinterpret_cast<GrTexture*>(filtered_device_background.getTexture()); |
677 int filtered_device_background_texture_id = texture->getTextureHandle(); | 677 int filtered_device_background_texture_id = texture->getTextureHandle(); |
678 | 678 |
679 scoped_ptr<ScopedResource> background_texture = | 679 scoped_ptr<ScopedResource> background_texture = |
680 ScopedResource::create(resource_provider_); | 680 ScopedResource::create(resource_provider_); |
681 if (!background_texture->Allocate(quad->rect.size(), | 681 if (!background_texture->Allocate(quad->rect.size(), |
682 GL_RGBA, | 682 ResourceProvider::TextureUsageFramebuffer, |
683 ResourceProvider::TextureUsageFramebuffer)) | 683 RGBA_8888)) |
684 return scoped_ptr<ScopedResource>(); | 684 return scoped_ptr<ScopedResource>(); |
685 | 685 |
686 const RenderPass* target_render_pass = frame->current_render_pass; | 686 const RenderPass* target_render_pass = frame->current_render_pass; |
687 bool using_background_texture = | 687 bool using_background_texture = |
688 UseScopedTexture(frame, background_texture.get(), quad->rect); | 688 UseScopedTexture(frame, background_texture.get(), quad->rect); |
689 | 689 |
690 if (using_background_texture) { | 690 if (using_background_texture) { |
691 // Copy the readback pixels from device to the background texture for the | 691 // Copy the readback pixels from device to the background texture for the |
692 // surface. | 692 // surface. |
693 gfx::Transform device_to_framebuffer_transform; | 693 gfx::Transform device_to_framebuffer_transform; |
(...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1695 SkBitmap::kARGB_8888_Config, | 1695 SkBitmap::kARGB_8888_Config, |
1696 quad->texture_size.width(), | 1696 quad->texture_size.width(), |
1697 quad->texture_size.height()); | 1697 quad->texture_size.height()); |
1698 on_demand_tile_raster_bitmap_.allocPixels(); | 1698 on_demand_tile_raster_bitmap_.allocPixels(); |
1699 | 1699 |
1700 if (on_demand_tile_raster_resource_id_) | 1700 if (on_demand_tile_raster_resource_id_) |
1701 resource_provider_->DeleteResource(on_demand_tile_raster_resource_id_); | 1701 resource_provider_->DeleteResource(on_demand_tile_raster_resource_id_); |
1702 | 1702 |
1703 on_demand_tile_raster_resource_id_ = resource_provider_->CreateGLTexture( | 1703 on_demand_tile_raster_resource_id_ = resource_provider_->CreateGLTexture( |
1704 quad->texture_size, | 1704 quad->texture_size, |
1705 GL_RGBA, | |
1706 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, | 1705 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, |
1707 GL_CLAMP_TO_EDGE, | 1706 GL_CLAMP_TO_EDGE, |
1708 ResourceProvider::TextureUsageAny); | 1707 ResourceProvider::TextureUsageAny, |
| 1708 quad->texture_format); |
1709 } | 1709 } |
1710 | 1710 |
1711 SkBitmapDevice device(on_demand_tile_raster_bitmap_); | 1711 SkBitmapDevice device(on_demand_tile_raster_bitmap_); |
1712 SkCanvas canvas(&device); | 1712 SkCanvas canvas(&device); |
1713 | 1713 |
1714 quad->picture_pile->RasterToBitmap(&canvas, quad->content_rect, | 1714 quad->picture_pile->RasterToBitmap(&canvas, quad->content_rect, |
1715 quad->contents_scale, NULL); | 1715 quad->contents_scale, NULL); |
1716 | 1716 |
| 1717 uint8_t* bitmap_pixels = NULL; |
| 1718 SkBitmap on_demand_tile_raster_bitmap_dest; |
| 1719 SkBitmap::Config config = SkBitmapConfigFromFormat(quad->texture_format); |
| 1720 if (on_demand_tile_raster_bitmap_.getConfig() != config) { |
| 1721 on_demand_tile_raster_bitmap_.copyTo(&on_demand_tile_raster_bitmap_dest, |
| 1722 config); |
| 1723 // TODO(kaanb): The GL pipeline assumes a 4-byte alignment for the |
| 1724 // bitmap data. This check will be removed once crbug.com/293728 is fixed. |
| 1725 CHECK_EQ(0u, on_demand_tile_raster_bitmap_dest.rowBytes() % 4); |
| 1726 bitmap_pixels = reinterpret_cast<uint8_t*>( |
| 1727 on_demand_tile_raster_bitmap_dest.getPixels()); |
| 1728 } else { |
| 1729 bitmap_pixels = reinterpret_cast<uint8_t*>( |
| 1730 on_demand_tile_raster_bitmap_.getPixels()); |
| 1731 } |
| 1732 |
1717 resource_provider_->SetPixels( | 1733 resource_provider_->SetPixels( |
1718 on_demand_tile_raster_resource_id_, | 1734 on_demand_tile_raster_resource_id_, |
1719 reinterpret_cast<uint8_t*>(on_demand_tile_raster_bitmap_.getPixels()), | 1735 bitmap_pixels, |
1720 gfx::Rect(quad->texture_size), | 1736 gfx::Rect(quad->texture_size), |
1721 gfx::Rect(quad->texture_size), | 1737 gfx::Rect(quad->texture_size), |
1722 gfx::Vector2d()); | 1738 gfx::Vector2d()); |
1723 | 1739 |
1724 DrawContentQuad(frame, quad, on_demand_tile_raster_resource_id_); | 1740 DrawContentQuad(frame, quad, on_demand_tile_raster_resource_id_); |
1725 } | 1741 } |
1726 | 1742 |
1727 struct TextureProgramBinding { | 1743 struct TextureProgramBinding { |
1728 template <class Program> | 1744 template <class Program> |
1729 void Set(Program* program, WebKit::WebGraphicsContext3D* context) { | 1745 void Set(Program* program, WebKit::WebGraphicsContext3D* context) { |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2198 unsigned int texture_id = context_->createTexture(); | 2214 unsigned int texture_id = context_->createTexture(); |
2199 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, texture_id)); | 2215 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, texture_id)); |
2200 GLC(context_, context_->texParameteri( | 2216 GLC(context_, context_->texParameteri( |
2201 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); | 2217 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); |
2202 GLC(context_, context_->texParameteri( | 2218 GLC(context_, context_->texParameteri( |
2203 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); | 2219 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); |
2204 GLC(context_, context_->texParameteri( | 2220 GLC(context_, context_->texParameteri( |
2205 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); | 2221 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); |
2206 GLC(context_, context_->texParameteri( | 2222 GLC(context_, context_->texParameteri( |
2207 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); | 2223 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); |
2208 GetFramebufferTexture(texture_id, GL_RGBA, window_rect); | 2224 GetFramebufferTexture(texture_id, RGBA_8888, window_rect); |
2209 | 2225 |
2210 gpu::Mailbox mailbox; | 2226 gpu::Mailbox mailbox; |
2211 unsigned sync_point = 0; | 2227 unsigned sync_point = 0; |
2212 GLC(context_, context_->genMailboxCHROMIUM(mailbox.name)); | 2228 GLC(context_, context_->genMailboxCHROMIUM(mailbox.name)); |
2213 if (mailbox.IsZero()) { | 2229 if (mailbox.IsZero()) { |
2214 context_->deleteTexture(texture_id); | 2230 context_->deleteTexture(texture_id); |
2215 request->SendEmptyResult(); | 2231 request->SendEmptyResult(); |
2216 return; | 2232 return; |
2217 } | 2233 } |
2218 | 2234 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2290 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); | 2306 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); |
2291 GLC(context_, context_->texParameteri( | 2307 GLC(context_, context_->texParameteri( |
2292 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); | 2308 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); |
2293 GLC(context_, context_->texParameteri( | 2309 GLC(context_, context_->texParameteri( |
2294 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); | 2310 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); |
2295 GLC(context_, context_->texParameteri( | 2311 GLC(context_, context_->texParameteri( |
2296 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); | 2312 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); |
2297 // Copy the contents of the current (IOSurface-backed) framebuffer into a | 2313 // Copy the contents of the current (IOSurface-backed) framebuffer into a |
2298 // temporary texture. | 2314 // temporary texture. |
2299 GetFramebufferTexture(temporary_texture, | 2315 GetFramebufferTexture(temporary_texture, |
2300 GL_RGBA, | 2316 RGBA_8888, |
2301 gfx::Rect(current_surface_size_)); | 2317 gfx::Rect(current_surface_size_)); |
2302 temporary_fbo = context_->createFramebuffer(); | 2318 temporary_fbo = context_->createFramebuffer(); |
2303 // Attach this texture to an FBO, and perform the readback from that FBO. | 2319 // Attach this texture to an FBO, and perform the readback from that FBO. |
2304 GLC(context_, context_->bindFramebuffer(GL_FRAMEBUFFER, temporary_fbo)); | 2320 GLC(context_, context_->bindFramebuffer(GL_FRAMEBUFFER, temporary_fbo)); |
2305 GLC(context_, context_->framebufferTexture2D(GL_FRAMEBUFFER, | 2321 GLC(context_, context_->framebufferTexture2D(GL_FRAMEBUFFER, |
2306 GL_COLOR_ATTACHMENT0, | 2322 GL_COLOR_ATTACHMENT0, |
2307 GL_TEXTURE_2D, | 2323 GL_TEXTURE_2D, |
2308 temporary_texture, | 2324 temporary_texture, |
2309 0)); | 2325 0)); |
2310 | 2326 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2440 scoped_ptr<SkAutoLockPixels> lock, | 2456 scoped_ptr<SkAutoLockPixels> lock, |
2441 scoped_ptr<CopyOutputRequest> request, | 2457 scoped_ptr<CopyOutputRequest> request, |
2442 bool success) { | 2458 bool success) { |
2443 DCHECK(request->force_bitmap_result()); | 2459 DCHECK(request->force_bitmap_result()); |
2444 | 2460 |
2445 lock.reset(); | 2461 lock.reset(); |
2446 if (success) | 2462 if (success) |
2447 request->SendBitmapResult(bitmap.Pass()); | 2463 request->SendBitmapResult(bitmap.Pass()); |
2448 } | 2464 } |
2449 | 2465 |
2450 void GLRenderer::GetFramebufferTexture(unsigned texture_id, | 2466 void GLRenderer::GetFramebufferTexture( |
2451 unsigned texture_format, | 2467 unsigned texture_id, ResourceFormat texture_format, gfx::Rect window_rect) { |
2452 gfx::Rect window_rect) { | |
2453 DCHECK(texture_id); | 2468 DCHECK(texture_id); |
2454 DCHECK_GE(window_rect.x(), 0); | 2469 DCHECK_GE(window_rect.x(), 0); |
2455 DCHECK_GE(window_rect.y(), 0); | 2470 DCHECK_GE(window_rect.y(), 0); |
2456 DCHECK_LE(window_rect.right(), current_surface_size_.width()); | 2471 DCHECK_LE(window_rect.right(), current_surface_size_.width()); |
2457 DCHECK_LE(window_rect.bottom(), current_surface_size_.height()); | 2472 DCHECK_LE(window_rect.bottom(), current_surface_size_.height()); |
2458 | 2473 |
2459 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, texture_id)); | 2474 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, texture_id)); |
2460 GLC(context_, | 2475 GLC(context_, |
2461 context_->copyTexImage2D(GL_TEXTURE_2D, | 2476 context_->copyTexImage2D( |
2462 0, | 2477 GL_TEXTURE_2D, |
2463 texture_format, | 2478 0, |
2464 window_rect.x(), | 2479 ResourceProvider::GetGLDataFormat(texture_format), |
2465 window_rect.y(), | 2480 window_rect.x(), |
2466 window_rect.width(), | 2481 window_rect.y(), |
2467 window_rect.height(), | 2482 window_rect.width(), |
2468 0)); | 2483 window_rect.height(), |
| 2484 0)); |
2469 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, 0)); | 2485 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, 0)); |
2470 } | 2486 } |
2471 | 2487 |
2472 bool GLRenderer::UseScopedTexture(DrawingFrame* frame, | 2488 bool GLRenderer::UseScopedTexture(DrawingFrame* frame, |
2473 const ScopedResource* texture, | 2489 const ScopedResource* texture, |
2474 gfx::Rect viewport_rect) { | 2490 gfx::Rect viewport_rect) { |
2475 DCHECK(texture->id()); | 2491 DCHECK(texture->id()); |
2476 frame->current_render_pass = NULL; | 2492 frame->current_render_pass = NULL; |
2477 frame->current_texture = texture; | 2493 frame->current_texture = texture; |
2478 | 2494 |
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3119 // The Skia GPU backend requires a stencil buffer. See ReinitializeGrCanvas | 3135 // The Skia GPU backend requires a stencil buffer. See ReinitializeGrCanvas |
3120 // implementation. | 3136 // implementation. |
3121 return gr_context_ && context_->getContextAttributes().stencil; | 3137 return gr_context_ && context_->getContextAttributes().stencil; |
3122 } | 3138 } |
3123 | 3139 |
3124 bool GLRenderer::IsContextLost() { | 3140 bool GLRenderer::IsContextLost() { |
3125 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR); | 3141 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR); |
3126 } | 3142 } |
3127 | 3143 |
3128 } // namespace cc | 3144 } // namespace cc |
OLD | NEW |