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

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: Apply patch https://codereview.chromium.org/23503066 to fix unittests 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 635 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 988 matching lines...) Expand 10 before | Expand all | Expand 10 after
1682 ReinitializeGLState(); 1682 ReinitializeGLState();
1683 } 1683 }
1684 1684
1685 void GLRenderer::DrawPictureQuad(const DrawingFrame* frame, 1685 void GLRenderer::DrawPictureQuad(const DrawingFrame* frame,
1686 const PictureDrawQuad* quad) { 1686 const PictureDrawQuad* quad) {
1687 if (quad->can_draw_direct_to_backbuffer && CanUseSkiaGPUBackend()) { 1687 if (quad->can_draw_direct_to_backbuffer && CanUseSkiaGPUBackend()) {
1688 DrawPictureQuadDirectToBackbuffer(frame, quad); 1688 DrawPictureQuadDirectToBackbuffer(frame, quad);
1689 return; 1689 return;
1690 } 1690 }
1691 1691
1692 ResourceFormat format = resource_provider_->memory_efficient_texture_format();
1692 if (on_demand_tile_raster_bitmap_.width() != quad->texture_size.width() || 1693 if (on_demand_tile_raster_bitmap_.width() != quad->texture_size.width() ||
1693 on_demand_tile_raster_bitmap_.height() != quad->texture_size.height()) { 1694 on_demand_tile_raster_bitmap_.height() != quad->texture_size.height()) {
1694 on_demand_tile_raster_bitmap_.setConfig( 1695 on_demand_tile_raster_bitmap_.setConfig(
1695 SkBitmap::kARGB_8888_Config, 1696 SkBitmap::kARGB_8888_Config,
1696 quad->texture_size.width(), 1697 quad->texture_size.width(),
1697 quad->texture_size.height()); 1698 quad->texture_size.height());
1698 on_demand_tile_raster_bitmap_.allocPixels(); 1699 on_demand_tile_raster_bitmap_.allocPixels();
1699 1700
1700 if (on_demand_tile_raster_resource_id_) 1701 if (on_demand_tile_raster_resource_id_)
1701 resource_provider_->DeleteResource(on_demand_tile_raster_resource_id_); 1702 resource_provider_->DeleteResource(on_demand_tile_raster_resource_id_);
1702 1703
1704
reveman 2013/09/17 02:48:12 nit: no need for this blank line
kaanb 2013/09/17 04:12:18 Done.
1703 on_demand_tile_raster_resource_id_ = resource_provider_->CreateGLTexture( 1705 on_demand_tile_raster_resource_id_ = resource_provider_->CreateGLTexture(
1704 quad->texture_size, 1706 quad->texture_size,
1705 GL_RGBA,
1706 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, 1707 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM,
1707 GL_CLAMP_TO_EDGE, 1708 GL_CLAMP_TO_EDGE,
1708 ResourceProvider::TextureUsageAny); 1709 ResourceProvider::TextureUsageAny,
1710 quad->texture_format);
1709 } 1711 }
1710 1712
1711 SkBitmapDevice device(on_demand_tile_raster_bitmap_); 1713 SkBitmapDevice device(on_demand_tile_raster_bitmap_);
1712 SkCanvas canvas(&device); 1714 SkCanvas canvas(&device);
1713 1715
1714 quad->picture_pile->RasterToBitmap(&canvas, quad->content_rect, 1716 quad->picture_pile->RasterToBitmap(&canvas, quad->content_rect,
1715 quad->contents_scale, NULL); 1717 quad->contents_scale, NULL);
1716 1718
1719 uint8_t* bitmap_pixels = NULL;
1720 SkBitmap on_demand_tile_raster_bitmap_dest;
1721 SkBitmap::Config config = SkBitmapConfigFromFormat(format);
reveman 2013/09/17 02:48:12 this should be using quad->texture_format
kaanb 2013/09/17 04:12:18 Done.
1722 if (on_demand_tile_raster_bitmap_.getConfig() != config) {
1723 on_demand_tile_raster_bitmap_.copyTo(&on_demand_tile_raster_bitmap_dest,
1724 config);
1725 bitmap_pixels = reinterpret_cast<uint8_t*>(
1726 on_demand_tile_raster_bitmap_dest.getPixels());
1727 } else {
1728 bitmap_pixels = reinterpret_cast<uint8_t*>(
1729 on_demand_tile_raster_bitmap_.getPixels());
1730 }
1731
1717 resource_provider_->SetPixels( 1732 resource_provider_->SetPixels(
1718 on_demand_tile_raster_resource_id_, 1733 on_demand_tile_raster_resource_id_,
1719 reinterpret_cast<uint8_t*>(on_demand_tile_raster_bitmap_.getPixels()), 1734 bitmap_pixels,
1720 gfx::Rect(quad->texture_size), 1735 gfx::Rect(quad->texture_size),
1721 gfx::Rect(quad->texture_size), 1736 gfx::Rect(quad->texture_size),
1722 gfx::Vector2d()); 1737 gfx::Vector2d());
1723 1738
1724 DrawContentQuad(frame, quad, on_demand_tile_raster_resource_id_); 1739 DrawContentQuad(frame, quad, on_demand_tile_raster_resource_id_);
1725 } 1740 }
1726 1741
1727 struct TextureProgramBinding { 1742 struct TextureProgramBinding {
1728 template <class Program> 1743 template <class Program>
1729 void Set(Program* program, WebKit::WebGraphicsContext3D* context) { 1744 void Set(Program* program, WebKit::WebGraphicsContext3D* context) {
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
2198 unsigned int texture_id = context_->createTexture(); 2213 unsigned int texture_id = context_->createTexture();
2199 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, texture_id)); 2214 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, texture_id));
2200 GLC(context_, context_->texParameteri( 2215 GLC(context_, context_->texParameteri(
2201 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); 2216 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
2202 GLC(context_, context_->texParameteri( 2217 GLC(context_, context_->texParameteri(
2203 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); 2218 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
2204 GLC(context_, context_->texParameteri( 2219 GLC(context_, context_->texParameteri(
2205 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); 2220 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
2206 GLC(context_, context_->texParameteri( 2221 GLC(context_, context_->texParameteri(
2207 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); 2222 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
2208 GetFramebufferTexture(texture_id, GL_RGBA, window_rect); 2223 GetFramebufferTexture(texture_id, RGBA_8888, window_rect);
2209 2224
2210 gpu::Mailbox mailbox; 2225 gpu::Mailbox mailbox;
2211 unsigned sync_point = 0; 2226 unsigned sync_point = 0;
2212 GLC(context_, context_->genMailboxCHROMIUM(mailbox.name)); 2227 GLC(context_, context_->genMailboxCHROMIUM(mailbox.name));
2213 if (mailbox.IsZero()) { 2228 if (mailbox.IsZero()) {
2214 context_->deleteTexture(texture_id); 2229 context_->deleteTexture(texture_id);
2215 request->SendEmptyResult(); 2230 request->SendEmptyResult();
2216 return; 2231 return;
2217 } 2232 }
2218 2233
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
2290 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); 2305 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
2291 GLC(context_, context_->texParameteri( 2306 GLC(context_, context_->texParameteri(
2292 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); 2307 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
2293 GLC(context_, context_->texParameteri( 2308 GLC(context_, context_->texParameteri(
2294 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); 2309 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
2295 GLC(context_, context_->texParameteri( 2310 GLC(context_, context_->texParameteri(
2296 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); 2311 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
2297 // Copy the contents of the current (IOSurface-backed) framebuffer into a 2312 // Copy the contents of the current (IOSurface-backed) framebuffer into a
2298 // temporary texture. 2313 // temporary texture.
2299 GetFramebufferTexture(temporary_texture, 2314 GetFramebufferTexture(temporary_texture,
2300 GL_RGBA, 2315 RGBA_8888,
2301 gfx::Rect(current_surface_size_)); 2316 gfx::Rect(current_surface_size_));
2302 temporary_fbo = context_->createFramebuffer(); 2317 temporary_fbo = context_->createFramebuffer();
2303 // Attach this texture to an FBO, and perform the readback from that FBO. 2318 // Attach this texture to an FBO, and perform the readback from that FBO.
2304 GLC(context_, context_->bindFramebuffer(GL_FRAMEBUFFER, temporary_fbo)); 2319 GLC(context_, context_->bindFramebuffer(GL_FRAMEBUFFER, temporary_fbo));
2305 GLC(context_, context_->framebufferTexture2D(GL_FRAMEBUFFER, 2320 GLC(context_, context_->framebufferTexture2D(GL_FRAMEBUFFER,
2306 GL_COLOR_ATTACHMENT0, 2321 GL_COLOR_ATTACHMENT0,
2307 GL_TEXTURE_2D, 2322 GL_TEXTURE_2D,
2308 temporary_texture, 2323 temporary_texture,
2309 0)); 2324 0));
2310 2325
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
2440 scoped_ptr<SkAutoLockPixels> lock, 2455 scoped_ptr<SkAutoLockPixels> lock,
2441 scoped_ptr<CopyOutputRequest> request, 2456 scoped_ptr<CopyOutputRequest> request,
2442 bool success) { 2457 bool success) {
2443 DCHECK(request->force_bitmap_result()); 2458 DCHECK(request->force_bitmap_result());
2444 2459
2445 lock.reset(); 2460 lock.reset();
2446 if (success) 2461 if (success)
2447 request->SendBitmapResult(bitmap.Pass()); 2462 request->SendBitmapResult(bitmap.Pass());
2448 } 2463 }
2449 2464
2450 void GLRenderer::GetFramebufferTexture(unsigned texture_id, 2465 void GLRenderer::GetFramebufferTexture(
2451 unsigned texture_format, 2466 unsigned texture_id, ResourceFormat texture_format, gfx::Rect window_rect) {
2452 gfx::Rect window_rect) {
2453 DCHECK(texture_id); 2467 DCHECK(texture_id);
2454 DCHECK_GE(window_rect.x(), 0); 2468 DCHECK_GE(window_rect.x(), 0);
2455 DCHECK_GE(window_rect.y(), 0); 2469 DCHECK_GE(window_rect.y(), 0);
2456 DCHECK_LE(window_rect.right(), current_surface_size_.width()); 2470 DCHECK_LE(window_rect.right(), current_surface_size_.width());
2457 DCHECK_LE(window_rect.bottom(), current_surface_size_.height()); 2471 DCHECK_LE(window_rect.bottom(), current_surface_size_.height());
2458 2472
2459 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, texture_id)); 2473 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, texture_id));
2460 GLC(context_, 2474 GLC(context_,
2461 context_->copyTexImage2D(GL_TEXTURE_2D, 2475 context_->copyTexImage2D(
2462 0, 2476 GL_TEXTURE_2D,
2463 texture_format, 2477 0,
2464 window_rect.x(), 2478 ResourceProvider::GetGLDataFormat(texture_format),
2465 window_rect.y(), 2479 window_rect.x(),
2466 window_rect.width(), 2480 window_rect.y(),
2467 window_rect.height(), 2481 window_rect.width(),
2468 0)); 2482 window_rect.height(),
2483 0));
2469 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, 0)); 2484 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, 0));
2470 } 2485 }
2471 2486
2472 bool GLRenderer::UseScopedTexture(DrawingFrame* frame, 2487 bool GLRenderer::UseScopedTexture(DrawingFrame* frame,
2473 const ScopedResource* texture, 2488 const ScopedResource* texture,
2474 gfx::Rect viewport_rect) { 2489 gfx::Rect viewport_rect) {
2475 DCHECK(texture->id()); 2490 DCHECK(texture->id());
2476 frame->current_render_pass = NULL; 2491 frame->current_render_pass = NULL;
2477 frame->current_texture = texture; 2492 frame->current_texture = texture;
2478 2493
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after
3119 // The Skia GPU backend requires a stencil buffer. See ReinitializeGrCanvas 3134 // The Skia GPU backend requires a stencil buffer. See ReinitializeGrCanvas
3120 // implementation. 3135 // implementation.
3121 return gr_context_ && context_->getContextAttributes().stencil; 3136 return gr_context_ && context_->getContextAttributes().stencil;
3122 } 3137 }
3123 3138
3124 bool GLRenderer::IsContextLost() { 3139 bool GLRenderer::IsContextLost() {
3125 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR); 3140 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR);
3126 } 3141 }
3127 3142
3128 } // namespace cc 3143 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698