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

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

Issue 21159007: cc: Adding support for RGBA_4444 tile textures (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review comments Created 7 years, 3 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 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
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 988 matching lines...) Expand 10 before | Expand all | Expand 10 after
1691 ReinitializeGLState(); 1691 ReinitializeGLState();
1692 } 1692 }
1693 1693
1694 void GLRenderer::DrawPictureQuad(const DrawingFrame* frame, 1694 void GLRenderer::DrawPictureQuad(const DrawingFrame* frame,
1695 const PictureDrawQuad* quad) { 1695 const PictureDrawQuad* quad) {
1696 if (quad->can_draw_direct_to_backbuffer && CanUseSkiaGPUBackend()) { 1696 if (quad->can_draw_direct_to_backbuffer && CanUseSkiaGPUBackend()) {
1697 DrawPictureQuadDirectToBackbuffer(frame, quad); 1697 DrawPictureQuadDirectToBackbuffer(frame, quad);
1698 return; 1698 return;
1699 } 1699 }
1700 1700
1701 ResourceFormat format = resource_provider_->best_tile_texture_format();
1701 if (on_demand_tile_raster_bitmap_.width() != quad->texture_size.width() || 1702 if (on_demand_tile_raster_bitmap_.width() != quad->texture_size.width() ||
1702 on_demand_tile_raster_bitmap_.height() != quad->texture_size.height()) { 1703 on_demand_tile_raster_bitmap_.height() != quad->texture_size.height()) {
1703 on_demand_tile_raster_bitmap_.setConfig( 1704 on_demand_tile_raster_bitmap_.setConfig(
1704 SkBitmap::kARGB_8888_Config, 1705 SkBitmap::kARGB_8888_Config,
1705 quad->texture_size.width(), 1706 quad->texture_size.width(),
1706 quad->texture_size.height()); 1707 quad->texture_size.height());
1707 on_demand_tile_raster_bitmap_.allocPixels(); 1708 on_demand_tile_raster_bitmap_.allocPixels();
1708 1709
1709 if (on_demand_tile_raster_resource_id_) 1710 if (on_demand_tile_raster_resource_id_)
1710 resource_provider_->DeleteResource(on_demand_tile_raster_resource_id_); 1711 resource_provider_->DeleteResource(on_demand_tile_raster_resource_id_);
1711 1712
1713
1712 on_demand_tile_raster_resource_id_ = resource_provider_->CreateGLTexture( 1714 on_demand_tile_raster_resource_id_ = resource_provider_->CreateGLTexture(
1713 quad->texture_size, 1715 quad->texture_size,
1714 GL_RGBA,
1715 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, 1716 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM,
1716 GL_CLAMP_TO_EDGE, 1717 GL_CLAMP_TO_EDGE,
1717 ResourceProvider::TextureUsageAny); 1718 ResourceProvider::TextureUsageAny,
1719 format);
1718 } 1720 }
1719 1721
1720 SkBitmapDevice device(on_demand_tile_raster_bitmap_); 1722 SkBitmapDevice device(on_demand_tile_raster_bitmap_);
1721 SkCanvas canvas(&device); 1723 SkCanvas canvas(&device);
1722 1724
1723 quad->picture_pile->RasterToBitmap(&canvas, quad->content_rect, 1725 quad->picture_pile->RasterToBitmap(&canvas, quad->content_rect,
1724 quad->contents_scale, NULL); 1726 quad->contents_scale, NULL);
1725 1727
1728 uint8_t* bitmap_pixels = NULL;
1729 SkBitmap on_demand_tile_raster_bitmap_dest;
1730 SkBitmap::Config config = SkBitmapConfigFromFormat(format);
1731 if (on_demand_tile_raster_bitmap_.getConfig() != config) {
1732 on_demand_tile_raster_bitmap_.copyTo(&on_demand_tile_raster_bitmap_dest,
1733 config);
1734 bitmap_pixels = reinterpret_cast<uint8_t*>(
1735 on_demand_tile_raster_bitmap_dest.getPixels());
1736 } else {
1737 bitmap_pixels = reinterpret_cast<uint8_t*>(
1738 on_demand_tile_raster_bitmap_.getPixels());
1739 }
1740
1726 resource_provider_->SetPixels( 1741 resource_provider_->SetPixels(
1727 on_demand_tile_raster_resource_id_, 1742 on_demand_tile_raster_resource_id_,
1728 reinterpret_cast<uint8_t*>(on_demand_tile_raster_bitmap_.getPixels()), 1743 bitmap_pixels,
1729 gfx::Rect(quad->texture_size), 1744 gfx::Rect(quad->texture_size),
1730 gfx::Rect(quad->texture_size), 1745 gfx::Rect(quad->texture_size),
1731 gfx::Vector2d()); 1746 gfx::Vector2d());
1732 1747
1733 DrawContentQuad(frame, quad, on_demand_tile_raster_resource_id_); 1748 DrawContentQuad(frame, quad, on_demand_tile_raster_resource_id_);
1734 } 1749 }
1735 1750
1736 struct TextureProgramBinding { 1751 struct TextureProgramBinding {
1737 template <class Program> 1752 template <class Program>
1738 void Set(Program* program, WebKit::WebGraphicsContext3D* context) { 1753 void Set(Program* program, WebKit::WebGraphicsContext3D* context) {
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
2207 unsigned int texture_id = context_->createTexture(); 2222 unsigned int texture_id = context_->createTexture();
2208 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, texture_id)); 2223 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, texture_id));
2209 GLC(context_, context_->texParameteri( 2224 GLC(context_, context_->texParameteri(
2210 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); 2225 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
2211 GLC(context_, context_->texParameteri( 2226 GLC(context_, context_->texParameteri(
2212 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); 2227 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
2213 GLC(context_, context_->texParameteri( 2228 GLC(context_, context_->texParameteri(
2214 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); 2229 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
2215 GLC(context_, context_->texParameteri( 2230 GLC(context_, context_->texParameteri(
2216 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); 2231 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
2217 GetFramebufferTexture(texture_id, GL_RGBA, window_rect); 2232 GetFramebufferTexture(texture_id, RGBA_8888, window_rect);
2218 2233
2219 gpu::Mailbox mailbox; 2234 gpu::Mailbox mailbox;
2220 unsigned sync_point = 0; 2235 unsigned sync_point = 0;
2221 GLC(context_, context_->genMailboxCHROMIUM(mailbox.name)); 2236 GLC(context_, context_->genMailboxCHROMIUM(mailbox.name));
2222 if (mailbox.IsZero()) { 2237 if (mailbox.IsZero()) {
2223 context_->deleteTexture(texture_id); 2238 context_->deleteTexture(texture_id);
2224 request->SendEmptyResult(); 2239 request->SendEmptyResult();
2225 return; 2240 return;
2226 } 2241 }
2227 2242
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
2299 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); 2314 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
2300 GLC(context_, context_->texParameteri( 2315 GLC(context_, context_->texParameteri(
2301 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); 2316 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
2302 GLC(context_, context_->texParameteri( 2317 GLC(context_, context_->texParameteri(
2303 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); 2318 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
2304 GLC(context_, context_->texParameteri( 2319 GLC(context_, context_->texParameteri(
2305 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); 2320 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
2306 // Copy the contents of the current (IOSurface-backed) framebuffer into a 2321 // Copy the contents of the current (IOSurface-backed) framebuffer into a
2307 // temporary texture. 2322 // temporary texture.
2308 GetFramebufferTexture(temporary_texture, 2323 GetFramebufferTexture(temporary_texture,
2309 GL_RGBA, 2324 RGBA_8888,
2310 gfx::Rect(current_surface_size_)); 2325 gfx::Rect(current_surface_size_));
2311 temporary_fbo = context_->createFramebuffer(); 2326 temporary_fbo = context_->createFramebuffer();
2312 // Attach this texture to an FBO, and perform the readback from that FBO. 2327 // Attach this texture to an FBO, and perform the readback from that FBO.
2313 GLC(context_, context_->bindFramebuffer(GL_FRAMEBUFFER, temporary_fbo)); 2328 GLC(context_, context_->bindFramebuffer(GL_FRAMEBUFFER, temporary_fbo));
2314 GLC(context_, context_->framebufferTexture2D(GL_FRAMEBUFFER, 2329 GLC(context_, context_->framebufferTexture2D(GL_FRAMEBUFFER,
2315 GL_COLOR_ATTACHMENT0, 2330 GL_COLOR_ATTACHMENT0,
2316 GL_TEXTURE_2D, 2331 GL_TEXTURE_2D,
2317 temporary_texture, 2332 temporary_texture,
2318 0)); 2333 0));
2319 2334
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
2449 scoped_ptr<SkAutoLockPixels> lock, 2464 scoped_ptr<SkAutoLockPixels> lock,
2450 scoped_ptr<CopyOutputRequest> request, 2465 scoped_ptr<CopyOutputRequest> request,
2451 bool success) { 2466 bool success) {
2452 DCHECK(request->force_bitmap_result()); 2467 DCHECK(request->force_bitmap_result());
2453 2468
2454 lock.reset(); 2469 lock.reset();
2455 if (success) 2470 if (success)
2456 request->SendBitmapResult(bitmap.Pass()); 2471 request->SendBitmapResult(bitmap.Pass());
2457 } 2472 }
2458 2473
2459 void GLRenderer::GetFramebufferTexture(unsigned texture_id, 2474 void GLRenderer::GetFramebufferTexture(
2460 unsigned texture_format, 2475 unsigned texture_id, ResourceFormat texture_format, gfx::Rect window_rect) {
2461 gfx::Rect window_rect) {
2462 DCHECK(texture_id); 2476 DCHECK(texture_id);
2463 DCHECK_GE(window_rect.x(), 0); 2477 DCHECK_GE(window_rect.x(), 0);
2464 DCHECK_GE(window_rect.y(), 0); 2478 DCHECK_GE(window_rect.y(), 0);
2465 DCHECK_LE(window_rect.right(), current_surface_size_.width()); 2479 DCHECK_LE(window_rect.right(), current_surface_size_.width());
2466 DCHECK_LE(window_rect.bottom(), current_surface_size_.height()); 2480 DCHECK_LE(window_rect.bottom(), current_surface_size_.height());
2467 2481
2468 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, texture_id)); 2482 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, texture_id));
2469 GLC(context_, 2483 GLC(context_,
2470 context_->copyTexImage2D(GL_TEXTURE_2D, 2484 context_->copyTexImage2D(
2471 0, 2485 GL_TEXTURE_2D,
2472 texture_format, 2486 0,
2473 window_rect.x(), 2487 ResourceProvider::GetGLDataFormat(texture_format),
2474 window_rect.y(), 2488 window_rect.x(),
2475 window_rect.width(), 2489 window_rect.y(),
2476 window_rect.height(), 2490 window_rect.width(),
2477 0)); 2491 window_rect.height(),
2492 0));
2478 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, 0)); 2493 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, 0));
2479 } 2494 }
2480 2495
2481 bool GLRenderer::UseScopedTexture(DrawingFrame* frame, 2496 bool GLRenderer::UseScopedTexture(DrawingFrame* frame,
2482 const ScopedResource* texture, 2497 const ScopedResource* texture,
2483 gfx::Rect viewport_rect) { 2498 gfx::Rect viewport_rect) {
2484 DCHECK(texture->id()); 2499 DCHECK(texture->id());
2485 frame->current_render_pass = NULL; 2500 frame->current_render_pass = NULL;
2486 frame->current_texture = texture; 2501 frame->current_texture = texture;
2487 2502
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after
3140 return; 3155 return;
3141 offscreen_context_labelled_ = true; 3156 offscreen_context_labelled_ = true;
3142 std::string unique_context_name = base::StringPrintf( 3157 std::string unique_context_name = base::StringPrintf(
3143 "%s-Offscreen-%p", settings_->compositor_name.c_str(), context_); 3158 "%s-Offscreen-%p", settings_->compositor_name.c_str(), context_);
3144 offscreen_context_provider->Context3d() 3159 offscreen_context_provider->Context3d()
3145 ->pushGroupMarkerEXT(unique_context_name.c_str()); 3160 ->pushGroupMarkerEXT(unique_context_name.c_str());
3146 } 3161 }
3147 3162
3148 3163
3149 } // namespace cc 3164 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698