Chromium Code Reviews| 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 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 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 ? RGBA_4444 : RGBA_8888); | |
|
reveman
2013/09/14 00:58:39
I think this should be using resource_provider->be
kaanb
2013/09/16 07:22:25
Yes, since previously GL_RGBA was hardcoded, raste
| |
| 1718 } | 1718 } |
| 1719 | 1719 |
| 1720 SkBitmapDevice device(on_demand_tile_raster_bitmap_); | 1720 SkBitmapDevice device(on_demand_tile_raster_bitmap_); |
| 1721 SkCanvas canvas(&device); | 1721 SkCanvas canvas(&device); |
| 1722 | 1722 |
| 1723 quad->picture_pile->RasterToBitmap(&canvas, quad->content_rect, | 1723 quad->picture_pile->RasterToBitmap(&canvas, quad->content_rect, |
| 1724 quad->contents_scale, NULL); | 1724 quad->contents_scale, NULL); |
| 1725 | 1725 |
| 1726 const uint8_t* bitmap_pixels = NULL; | |
| 1727 if (settings_->use_rgba_4444_textures) { | |
|
reveman
2013/09/14 00:58:39
I think this code should be similar to PBRWP code
kaanb
2013/09/16 07:22:25
Done.
| |
| 1728 on_demand_tile_raster_bitmap_.copyTo( | |
| 1729 &on_demand_tile_raster_bitmap_4444_, SkBitmap::kARGB_4444_Config); | |
| 1730 bitmap_pixels = reinterpret_cast<uint8_t*>( | |
| 1731 on_demand_tile_raster_bitmap_4444_.getPixels()); | |
|
reveman
2013/09/14 00:58:39
does caching on_demand_tile_raster_bitmap_4444_ re
kaanb
2013/09/16 07:22:25
Done.
| |
| 1732 } else { | |
| 1733 bitmap_pixels = reinterpret_cast<uint8_t*>( | |
| 1734 on_demand_tile_raster_bitmap_.getPixels()); | |
| 1735 } | |
| 1736 | |
| 1726 resource_provider_->SetPixels( | 1737 resource_provider_->SetPixels( |
| 1727 on_demand_tile_raster_resource_id_, | 1738 on_demand_tile_raster_resource_id_, |
| 1728 reinterpret_cast<uint8_t*>(on_demand_tile_raster_bitmap_.getPixels()), | 1739 bitmap_pixels, |
| 1729 gfx::Rect(quad->texture_size), | 1740 gfx::Rect(quad->texture_size), |
| 1730 gfx::Rect(quad->texture_size), | 1741 gfx::Rect(quad->texture_size), |
| 1731 gfx::Vector2d()); | 1742 gfx::Vector2d()); |
| 1732 | 1743 |
| 1733 DrawContentQuad(frame, quad, on_demand_tile_raster_resource_id_); | 1744 DrawContentQuad(frame, quad, on_demand_tile_raster_resource_id_); |
| 1734 } | 1745 } |
| 1735 | 1746 |
| 1736 struct TextureProgramBinding { | 1747 struct TextureProgramBinding { |
| 1737 template <class Program> | 1748 template <class Program> |
| 1738 void Set(Program* program, WebKit::WebGraphicsContext3D* context) { | 1749 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(); | 2218 unsigned int texture_id = context_->createTexture(); |
| 2208 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, texture_id)); | 2219 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, texture_id)); |
| 2209 GLC(context_, context_->texParameteri( | 2220 GLC(context_, context_->texParameteri( |
| 2210 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); | 2221 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); |
| 2211 GLC(context_, context_->texParameteri( | 2222 GLC(context_, context_->texParameteri( |
| 2212 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); | 2223 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); |
| 2213 GLC(context_, context_->texParameteri( | 2224 GLC(context_, context_->texParameteri( |
| 2214 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); | 2225 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); |
| 2215 GLC(context_, context_->texParameteri( | 2226 GLC(context_, context_->texParameteri( |
| 2216 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); | 2227 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); |
| 2217 GetFramebufferTexture(texture_id, GL_RGBA, window_rect); | 2228 GetFramebufferTexture(texture_id, RGBA_8888, window_rect); |
| 2218 | 2229 |
| 2219 gpu::Mailbox mailbox; | 2230 gpu::Mailbox mailbox; |
| 2220 unsigned sync_point = 0; | 2231 unsigned sync_point = 0; |
| 2221 GLC(context_, context_->genMailboxCHROMIUM(mailbox.name)); | 2232 GLC(context_, context_->genMailboxCHROMIUM(mailbox.name)); |
| 2222 if (mailbox.IsZero()) { | 2233 if (mailbox.IsZero()) { |
| 2223 context_->deleteTexture(texture_id); | 2234 context_->deleteTexture(texture_id); |
| 2224 request->SendEmptyResult(); | 2235 request->SendEmptyResult(); |
| 2225 return; | 2236 return; |
| 2226 } | 2237 } |
| 2227 | 2238 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2299 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); | 2310 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); |
| 2300 GLC(context_, context_->texParameteri( | 2311 GLC(context_, context_->texParameteri( |
| 2301 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); | 2312 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); |
| 2302 GLC(context_, context_->texParameteri( | 2313 GLC(context_, context_->texParameteri( |
| 2303 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); | 2314 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); |
| 2304 GLC(context_, context_->texParameteri( | 2315 GLC(context_, context_->texParameteri( |
| 2305 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); | 2316 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); |
| 2306 // Copy the contents of the current (IOSurface-backed) framebuffer into a | 2317 // Copy the contents of the current (IOSurface-backed) framebuffer into a |
| 2307 // temporary texture. | 2318 // temporary texture. |
| 2308 GetFramebufferTexture(temporary_texture, | 2319 GetFramebufferTexture(temporary_texture, |
| 2309 GL_RGBA, | 2320 RGBA_8888, |
| 2310 gfx::Rect(current_surface_size_)); | 2321 gfx::Rect(current_surface_size_)); |
| 2311 temporary_fbo = context_->createFramebuffer(); | 2322 temporary_fbo = context_->createFramebuffer(); |
| 2312 // Attach this texture to an FBO, and perform the readback from that FBO. | 2323 // Attach this texture to an FBO, and perform the readback from that FBO. |
| 2313 GLC(context_, context_->bindFramebuffer(GL_FRAMEBUFFER, temporary_fbo)); | 2324 GLC(context_, context_->bindFramebuffer(GL_FRAMEBUFFER, temporary_fbo)); |
| 2314 GLC(context_, context_->framebufferTexture2D(GL_FRAMEBUFFER, | 2325 GLC(context_, context_->framebufferTexture2D(GL_FRAMEBUFFER, |
| 2315 GL_COLOR_ATTACHMENT0, | 2326 GL_COLOR_ATTACHMENT0, |
| 2316 GL_TEXTURE_2D, | 2327 GL_TEXTURE_2D, |
| 2317 temporary_texture, | 2328 temporary_texture, |
| 2318 0)); | 2329 0)); |
| 2319 | 2330 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2449 scoped_ptr<SkAutoLockPixels> lock, | 2460 scoped_ptr<SkAutoLockPixels> lock, |
| 2450 scoped_ptr<CopyOutputRequest> request, | 2461 scoped_ptr<CopyOutputRequest> request, |
| 2451 bool success) { | 2462 bool success) { |
| 2452 DCHECK(request->force_bitmap_result()); | 2463 DCHECK(request->force_bitmap_result()); |
| 2453 | 2464 |
| 2454 lock.reset(); | 2465 lock.reset(); |
| 2455 if (success) | 2466 if (success) |
| 2456 request->SendBitmapResult(bitmap.Pass()); | 2467 request->SendBitmapResult(bitmap.Pass()); |
| 2457 } | 2468 } |
| 2458 | 2469 |
| 2459 void GLRenderer::GetFramebufferTexture(unsigned texture_id, | 2470 void GLRenderer::GetFramebufferTexture( |
| 2460 unsigned texture_format, | 2471 unsigned texture_id, ResourceFormat texture_format, gfx::Rect window_rect) { |
| 2461 gfx::Rect window_rect) { | |
| 2462 DCHECK(texture_id); | 2472 DCHECK(texture_id); |
| 2463 DCHECK_GE(window_rect.x(), 0); | 2473 DCHECK_GE(window_rect.x(), 0); |
| 2464 DCHECK_GE(window_rect.y(), 0); | 2474 DCHECK_GE(window_rect.y(), 0); |
| 2465 DCHECK_LE(window_rect.right(), current_surface_size_.width()); | 2475 DCHECK_LE(window_rect.right(), current_surface_size_.width()); |
| 2466 DCHECK_LE(window_rect.bottom(), current_surface_size_.height()); | 2476 DCHECK_LE(window_rect.bottom(), current_surface_size_.height()); |
| 2467 | 2477 |
| 2468 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, texture_id)); | 2478 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, texture_id)); |
| 2469 GLC(context_, | 2479 GLC(context_, |
| 2470 context_->copyTexImage2D(GL_TEXTURE_2D, | 2480 context_->copyTexImage2D( |
| 2471 0, | 2481 GL_TEXTURE_2D, |
| 2472 texture_format, | 2482 0, |
| 2473 window_rect.x(), | 2483 ResourceProvider::GetGLDataFormat(texture_format), |
| 2474 window_rect.y(), | 2484 window_rect.x(), |
| 2475 window_rect.width(), | 2485 window_rect.y(), |
| 2476 window_rect.height(), | 2486 window_rect.width(), |
| 2477 0)); | 2487 window_rect.height(), |
| 2488 0)); | |
| 2478 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, 0)); | 2489 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, 0)); |
| 2479 } | 2490 } |
| 2480 | 2491 |
| 2481 bool GLRenderer::UseScopedTexture(DrawingFrame* frame, | 2492 bool GLRenderer::UseScopedTexture(DrawingFrame* frame, |
| 2482 const ScopedResource* texture, | 2493 const ScopedResource* texture, |
| 2483 gfx::Rect viewport_rect) { | 2494 gfx::Rect viewport_rect) { |
| 2484 DCHECK(texture->id()); | 2495 DCHECK(texture->id()); |
| 2485 frame->current_render_pass = NULL; | 2496 frame->current_render_pass = NULL; |
| 2486 frame->current_texture = texture; | 2497 frame->current_texture = texture; |
| 2487 | 2498 |
| (...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3140 return; | 3151 return; |
| 3141 offscreen_context_labelled_ = true; | 3152 offscreen_context_labelled_ = true; |
| 3142 std::string unique_context_name = base::StringPrintf( | 3153 std::string unique_context_name = base::StringPrintf( |
| 3143 "%s-Offscreen-%p", settings_->compositor_name.c_str(), context_); | 3154 "%s-Offscreen-%p", settings_->compositor_name.c_str(), context_); |
| 3144 offscreen_context_provider->Context3d() | 3155 offscreen_context_provider->Context3d() |
| 3145 ->pushGroupMarkerEXT(unique_context_name.c_str()); | 3156 ->pushGroupMarkerEXT(unique_context_name.c_str()); |
| 3146 } | 3157 } |
| 3147 | 3158 |
| 3148 | 3159 |
| 3149 } // namespace cc | 3160 } // namespace cc |
| OLD | NEW |