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

Side by Side Diff: cc/resources/resource_provider.cc

Issue 486853002: cc: Use a normal texture for background texture. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add TextureHintImmutableFramebuffer because fbo binding immutable texture is efficient. Created 6 years, 4 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/resources/resource_provider.h" 5 #include "cc/resources/resource_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/containers/hash_tables.h" 10 #include "base/containers/hash_tables.h"
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 read_lock_fence(NULL), 241 read_lock_fence(NULL),
242 size(), 242 size(),
243 origin(Internal), 243 origin(Internal),
244 target(0), 244 target(0),
245 original_filter(0), 245 original_filter(0),
246 filter(0), 246 filter(0),
247 image_id(0), 247 image_id(0),
248 bound_image_id(0), 248 bound_image_id(0),
249 texture_pool(0), 249 texture_pool(0),
250 wrap_mode(0), 250 wrap_mode(0),
251 hint(TextureUsageAny), 251 hint(TextureHintImmutable),
252 type(InvalidType), 252 type(InvalidType),
253 format(RGBA_8888), 253 format(RGBA_8888),
254 shared_bitmap(NULL) { 254 shared_bitmap(NULL) {
255 } 255 }
256 256
257 ResourceProvider::Resource::~Resource() {} 257 ResourceProvider::Resource::~Resource() {}
258 258
259 ResourceProvider::Resource::Resource(GLuint texture_id, 259 ResourceProvider::Resource::Resource(GLuint texture_id,
260 const gfx::Size& size, 260 const gfx::Size& size,
261 Origin origin, 261 Origin origin,
262 GLenum target, 262 GLenum target,
263 GLenum filter, 263 GLenum filter,
264 GLenum texture_pool, 264 GLenum texture_pool,
265 GLint wrap_mode, 265 GLint wrap_mode,
266 TextureUsageHint hint, 266 TextureHint hint,
267 ResourceFormat format) 267 ResourceFormat format)
268 : child_id(0), 268 : child_id(0),
269 gl_id(texture_id), 269 gl_id(texture_id),
270 gl_pixel_buffer_id(0), 270 gl_pixel_buffer_id(0),
271 gl_upload_query_id(0), 271 gl_upload_query_id(0),
272 gl_read_lock_query_id(0), 272 gl_read_lock_query_id(0),
273 pixels(NULL), 273 pixels(NULL),
274 lock_for_read_count(0), 274 lock_for_read_count(0),
275 imported_count(0), 275 imported_count(0),
276 exported_count(0), 276 exported_count(0),
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 read_lock_fence(NULL), 330 read_lock_fence(NULL),
331 size(size), 331 size(size),
332 origin(origin), 332 origin(origin),
333 target(0), 333 target(0),
334 original_filter(filter), 334 original_filter(filter),
335 filter(filter), 335 filter(filter),
336 image_id(0), 336 image_id(0),
337 bound_image_id(0), 337 bound_image_id(0),
338 texture_pool(0), 338 texture_pool(0),
339 wrap_mode(wrap_mode), 339 wrap_mode(wrap_mode),
340 hint(TextureUsageAny), 340 hint(TextureHintImmutable),
341 type(Bitmap), 341 type(Bitmap),
342 format(RGBA_8888), 342 format(RGBA_8888),
343 shared_bitmap(bitmap) { 343 shared_bitmap(bitmap) {
344 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); 344 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT);
345 DCHECK(origin == Delegated || pixels); 345 DCHECK(origin == Delegated || pixels);
346 if (bitmap) 346 if (bitmap)
347 shared_bitmap_id = bitmap->id(); 347 shared_bitmap_id = bitmap->id();
348 } 348 }
349 349
350 ResourceProvider::Resource::Resource(const SharedBitmapId& bitmap_id, 350 ResourceProvider::Resource::Resource(const SharedBitmapId& bitmap_id,
(...skipping 23 matching lines...) Expand all
374 read_lock_fence(NULL), 374 read_lock_fence(NULL),
375 size(size), 375 size(size),
376 origin(origin), 376 origin(origin),
377 target(0), 377 target(0),
378 original_filter(filter), 378 original_filter(filter),
379 filter(filter), 379 filter(filter),
380 image_id(0), 380 image_id(0),
381 bound_image_id(0), 381 bound_image_id(0),
382 texture_pool(0), 382 texture_pool(0),
383 wrap_mode(wrap_mode), 383 wrap_mode(wrap_mode),
384 hint(TextureUsageAny), 384 hint(TextureHintImmutable),
385 type(Bitmap), 385 type(Bitmap),
386 format(RGBA_8888), 386 format(RGBA_8888),
387 shared_bitmap_id(bitmap_id), 387 shared_bitmap_id(bitmap_id),
388 shared_bitmap(NULL) { 388 shared_bitmap(NULL) {
389 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); 389 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT);
390 } 390 }
391 391
392 ResourceProvider::RasterBuffer::RasterBuffer( 392 ResourceProvider::RasterBuffer::RasterBuffer(
393 const Resource* resource, 393 const Resource* resource,
394 ResourceProvider* resource_provider) 394 ResourceProvider* resource_provider)
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 } 622 }
623 623
624 bool ResourceProvider::AllowOverlay(ResourceId id) { 624 bool ResourceProvider::AllowOverlay(ResourceId id) {
625 Resource* resource = GetResource(id); 625 Resource* resource = GetResource(id);
626 return resource->allow_overlay; 626 return resource->allow_overlay;
627 } 627 }
628 628
629 ResourceProvider::ResourceId ResourceProvider::CreateResource( 629 ResourceProvider::ResourceId ResourceProvider::CreateResource(
630 const gfx::Size& size, 630 const gfx::Size& size,
631 GLint wrap_mode, 631 GLint wrap_mode,
632 TextureUsageHint hint, 632 TextureHint hint,
633 ResourceFormat format) { 633 ResourceFormat format) {
634 DCHECK(!size.IsEmpty()); 634 DCHECK(!size.IsEmpty());
635 switch (default_resource_type_) { 635 switch (default_resource_type_) {
636 case GLTexture: 636 case GLTexture:
637 return CreateGLTexture(size, 637 return CreateGLTexture(size,
638 GL_TEXTURE_2D, 638 GL_TEXTURE_2D,
639 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, 639 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM,
640 wrap_mode, 640 wrap_mode,
641 hint, 641 hint,
642 format); 642 format);
643 case Bitmap: 643 case Bitmap:
644 DCHECK_EQ(RGBA_8888, format); 644 DCHECK_EQ(RGBA_8888, format);
645 return CreateBitmap(size, wrap_mode); 645 return CreateBitmap(size, wrap_mode);
646 case InvalidType: 646 case InvalidType:
647 break; 647 break;
648 } 648 }
649 649
650 LOG(FATAL) << "Invalid default resource type."; 650 LOG(FATAL) << "Invalid default resource type.";
651 return 0; 651 return 0;
652 } 652 }
653 653
654 ResourceProvider::ResourceId ResourceProvider::CreateManagedResource( 654 ResourceProvider::ResourceId ResourceProvider::CreateManagedResource(
655 const gfx::Size& size, 655 const gfx::Size& size,
656 GLenum target, 656 GLenum target,
657 GLint wrap_mode, 657 GLint wrap_mode,
658 TextureUsageHint hint, 658 TextureHint hint,
659 ResourceFormat format) { 659 ResourceFormat format) {
660 DCHECK(!size.IsEmpty()); 660 DCHECK(!size.IsEmpty());
661 switch (default_resource_type_) { 661 switch (default_resource_type_) {
662 case GLTexture: 662 case GLTexture:
663 return CreateGLTexture(size, 663 return CreateGLTexture(size,
664 target, 664 target,
665 GL_TEXTURE_POOL_MANAGED_CHROMIUM, 665 GL_TEXTURE_POOL_MANAGED_CHROMIUM,
666 wrap_mode, 666 wrap_mode,
667 hint, 667 hint,
668 format); 668 format);
669 case Bitmap: 669 case Bitmap:
670 DCHECK_EQ(RGBA_8888, format); 670 DCHECK_EQ(RGBA_8888, format);
671 return CreateBitmap(size, wrap_mode); 671 return CreateBitmap(size, wrap_mode);
672 case InvalidType: 672 case InvalidType:
673 break; 673 break;
674 } 674 }
675 675
676 LOG(FATAL) << "Invalid default resource type."; 676 LOG(FATAL) << "Invalid default resource type.";
677 return 0; 677 return 0;
678 } 678 }
679 679
680 ResourceProvider::ResourceId ResourceProvider::CreateGLTexture( 680 ResourceProvider::ResourceId ResourceProvider::CreateGLTexture(
681 const gfx::Size& size, 681 const gfx::Size& size,
682 GLenum target, 682 GLenum target,
683 GLenum texture_pool, 683 GLenum texture_pool,
684 GLint wrap_mode, 684 GLint wrap_mode,
685 TextureUsageHint hint, 685 TextureHint hint,
686 ResourceFormat format) { 686 ResourceFormat format) {
687 DCHECK_LE(size.width(), max_texture_size_); 687 DCHECK_LE(size.width(), max_texture_size_);
688 DCHECK_LE(size.height(), max_texture_size_); 688 DCHECK_LE(size.height(), max_texture_size_);
689 DCHECK(thread_checker_.CalledOnValidThread()); 689 DCHECK(thread_checker_.CalledOnValidThread());
690 690
691 ResourceId id = next_id_++; 691 ResourceId id = next_id_++;
692 Resource resource(0, 692 Resource resource(0,
693 size, 693 size,
694 Resource::Internal, 694 Resource::Internal,
695 target, 695 target,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 DCHECK(thread_checker_.CalledOnValidThread()); 734 DCHECK(thread_checker_.CalledOnValidThread());
735 735
736 ResourceId id = next_id_++; 736 ResourceId id = next_id_++;
737 Resource resource(0, 737 Resource resource(0,
738 gfx::Size(), 738 gfx::Size(),
739 Resource::Internal, 739 Resource::Internal,
740 GL_TEXTURE_RECTANGLE_ARB, 740 GL_TEXTURE_RECTANGLE_ARB,
741 GL_LINEAR, 741 GL_LINEAR,
742 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, 742 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM,
743 GL_CLAMP_TO_EDGE, 743 GL_CLAMP_TO_EDGE,
744 TextureUsageAny, 744 TextureHintImmutable,
745 RGBA_8888); 745 RGBA_8888);
746 LazyCreate(&resource); 746 LazyCreate(&resource);
747 GLES2Interface* gl = ContextGL(); 747 GLES2Interface* gl = ContextGL();
748 DCHECK(gl); 748 DCHECK(gl);
749 gl->BindTexture(GL_TEXTURE_RECTANGLE_ARB, resource.gl_id); 749 gl->BindTexture(GL_TEXTURE_RECTANGLE_ARB, resource.gl_id);
750 gl->TexImageIOSurface2DCHROMIUM( 750 gl->TexImageIOSurface2DCHROMIUM(
751 GL_TEXTURE_RECTANGLE_ARB, size.width(), size.height(), io_surface_id, 0); 751 GL_TEXTURE_RECTANGLE_ARB, size.width(), size.height(), io_surface_id, 0);
752 resource.allocated = true; 752 resource.allocated = true;
753 resources_[id] = resource; 753 resources_[id] = resource;
754 return id; 754 return id;
755 } 755 }
756 756
757 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( 757 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox(
758 const TextureMailbox& mailbox, 758 const TextureMailbox& mailbox,
759 scoped_ptr<SingleReleaseCallback> release_callback) { 759 scoped_ptr<SingleReleaseCallback> release_callback) {
760 DCHECK(thread_checker_.CalledOnValidThread()); 760 DCHECK(thread_checker_.CalledOnValidThread());
761 // Just store the information. Mailbox will be consumed in LockForRead(). 761 // Just store the information. Mailbox will be consumed in LockForRead().
762 ResourceId id = next_id_++; 762 ResourceId id = next_id_++;
763 DCHECK(mailbox.IsValid()); 763 DCHECK(mailbox.IsValid());
764 Resource& resource = resources_[id]; 764 Resource& resource = resources_[id];
765 if (mailbox.IsTexture()) { 765 if (mailbox.IsTexture()) {
766 resource = Resource(0, 766 resource = Resource(0,
767 gfx::Size(), 767 gfx::Size(),
768 Resource::External, 768 Resource::External,
769 mailbox.target(), 769 mailbox.target(),
770 GL_LINEAR, 770 GL_LINEAR,
771 0, 771 0,
772 GL_CLAMP_TO_EDGE, 772 GL_CLAMP_TO_EDGE,
773 TextureUsageAny, 773 TextureHintImmutable,
774 RGBA_8888); 774 RGBA_8888);
775 } else { 775 } else {
776 DCHECK(mailbox.IsSharedMemory()); 776 DCHECK(mailbox.IsSharedMemory());
777 base::SharedMemory* shared_memory = mailbox.shared_memory(); 777 base::SharedMemory* shared_memory = mailbox.shared_memory();
778 DCHECK(shared_memory->memory()); 778 DCHECK(shared_memory->memory());
779 uint8_t* pixels = reinterpret_cast<uint8_t*>(shared_memory->memory()); 779 uint8_t* pixels = reinterpret_cast<uint8_t*>(shared_memory->memory());
780 DCHECK(pixels); 780 DCHECK(pixels);
781 scoped_ptr<SharedBitmap> shared_bitmap; 781 scoped_ptr<SharedBitmap> shared_bitmap;
782 if (shared_bitmap_manager_) { 782 if (shared_bitmap_manager_) {
783 shared_bitmap = 783 shared_bitmap =
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
1411 GL_LINEAR, 1411 GL_LINEAR,
1412 it->is_repeated ? GL_REPEAT : GL_CLAMP_TO_EDGE); 1412 it->is_repeated ? GL_REPEAT : GL_CLAMP_TO_EDGE);
1413 } else { 1413 } else {
1414 resource = Resource(0, 1414 resource = Resource(0,
1415 it->size, 1415 it->size,
1416 Resource::Delegated, 1416 Resource::Delegated,
1417 it->mailbox_holder.texture_target, 1417 it->mailbox_holder.texture_target,
1418 it->filter, 1418 it->filter,
1419 0, 1419 0,
1420 it->is_repeated ? GL_REPEAT : GL_CLAMP_TO_EDGE, 1420 it->is_repeated ? GL_REPEAT : GL_CLAMP_TO_EDGE,
1421 TextureUsageAny, 1421 TextureHintImmutable,
1422 it->format); 1422 it->format);
1423 resource.mailbox = TextureMailbox(it->mailbox_holder.mailbox, 1423 resource.mailbox = TextureMailbox(it->mailbox_holder.mailbox,
1424 it->mailbox_holder.texture_target, 1424 it->mailbox_holder.texture_target,
1425 it->mailbox_holder.sync_point); 1425 it->mailbox_holder.sync_point);
1426 } 1426 }
1427 resource.child_id = child; 1427 resource.child_id = child;
1428 // Don't allocate a texture for a child. 1428 // Don't allocate a texture for a child.
1429 resource.allocated = true; 1429 resource.allocated = true;
1430 resource.imported_count = 1; 1430 resource.imported_count = 1;
1431 resource.allow_overlay = it->allow_overlay; 1431 resource.allow_overlay = it->allow_overlay;
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
2041 resource->target, GL_TEXTURE_MAG_FILTER, resource->original_filter)); 2041 resource->target, GL_TEXTURE_MAG_FILTER, resource->original_filter));
2042 GLC(gl, 2042 GLC(gl,
2043 gl->TexParameteri( 2043 gl->TexParameteri(
2044 resource->target, GL_TEXTURE_WRAP_S, resource->wrap_mode)); 2044 resource->target, GL_TEXTURE_WRAP_S, resource->wrap_mode));
2045 GLC(gl, 2045 GLC(gl,
2046 gl->TexParameteri( 2046 gl->TexParameteri(
2047 resource->target, GL_TEXTURE_WRAP_T, resource->wrap_mode)); 2047 resource->target, GL_TEXTURE_WRAP_T, resource->wrap_mode));
2048 GLC(gl, 2048 GLC(gl,
2049 gl->TexParameteri( 2049 gl->TexParameteri(
2050 resource->target, GL_TEXTURE_POOL_CHROMIUM, resource->texture_pool)); 2050 resource->target, GL_TEXTURE_POOL_CHROMIUM, resource->texture_pool));
2051 if (use_texture_usage_hint_ && resource->hint == TextureUsageFramebuffer) { 2051 if (use_texture_usage_hint_ && (resource->hint & TextureHintFramebuffer)) {
2052 GLC(gl, 2052 GLC(gl,
2053 gl->TexParameteri(resource->target, 2053 gl->TexParameteri(resource->target,
2054 GL_TEXTURE_USAGE_ANGLE, 2054 GL_TEXTURE_USAGE_ANGLE,
2055 GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); 2055 GL_FRAMEBUFFER_ATTACHMENT_ANGLE));
2056 } 2056 }
2057 } 2057 }
2058 2058
2059 void ResourceProvider::AllocateForTesting(ResourceId id) { 2059 void ResourceProvider::AllocateForTesting(ResourceId id) {
2060 LazyAllocate(GetResource(id)); 2060 LazyAllocate(GetResource(id));
2061 } 2061 }
2062 2062
2063 void ResourceProvider::LazyAllocate(Resource* resource) { 2063 void ResourceProvider::LazyAllocate(Resource* resource) {
2064 DCHECK(resource); 2064 DCHECK(resource);
2065 LazyCreate(resource); 2065 LazyCreate(resource);
2066 2066
2067 DCHECK(resource->gl_id || resource->allocated); 2067 DCHECK(resource->gl_id || resource->allocated);
2068 if (resource->allocated || !resource->gl_id) 2068 if (resource->allocated || !resource->gl_id)
2069 return; 2069 return;
2070 resource->allocated = true; 2070 resource->allocated = true;
2071 GLES2Interface* gl = ContextGL(); 2071 GLES2Interface* gl = ContextGL();
2072 gfx::Size& size = resource->size; 2072 gfx::Size& size = resource->size;
2073 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); 2073 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D));
2074 ResourceFormat format = resource->format; 2074 ResourceFormat format = resource->format;
2075 GLC(gl, gl->BindTexture(GL_TEXTURE_2D, resource->gl_id)); 2075 GLC(gl, gl->BindTexture(GL_TEXTURE_2D, resource->gl_id));
2076 if (use_texture_storage_ext_ && IsFormatSupportedForStorage(format) && 2076 if (use_texture_storage_ext_ && IsFormatSupportedForStorage(format) &&
2077 resource->hint != TextureUsageFramebuffer) { 2077 (resource->hint & TextureHintImmutable)) {
2078 GLenum storage_format = TextureToStorageFormat(format); 2078 GLenum storage_format = TextureToStorageFormat(format);
2079 GLC(gl, 2079 GLC(gl,
2080 gl->TexStorage2DEXT( 2080 gl->TexStorage2DEXT(
2081 GL_TEXTURE_2D, 1, storage_format, size.width(), size.height())); 2081 GL_TEXTURE_2D, 1, storage_format, size.width(), size.height()));
2082 } else { 2082 } else {
2083 // ETC1 does not support preallocation. 2083 // ETC1 does not support preallocation.
2084 if (format != ETC1) { 2084 if (format != ETC1) {
2085 GLC(gl, 2085 GLC(gl,
2086 gl->TexImage2D(GL_TEXTURE_2D, 2086 gl->TexImage2D(GL_TEXTURE_2D,
2087 0, 2087 0,
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
2264 ContextProvider* context_provider = output_surface_->context_provider(); 2264 ContextProvider* context_provider = output_surface_->context_provider();
2265 return context_provider ? context_provider->ContextGL() : NULL; 2265 return context_provider ? context_provider->ContextGL() : NULL;
2266 } 2266 }
2267 2267
2268 class GrContext* ResourceProvider::GrContext() const { 2268 class GrContext* ResourceProvider::GrContext() const {
2269 ContextProvider* context_provider = output_surface_->context_provider(); 2269 ContextProvider* context_provider = output_surface_->context_provider();
2270 return context_provider ? context_provider->GrContext() : NULL; 2270 return context_provider ? context_provider->GrContext() : NULL;
2271 } 2271 }
2272 2272
2273 } // namespace cc 2273 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698