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

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: 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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 read_lock_fence(NULL), 250 read_lock_fence(NULL),
251 size(), 251 size(),
252 origin(Internal), 252 origin(Internal),
253 target(0), 253 target(0),
254 original_filter(0), 254 original_filter(0),
255 filter(0), 255 filter(0),
256 image_id(0), 256 image_id(0),
257 bound_image_id(0), 257 bound_image_id(0),
258 texture_pool(0), 258 texture_pool(0),
259 wrap_mode(0), 259 wrap_mode(0),
260 hint(TextureUsageAny), 260 hint(TextureHintImmutable),
261 type(InvalidType), 261 type(InvalidType),
262 format(RGBA_8888), 262 format(RGBA_8888),
263 shared_bitmap(NULL) { 263 shared_bitmap(NULL) {
264 } 264 }
265 265
266 ResourceProvider::Resource::~Resource() {} 266 ResourceProvider::Resource::~Resource() {}
267 267
268 ResourceProvider::Resource::Resource(GLuint texture_id, 268 ResourceProvider::Resource::Resource(GLuint texture_id,
269 const gfx::Size& size, 269 const gfx::Size& size,
270 Origin origin, 270 Origin origin,
271 GLenum target, 271 GLenum target,
272 GLenum filter, 272 GLenum filter,
273 GLenum texture_pool, 273 GLenum texture_pool,
274 GLint wrap_mode, 274 GLint wrap_mode,
275 TextureUsageHint hint, 275 TextureHint hint,
276 ResourceFormat format) 276 ResourceFormat format)
277 : child_id(0), 277 : child_id(0),
278 gl_id(texture_id), 278 gl_id(texture_id),
279 gl_pixel_buffer_id(0), 279 gl_pixel_buffer_id(0),
280 gl_upload_query_id(0), 280 gl_upload_query_id(0),
281 gl_read_lock_query_id(0), 281 gl_read_lock_query_id(0),
282 pixels(NULL), 282 pixels(NULL),
283 lock_for_read_count(0), 283 lock_for_read_count(0),
284 imported_count(0), 284 imported_count(0),
285 exported_count(0), 285 exported_count(0),
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 read_lock_fence(NULL), 339 read_lock_fence(NULL),
340 size(size), 340 size(size),
341 origin(origin), 341 origin(origin),
342 target(0), 342 target(0),
343 original_filter(filter), 343 original_filter(filter),
344 filter(filter), 344 filter(filter),
345 image_id(0), 345 image_id(0),
346 bound_image_id(0), 346 bound_image_id(0),
347 texture_pool(0), 347 texture_pool(0),
348 wrap_mode(wrap_mode), 348 wrap_mode(wrap_mode),
349 hint(TextureUsageAny), 349 hint(TextureHintImmutable),
350 type(Bitmap), 350 type(Bitmap),
351 format(RGBA_8888), 351 format(RGBA_8888),
352 shared_bitmap(bitmap) { 352 shared_bitmap(bitmap) {
353 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); 353 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT);
354 DCHECK(origin == Delegated || pixels); 354 DCHECK(origin == Delegated || pixels);
355 if (bitmap) 355 if (bitmap)
356 shared_bitmap_id = bitmap->id(); 356 shared_bitmap_id = bitmap->id();
357 } 357 }
358 358
359 ResourceProvider::Resource::Resource(const SharedBitmapId& bitmap_id, 359 ResourceProvider::Resource::Resource(const SharedBitmapId& bitmap_id,
(...skipping 23 matching lines...) Expand all
383 read_lock_fence(NULL), 383 read_lock_fence(NULL),
384 size(size), 384 size(size),
385 origin(origin), 385 origin(origin),
386 target(0), 386 target(0),
387 original_filter(filter), 387 original_filter(filter),
388 filter(filter), 388 filter(filter),
389 image_id(0), 389 image_id(0),
390 bound_image_id(0), 390 bound_image_id(0),
391 texture_pool(0), 391 texture_pool(0),
392 wrap_mode(wrap_mode), 392 wrap_mode(wrap_mode),
393 hint(TextureUsageAny), 393 hint(TextureHintImmutable),
394 type(Bitmap), 394 type(Bitmap),
395 format(RGBA_8888), 395 format(RGBA_8888),
396 shared_bitmap_id(bitmap_id), 396 shared_bitmap_id(bitmap_id),
397 shared_bitmap(NULL) { 397 shared_bitmap(NULL) {
398 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); 398 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT);
399 } 399 }
400 400
401 ResourceProvider::RasterBuffer::RasterBuffer( 401 ResourceProvider::RasterBuffer::RasterBuffer(
402 const Resource* resource, 402 const Resource* resource,
403 ResourceProvider* resource_provider) 403 ResourceProvider* resource_provider)
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 } 631 }
632 632
633 bool ResourceProvider::AllowOverlay(ResourceId id) { 633 bool ResourceProvider::AllowOverlay(ResourceId id) {
634 Resource* resource = GetResource(id); 634 Resource* resource = GetResource(id);
635 return resource->allow_overlay; 635 return resource->allow_overlay;
636 } 636 }
637 637
638 ResourceProvider::ResourceId ResourceProvider::CreateResource( 638 ResourceProvider::ResourceId ResourceProvider::CreateResource(
639 const gfx::Size& size, 639 const gfx::Size& size,
640 GLint wrap_mode, 640 GLint wrap_mode,
641 TextureUsageHint hint, 641 TextureHint hint,
642 ResourceFormat format) { 642 ResourceFormat format) {
643 DCHECK(!size.IsEmpty()); 643 DCHECK(!size.IsEmpty());
644 switch (default_resource_type_) { 644 switch (default_resource_type_) {
645 case GLTexture: 645 case GLTexture:
646 return CreateGLTexture(size, 646 return CreateGLTexture(size,
647 GL_TEXTURE_2D, 647 GL_TEXTURE_2D,
648 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, 648 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM,
649 wrap_mode, 649 wrap_mode,
650 hint, 650 hint,
651 format); 651 format);
652 case Bitmap: 652 case Bitmap:
653 DCHECK_EQ(RGBA_8888, format); 653 DCHECK_EQ(RGBA_8888, format);
654 return CreateBitmap(size, wrap_mode); 654 return CreateBitmap(size, wrap_mode);
655 case InvalidType: 655 case InvalidType:
656 break; 656 break;
657 } 657 }
658 658
659 LOG(FATAL) << "Invalid default resource type."; 659 LOG(FATAL) << "Invalid default resource type.";
660 return 0; 660 return 0;
661 } 661 }
662 662
663 ResourceProvider::ResourceId ResourceProvider::CreateManagedResource( 663 ResourceProvider::ResourceId ResourceProvider::CreateManagedResource(
664 const gfx::Size& size, 664 const gfx::Size& size,
665 GLenum target, 665 GLenum target,
666 GLint wrap_mode, 666 GLint wrap_mode,
667 TextureUsageHint hint, 667 TextureHint hint,
668 ResourceFormat format) { 668 ResourceFormat format) {
669 DCHECK(!size.IsEmpty()); 669 DCHECK(!size.IsEmpty());
670 switch (default_resource_type_) { 670 switch (default_resource_type_) {
671 case GLTexture: 671 case GLTexture:
672 return CreateGLTexture(size, 672 return CreateGLTexture(size,
673 target, 673 target,
674 GL_TEXTURE_POOL_MANAGED_CHROMIUM, 674 GL_TEXTURE_POOL_MANAGED_CHROMIUM,
675 wrap_mode, 675 wrap_mode,
676 hint, 676 hint,
677 format); 677 format);
678 case Bitmap: 678 case Bitmap:
679 DCHECK_EQ(RGBA_8888, format); 679 DCHECK_EQ(RGBA_8888, format);
680 return CreateBitmap(size, wrap_mode); 680 return CreateBitmap(size, wrap_mode);
681 case InvalidType: 681 case InvalidType:
682 break; 682 break;
683 } 683 }
684 684
685 LOG(FATAL) << "Invalid default resource type."; 685 LOG(FATAL) << "Invalid default resource type.";
686 return 0; 686 return 0;
687 } 687 }
688 688
689 ResourceProvider::ResourceId ResourceProvider::CreateGLTexture( 689 ResourceProvider::ResourceId ResourceProvider::CreateGLTexture(
690 const gfx::Size& size, 690 const gfx::Size& size,
691 GLenum target, 691 GLenum target,
692 GLenum texture_pool, 692 GLenum texture_pool,
693 GLint wrap_mode, 693 GLint wrap_mode,
694 TextureUsageHint hint, 694 TextureHint hint,
695 ResourceFormat format) { 695 ResourceFormat format) {
696 DCHECK_LE(size.width(), max_texture_size_); 696 DCHECK_LE(size.width(), max_texture_size_);
697 DCHECK_LE(size.height(), max_texture_size_); 697 DCHECK_LE(size.height(), max_texture_size_);
698 DCHECK(thread_checker_.CalledOnValidThread()); 698 DCHECK(thread_checker_.CalledOnValidThread());
699 699
700 ResourceId id = next_id_++; 700 ResourceId id = next_id_++;
701 Resource resource(0, 701 Resource resource(0,
702 size, 702 size,
703 Resource::Internal, 703 Resource::Internal,
704 target, 704 target,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 DCHECK(thread_checker_.CalledOnValidThread()); 743 DCHECK(thread_checker_.CalledOnValidThread());
744 744
745 ResourceId id = next_id_++; 745 ResourceId id = next_id_++;
746 Resource resource(0, 746 Resource resource(0,
747 gfx::Size(), 747 gfx::Size(),
748 Resource::Internal, 748 Resource::Internal,
749 GL_TEXTURE_RECTANGLE_ARB, 749 GL_TEXTURE_RECTANGLE_ARB,
750 GL_LINEAR, 750 GL_LINEAR,
751 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, 751 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM,
752 GL_CLAMP_TO_EDGE, 752 GL_CLAMP_TO_EDGE,
753 TextureUsageAny, 753 TextureHintImmutable,
754 RGBA_8888); 754 RGBA_8888);
755 LazyCreate(&resource); 755 LazyCreate(&resource);
756 GLES2Interface* gl = ContextGL(); 756 GLES2Interface* gl = ContextGL();
757 DCHECK(gl); 757 DCHECK(gl);
758 gl->BindTexture(GL_TEXTURE_RECTANGLE_ARB, resource.gl_id); 758 gl->BindTexture(GL_TEXTURE_RECTANGLE_ARB, resource.gl_id);
759 gl->TexImageIOSurface2DCHROMIUM( 759 gl->TexImageIOSurface2DCHROMIUM(
760 GL_TEXTURE_RECTANGLE_ARB, size.width(), size.height(), io_surface_id, 0); 760 GL_TEXTURE_RECTANGLE_ARB, size.width(), size.height(), io_surface_id, 0);
761 resource.allocated = true; 761 resource.allocated = true;
762 resources_[id] = resource; 762 resources_[id] = resource;
763 return id; 763 return id;
764 } 764 }
765 765
766 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( 766 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox(
767 const TextureMailbox& mailbox, 767 const TextureMailbox& mailbox,
768 scoped_ptr<SingleReleaseCallback> release_callback) { 768 scoped_ptr<SingleReleaseCallback> release_callback) {
769 DCHECK(thread_checker_.CalledOnValidThread()); 769 DCHECK(thread_checker_.CalledOnValidThread());
770 // Just store the information. Mailbox will be consumed in LockForRead(). 770 // Just store the information. Mailbox will be consumed in LockForRead().
771 ResourceId id = next_id_++; 771 ResourceId id = next_id_++;
772 DCHECK(mailbox.IsValid()); 772 DCHECK(mailbox.IsValid());
773 Resource& resource = resources_[id]; 773 Resource& resource = resources_[id];
774 if (mailbox.IsTexture()) { 774 if (mailbox.IsTexture()) {
775 resource = Resource(0, 775 resource = Resource(0,
776 gfx::Size(), 776 gfx::Size(),
777 Resource::External, 777 Resource::External,
778 mailbox.target(), 778 mailbox.target(),
779 GL_LINEAR, 779 GL_LINEAR,
780 0, 780 0,
781 GL_CLAMP_TO_EDGE, 781 GL_CLAMP_TO_EDGE,
782 TextureUsageAny, 782 TextureHintImmutable,
783 RGBA_8888); 783 RGBA_8888);
784 } else { 784 } else {
785 DCHECK(mailbox.IsSharedMemory()); 785 DCHECK(mailbox.IsSharedMemory());
786 base::SharedMemory* shared_memory = mailbox.shared_memory(); 786 base::SharedMemory* shared_memory = mailbox.shared_memory();
787 DCHECK(shared_memory->memory()); 787 DCHECK(shared_memory->memory());
788 uint8_t* pixels = reinterpret_cast<uint8_t*>(shared_memory->memory()); 788 uint8_t* pixels = reinterpret_cast<uint8_t*>(shared_memory->memory());
789 DCHECK(pixels); 789 DCHECK(pixels);
790 scoped_ptr<SharedBitmap> shared_bitmap; 790 scoped_ptr<SharedBitmap> shared_bitmap;
791 if (shared_bitmap_manager_) { 791 if (shared_bitmap_manager_) {
792 shared_bitmap = 792 shared_bitmap =
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
1420 GL_LINEAR, 1420 GL_LINEAR,
1421 it->is_repeated ? GL_REPEAT : GL_CLAMP_TO_EDGE); 1421 it->is_repeated ? GL_REPEAT : GL_CLAMP_TO_EDGE);
1422 } else { 1422 } else {
1423 resource = Resource(0, 1423 resource = Resource(0,
1424 it->size, 1424 it->size,
1425 Resource::Delegated, 1425 Resource::Delegated,
1426 it->mailbox_holder.texture_target, 1426 it->mailbox_holder.texture_target,
1427 it->filter, 1427 it->filter,
1428 0, 1428 0,
1429 it->is_repeated ? GL_REPEAT : GL_CLAMP_TO_EDGE, 1429 it->is_repeated ? GL_REPEAT : GL_CLAMP_TO_EDGE,
1430 TextureUsageAny, 1430 TextureHintImmutable,
1431 it->format); 1431 it->format);
1432 resource.mailbox = TextureMailbox(it->mailbox_holder.mailbox, 1432 resource.mailbox = TextureMailbox(it->mailbox_holder.mailbox,
1433 it->mailbox_holder.texture_target, 1433 it->mailbox_holder.texture_target,
1434 it->mailbox_holder.sync_point); 1434 it->mailbox_holder.sync_point);
1435 } 1435 }
1436 resource.child_id = child; 1436 resource.child_id = child;
1437 // Don't allocate a texture for a child. 1437 // Don't allocate a texture for a child.
1438 resource.allocated = true; 1438 resource.allocated = true;
1439 resource.imported_count = 1; 1439 resource.imported_count = 1;
1440 resource.allow_overlay = it->allow_overlay; 1440 resource.allow_overlay = it->allow_overlay;
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
2048 gl->TexParameteri(resource->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); 2048 gl->TexParameteri(resource->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
2049 GLC(gl, 2049 GLC(gl,
2050 gl->TexParameteri( 2050 gl->TexParameteri(
2051 resource->target, GL_TEXTURE_WRAP_S, resource->wrap_mode)); 2051 resource->target, GL_TEXTURE_WRAP_S, resource->wrap_mode));
2052 GLC(gl, 2052 GLC(gl,
2053 gl->TexParameteri( 2053 gl->TexParameteri(
2054 resource->target, GL_TEXTURE_WRAP_T, resource->wrap_mode)); 2054 resource->target, GL_TEXTURE_WRAP_T, resource->wrap_mode));
2055 GLC(gl, 2055 GLC(gl,
2056 gl->TexParameteri( 2056 gl->TexParameteri(
2057 resource->target, GL_TEXTURE_POOL_CHROMIUM, resource->texture_pool)); 2057 resource->target, GL_TEXTURE_POOL_CHROMIUM, resource->texture_pool));
2058 if (use_texture_usage_hint_ && resource->hint == TextureUsageFramebuffer) { 2058 if (use_texture_usage_hint_ && resource->hint == TextureHintFramebuffer) {
2059 GLC(gl, 2059 GLC(gl,
2060 gl->TexParameteri(resource->target, 2060 gl->TexParameteri(resource->target,
2061 GL_TEXTURE_USAGE_ANGLE, 2061 GL_TEXTURE_USAGE_ANGLE,
2062 GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); 2062 GL_FRAMEBUFFER_ATTACHMENT_ANGLE));
2063 } 2063 }
2064 } 2064 }
2065 2065
2066 void ResourceProvider::AllocateForTesting(ResourceId id) { 2066 void ResourceProvider::AllocateForTesting(ResourceId id) {
2067 LazyAllocate(GetResource(id)); 2067 LazyAllocate(GetResource(id));
2068 } 2068 }
2069 2069
2070 void ResourceProvider::LazyAllocate(Resource* resource) { 2070 void ResourceProvider::LazyAllocate(Resource* resource) {
2071 DCHECK(resource); 2071 DCHECK(resource);
2072 LazyCreate(resource); 2072 LazyCreate(resource);
2073 2073
2074 DCHECK(resource->gl_id || resource->allocated); 2074 DCHECK(resource->gl_id || resource->allocated);
2075 if (resource->allocated || !resource->gl_id) 2075 if (resource->allocated || !resource->gl_id)
2076 return; 2076 return;
2077 resource->allocated = true; 2077 resource->allocated = true;
2078 GLES2Interface* gl = ContextGL(); 2078 GLES2Interface* gl = ContextGL();
2079 gfx::Size& size = resource->size; 2079 gfx::Size& size = resource->size;
2080 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); 2080 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D));
2081 ResourceFormat format = resource->format; 2081 ResourceFormat format = resource->format;
2082 GLC(gl, gl->BindTexture(GL_TEXTURE_2D, resource->gl_id)); 2082 GLC(gl, gl->BindTexture(GL_TEXTURE_2D, resource->gl_id));
2083 if (use_texture_storage_ext_ && IsFormatSupportedForStorage(format) && 2083 if (use_texture_storage_ext_ && IsFormatSupportedForStorage(format) &&
2084 resource->hint != TextureUsageFramebuffer) { 2084 resource->hint == TextureHintImmutable) {
2085 GLenum storage_format = TextureToStorageFormat(format); 2085 GLenum storage_format = TextureToStorageFormat(format);
2086 GLC(gl, 2086 GLC(gl,
2087 gl->TexStorage2DEXT( 2087 gl->TexStorage2DEXT(
2088 GL_TEXTURE_2D, 1, storage_format, size.width(), size.height())); 2088 GL_TEXTURE_2D, 1, storage_format, size.width(), size.height()));
2089 } else { 2089 } else {
2090 // ETC1 does not support preallocation. 2090 // ETC1 does not support preallocation.
2091 if (format != ETC1) { 2091 if (format != ETC1) {
2092 GLC(gl, 2092 GLC(gl,
2093 gl->TexImage2D(GL_TEXTURE_2D, 2093 gl->TexImage2D(GL_TEXTURE_2D,
2094 0, 2094 0,
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
2271 ContextProvider* context_provider = output_surface_->context_provider(); 2271 ContextProvider* context_provider = output_surface_->context_provider();
2272 return context_provider ? context_provider->ContextGL() : NULL; 2272 return context_provider ? context_provider->ContextGL() : NULL;
2273 } 2273 }
2274 2274
2275 class GrContext* ResourceProvider::GrContext() const { 2275 class GrContext* ResourceProvider::GrContext() const {
2276 ContextProvider* context_provider = output_surface_->context_provider(); 2276 ContextProvider* context_provider = output_surface_->context_provider();
2277 return context_provider ? context_provider->GrContext() : NULL; 2277 return context_provider ? context_provider->GrContext() : NULL;
2278 } 2278 }
2279 2279
2280 } // namespace cc 2280 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698