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

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: Move stride check to RWP 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 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 bitmap_pixels = reinterpret_cast<uint8_t*>(
1724 on_demand_tile_raster_bitmap_dest.getPixels());
reveman 2013/09/17 22:09:38 Add the same CHECK_EQ and TODO here.
kaanb 2013/09/17 22:40:01 Done.
1725 } else {
1726 bitmap_pixels = reinterpret_cast<uint8_t*>(
1727 on_demand_tile_raster_bitmap_.getPixels());
1728 }
1729
1717 resource_provider_->SetPixels( 1730 resource_provider_->SetPixels(
1718 on_demand_tile_raster_resource_id_, 1731 on_demand_tile_raster_resource_id_,
1719 reinterpret_cast<uint8_t*>(on_demand_tile_raster_bitmap_.getPixels()), 1732 bitmap_pixels,
1720 gfx::Rect(quad->texture_size), 1733 gfx::Rect(quad->texture_size),
1721 gfx::Rect(quad->texture_size), 1734 gfx::Rect(quad->texture_size),
1722 gfx::Vector2d()); 1735 gfx::Vector2d());
1723 1736
1724 DrawContentQuad(frame, quad, on_demand_tile_raster_resource_id_); 1737 DrawContentQuad(frame, quad, on_demand_tile_raster_resource_id_);
1725 } 1738 }
1726 1739
1727 struct TextureProgramBinding { 1740 struct TextureProgramBinding {
1728 template <class Program> 1741 template <class Program>
1729 void Set(Program* program, WebKit::WebGraphicsContext3D* context) { 1742 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(); 2211 unsigned int texture_id = context_->createTexture();
2199 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, texture_id)); 2212 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, texture_id));
2200 GLC(context_, context_->texParameteri( 2213 GLC(context_, context_->texParameteri(
2201 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); 2214 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
2202 GLC(context_, context_->texParameteri( 2215 GLC(context_, context_->texParameteri(
2203 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); 2216 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
2204 GLC(context_, context_->texParameteri( 2217 GLC(context_, context_->texParameteri(
2205 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); 2218 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
2206 GLC(context_, context_->texParameteri( 2219 GLC(context_, context_->texParameteri(
2207 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); 2220 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
2208 GetFramebufferTexture(texture_id, GL_RGBA, window_rect); 2221 GetFramebufferTexture(texture_id, RGBA_8888, window_rect);
2209 2222
2210 gpu::Mailbox mailbox; 2223 gpu::Mailbox mailbox;
2211 unsigned sync_point = 0; 2224 unsigned sync_point = 0;
2212 GLC(context_, context_->genMailboxCHROMIUM(mailbox.name)); 2225 GLC(context_, context_->genMailboxCHROMIUM(mailbox.name));
2213 if (mailbox.IsZero()) { 2226 if (mailbox.IsZero()) {
2214 context_->deleteTexture(texture_id); 2227 context_->deleteTexture(texture_id);
2215 request->SendEmptyResult(); 2228 request->SendEmptyResult();
2216 return; 2229 return;
2217 } 2230 }
2218 2231
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
2290 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); 2303 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
2291 GLC(context_, context_->texParameteri( 2304 GLC(context_, context_->texParameteri(
2292 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); 2305 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
2293 GLC(context_, context_->texParameteri( 2306 GLC(context_, context_->texParameteri(
2294 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); 2307 GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
2295 GLC(context_, context_->texParameteri( 2308 GLC(context_, context_->texParameteri(
2296 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); 2309 GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
2297 // Copy the contents of the current (IOSurface-backed) framebuffer into a 2310 // Copy the contents of the current (IOSurface-backed) framebuffer into a
2298 // temporary texture. 2311 // temporary texture.
2299 GetFramebufferTexture(temporary_texture, 2312 GetFramebufferTexture(temporary_texture,
2300 GL_RGBA, 2313 RGBA_8888,
2301 gfx::Rect(current_surface_size_)); 2314 gfx::Rect(current_surface_size_));
2302 temporary_fbo = context_->createFramebuffer(); 2315 temporary_fbo = context_->createFramebuffer();
2303 // Attach this texture to an FBO, and perform the readback from that FBO. 2316 // Attach this texture to an FBO, and perform the readback from that FBO.
2304 GLC(context_, context_->bindFramebuffer(GL_FRAMEBUFFER, temporary_fbo)); 2317 GLC(context_, context_->bindFramebuffer(GL_FRAMEBUFFER, temporary_fbo));
2305 GLC(context_, context_->framebufferTexture2D(GL_FRAMEBUFFER, 2318 GLC(context_, context_->framebufferTexture2D(GL_FRAMEBUFFER,
2306 GL_COLOR_ATTACHMENT0, 2319 GL_COLOR_ATTACHMENT0,
2307 GL_TEXTURE_2D, 2320 GL_TEXTURE_2D,
2308 temporary_texture, 2321 temporary_texture,
2309 0)); 2322 0));
2310 2323
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
2440 scoped_ptr<SkAutoLockPixels> lock, 2453 scoped_ptr<SkAutoLockPixels> lock,
2441 scoped_ptr<CopyOutputRequest> request, 2454 scoped_ptr<CopyOutputRequest> request,
2442 bool success) { 2455 bool success) {
2443 DCHECK(request->force_bitmap_result()); 2456 DCHECK(request->force_bitmap_result());
2444 2457
2445 lock.reset(); 2458 lock.reset();
2446 if (success) 2459 if (success)
2447 request->SendBitmapResult(bitmap.Pass()); 2460 request->SendBitmapResult(bitmap.Pass());
2448 } 2461 }
2449 2462
2450 void GLRenderer::GetFramebufferTexture(unsigned texture_id, 2463 void GLRenderer::GetFramebufferTexture(
2451 unsigned texture_format, 2464 unsigned texture_id, ResourceFormat texture_format, gfx::Rect window_rect) {
2452 gfx::Rect window_rect) {
2453 DCHECK(texture_id); 2465 DCHECK(texture_id);
2454 DCHECK_GE(window_rect.x(), 0); 2466 DCHECK_GE(window_rect.x(), 0);
2455 DCHECK_GE(window_rect.y(), 0); 2467 DCHECK_GE(window_rect.y(), 0);
2456 DCHECK_LE(window_rect.right(), current_surface_size_.width()); 2468 DCHECK_LE(window_rect.right(), current_surface_size_.width());
2457 DCHECK_LE(window_rect.bottom(), current_surface_size_.height()); 2469 DCHECK_LE(window_rect.bottom(), current_surface_size_.height());
2458 2470
2459 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, texture_id)); 2471 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, texture_id));
2460 GLC(context_, 2472 GLC(context_,
2461 context_->copyTexImage2D(GL_TEXTURE_2D, 2473 context_->copyTexImage2D(
2462 0, 2474 GL_TEXTURE_2D,
2463 texture_format, 2475 0,
2464 window_rect.x(), 2476 ResourceProvider::GetGLDataFormat(texture_format),
2465 window_rect.y(), 2477 window_rect.x(),
2466 window_rect.width(), 2478 window_rect.y(),
2467 window_rect.height(), 2479 window_rect.width(),
2468 0)); 2480 window_rect.height(),
2481 0));
2469 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, 0)); 2482 GLC(context_, context_->bindTexture(GL_TEXTURE_2D, 0));
2470 } 2483 }
2471 2484
2472 bool GLRenderer::UseScopedTexture(DrawingFrame* frame, 2485 bool GLRenderer::UseScopedTexture(DrawingFrame* frame,
2473 const ScopedResource* texture, 2486 const ScopedResource* texture,
2474 gfx::Rect viewport_rect) { 2487 gfx::Rect viewport_rect) {
2475 DCHECK(texture->id()); 2488 DCHECK(texture->id());
2476 frame->current_render_pass = NULL; 2489 frame->current_render_pass = NULL;
2477 frame->current_texture = texture; 2490 frame->current_texture = texture;
2478 2491
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after
3119 // The Skia GPU backend requires a stencil buffer. See ReinitializeGrCanvas 3132 // The Skia GPU backend requires a stencil buffer. See ReinitializeGrCanvas
3120 // implementation. 3133 // implementation.
3121 return gr_context_ && context_->getContextAttributes().stencil; 3134 return gr_context_ && context_->getContextAttributes().stencil;
3122 } 3135 }
3123 3136
3124 bool GLRenderer::IsContextLost() { 3137 bool GLRenderer::IsContextLost() {
3125 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR); 3138 return (context_->getGraphicsResetStatusARB() != GL_NO_ERROR);
3126 } 3139 }
3127 3140
3128 } // namespace cc 3141 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698