diff options
author | ccameron <ccameron@chromium.org> | 2015-11-03 12:14:31 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-03 20:15:50 +0000 |
commit | c7fcd13e9907d4a663d5bc47c1c9ff1701f0b068 (patch) | |
tree | a755ad06f5dd88ab2daeefc17d6cd71daf97e0c2 | |
parent | 1ae3c3a3b26dc42489c0209bbf8ab12738094857 (diff) | |
download | chromium_src-c7fcd13e9907d4a663d5bc47c1c9ff1701f0b068.zip chromium_src-c7fcd13e9907d4a663d5bc47c1c9ff1701f0b068.tar.gz chromium_src-c7fcd13e9907d4a663d5bc47c1c9ff1701f0b068.tar.bz2 |
cc: Add flag to specify to ResourceProvider to always use GMBs
Add a command line switch (similar to zero-copy) to specify that all
resources allocated by the cc::ResourceProvider should use GMBs and
have GLImages attached to them.
BUG=533677
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel
Review URL: https://codereview.chromium.org/1425533006
Cr-Commit-Position: refs/heads/master@{#357604}
-rw-r--r-- | cc/output/renderer_settings.cc | 3 | ||||
-rw-r--r-- | cc/output/renderer_settings.h | 1 | ||||
-rw-r--r-- | cc/resources/resource_provider.cc | 105 | ||||
-rw-r--r-- | cc/resources/resource_provider.h | 9 | ||||
-rw-r--r-- | cc/resources/resource_provider_unittest.cc | 49 | ||||
-rw-r--r-- | cc/surfaces/display.cc | 1 | ||||
-rw-r--r-- | cc/test/fake_resource_provider.h | 6 | ||||
-rw-r--r-- | cc/test/pixel_test.cc | 2 | ||||
-rw-r--r-- | cc/trees/layer_tree_host_impl.cc | 1 | ||||
-rw-r--r-- | content/browser/gpu/compositor_util.cc | 7 | ||||
-rw-r--r-- | content/browser/gpu/compositor_util.h | 3 | ||||
-rw-r--r-- | content/browser/renderer_host/render_process_host_impl.cc | 5 | ||||
-rw-r--r-- | content/public/common/content_switches.cc | 4 | ||||
-rw-r--r-- | content/public/common/content_switches.h | 1 | ||||
-rw-r--r-- | content/renderer/gpu/compositor_dependencies.h | 1 | ||||
-rw-r--r-- | content/renderer/gpu/render_widget_compositor.cc | 2 | ||||
-rw-r--r-- | content/renderer/render_thread_impl.cc | 6 | ||||
-rw-r--r-- | content/renderer/render_thread_impl.h | 2 | ||||
-rw-r--r-- | content/test/fake_compositor_dependencies.cc | 4 | ||||
-rw-r--r-- | content/test/fake_compositor_dependencies.h | 1 |
20 files changed, 142 insertions, 71 deletions
diff --git a/cc/output/renderer_settings.cc b/cc/output/renderer_settings.cc index db961c9..dce7e24 100644 --- a/cc/output/renderer_settings.cc +++ b/cc/output/renderer_settings.cc @@ -21,7 +21,8 @@ RendererSettings::RendererSettings() refresh_rate(60.0), highp_threshold_min(0), use_rgba_4444_textures(false), - texture_id_allocation_chunk_size(64) {} + texture_id_allocation_chunk_size(64), + use_gpu_memory_buffer_resources(false) {} RendererSettings::~RendererSettings() { } diff --git a/cc/output/renderer_settings.h b/cc/output/renderer_settings.h index ce0a470..8022800 100644 --- a/cc/output/renderer_settings.h +++ b/cc/output/renderer_settings.h @@ -26,6 +26,7 @@ class CC_EXPORT RendererSettings { int highp_threshold_min; bool use_rgba_4444_textures; size_t texture_id_allocation_chunk_size; + bool use_gpu_memory_buffer_resources; }; } // namespace cc diff --git a/cc/resources/resource_provider.cc b/cc/resources/resource_provider.cc index 807cbc7..9ea7b6d 100644 --- a/cc/resources/resource_provider.cc +++ b/cc/resources/resource_provider.cc @@ -323,11 +323,13 @@ scoped_ptr<ResourceProvider> ResourceProvider::Create( BlockingTaskRunner* blocking_main_thread_task_runner, int highp_threshold_min, size_t id_allocation_chunk_size, + bool use_gpu_memory_buffer_resources, const std::vector<unsigned>& use_image_texture_targets) { scoped_ptr<ResourceProvider> resource_provider(new ResourceProvider( output_surface, shared_bitmap_manager, gpu_memory_buffer_manager, blocking_main_thread_task_runner, highp_threshold_min, - id_allocation_chunk_size, use_image_texture_targets)); + id_allocation_chunk_size, use_gpu_memory_buffer_resources, + use_image_texture_targets)); resource_provider->Initialize(); return resource_provider; } @@ -385,10 +387,10 @@ ResourceId ResourceProvider::CreateResource(const gfx::Size& size, DCHECK(!size.IsEmpty()); switch (default_resource_type_) { case RESOURCE_TYPE_GL_TEXTURE: - return CreateGLTexture(size, - GL_TEXTURE_2D, - hint, - format); + return CreateGLTexture(size, use_gpu_memory_buffer_resources_ + ? GetImageTextureTarget(format) + : GL_TEXTURE_2D, + hint, format); case RESOURCE_TYPE_BITMAP: DCHECK_EQ(RGBA_8888, format); return CreateBitmap(size); @@ -815,6 +817,8 @@ ResourceProvider::ScopedWriteLockGL::ScopedWriteLockGL( resource_provider_->LazyAllocate(resource_); texture_id_ = resource_->gl_id; DCHECK(texture_id_); + if (resource_->dirty_image) + resource_provider_->BindImageForSampling(resource_); } ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() { @@ -859,13 +863,10 @@ ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: ScopedWriteLockGpuMemoryBuffer(ResourceProvider* resource_provider, ResourceId resource_id) : resource_provider_(resource_provider), - resource_(resource_provider->LockForWrite(resource_id)), - gpu_memory_buffer_manager_(resource_provider->gpu_memory_buffer_manager_), - gpu_memory_buffer_(nullptr), - size_(resource_->size), - format_(resource_->format) { + resource_(resource_provider->LockForWrite(resource_id)) { DCHECK_EQ(RESOURCE_TYPE_GL_TEXTURE, resource_->type); - std::swap(gpu_memory_buffer_, resource_->gpu_memory_buffer); + gpu_memory_buffer_.reset(resource_->gpu_memory_buffer); + resource_->gpu_memory_buffer = nullptr; } ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: @@ -875,27 +876,13 @@ ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: if (!gpu_memory_buffer_) return; + DCHECK(!resource_->gpu_memory_buffer); resource_provider_->LazyCreate(resource_); - - if (!resource_->image_id) { - GLES2Interface* gl = resource_provider_->ContextGL(); - DCHECK(gl); - -#if defined(OS_CHROMEOS) - // TODO(reveman): GL_COMMANDS_ISSUED_CHROMIUM is used for synchronization - // on ChromeOS to avoid some performance issues. This only works with - // shared memory backed buffers. crbug.com/436314 - DCHECK_EQ(gpu_memory_buffer_->GetHandle().type, gfx::SHARED_MEMORY_BUFFER); -#endif - - resource_->image_id = gl->CreateImageCHROMIUM( - gpu_memory_buffer_->AsClientBuffer(), size_.width(), size_.height(), - GLInternalFormat(resource_->format)); - } - - std::swap(resource_->gpu_memory_buffer, gpu_memory_buffer_); + resource_->gpu_memory_buffer = gpu_memory_buffer_.release(); resource_->allocated = true; + resource_provider_->LazyCreateImage(resource_); resource_->dirty_image = true; + resource_->is_overlay_candidate = true; // GpuMemoryBuffer provides direct access to the memory used by the GPU. // Read lock fences are required to ensure that we're not trying to map a @@ -905,14 +892,13 @@ ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: gfx::GpuMemoryBuffer* ResourceProvider::ScopedWriteLockGpuMemoryBuffer::GetGpuMemoryBuffer() { - if (gpu_memory_buffer_) - return gpu_memory_buffer_; - scoped_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer = - gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( - size_, BufferFormat(format_), - gfx::BufferUsage::GPU_READ_CPU_READ_WRITE); - gpu_memory_buffer_ = gpu_memory_buffer.release(); - return gpu_memory_buffer_; + if (!gpu_memory_buffer_) { + gpu_memory_buffer_ = + resource_provider_->gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( + resource_->size, BufferFormat(resource_->format), + gfx::BufferUsage::GPU_READ_CPU_READ_WRITE); + } + return gpu_memory_buffer_.get(); } ResourceProvider::ScopedWriteLockGr::ScopedWriteLockGr( @@ -1001,6 +987,7 @@ ResourceProvider::ResourceProvider( BlockingTaskRunner* blocking_main_thread_task_runner, int highp_threshold_min, size_t id_allocation_chunk_size, + bool use_gpu_memory_buffer_resources, const std::vector<unsigned>& use_image_texture_targets) : output_surface_(output_surface), shared_bitmap_manager_(shared_bitmap_manager), @@ -1011,6 +998,7 @@ ResourceProvider::ResourceProvider( next_id_(1), next_child_(1), default_resource_type_(RESOURCE_TYPE_BITMAP), + use_gpu_memory_buffer_resources_(use_gpu_memory_buffer_resources), use_texture_storage_ext_(false), use_texture_format_bgra_(false), use_texture_usage_hint_(false), @@ -1308,11 +1296,8 @@ void ResourceProvider::TransferResource(GLES2Interface* gl, LazyCreate(source); DCHECK(source->gl_id); DCHECK(source->origin == Resource::INTERNAL); - if (source->image_id) { - DCHECK(source->dirty_image); - gl->BindTexture(resource->mailbox_holder.texture_target, source->gl_id); + if (source->image_id && source->dirty_image) BindImageForSampling(source); - } // This is a resource allocated by the compositor, we need to produce it. // Don't set a sync point, the caller will do it. gl->GenMailboxCHROMIUM(resource->mailbox_holder.mailbox.name); @@ -1326,7 +1311,6 @@ void ResourceProvider::TransferResource(GLES2Interface* gl, if (source->image_id && source->dirty_image) { DCHECK(source->gl_id); DCHECK(source->origin == Resource::INTERNAL); - gl->BindTexture(resource->mailbox_holder.texture_target, source->gl_id); BindImageForSampling(source); } // This is either an external resource, or a compositor resource that we @@ -1514,9 +1498,18 @@ void ResourceProvider::LazyAllocate(Resource* resource) { gfx::Size& size = resource->size; ResourceFormat format = resource->format; gl->BindTexture(resource->target, resource->gl_id); - if (use_texture_storage_ext_ && - IsFormatSupportedForStorage(format, use_texture_format_bgra_) && - (resource->hint & TEXTURE_HINT_IMMUTABLE)) { + if (use_gpu_memory_buffer_resources_) { + resource->gpu_memory_buffer = + gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( + size, BufferFormat(format), + gfx::BufferUsage::SCANOUT) + .release(); + LazyCreateImage(resource); + resource->dirty_image = true; + resource->is_overlay_candidate = true; + } else if (use_texture_storage_ext_ && + IsFormatSupportedForStorage(format, use_texture_format_bgra_) && + (resource->hint & TEXTURE_HINT_IMMUTABLE)) { GLenum storage_format = TextureToStorageFormat(format); gl->TexStorage2DEXT(resource->target, 1, storage_format, size.width(), size.height()); @@ -1530,12 +1523,34 @@ void ResourceProvider::LazyAllocate(Resource* resource) { } } +void ResourceProvider::LazyCreateImage(Resource* resource) { + DCHECK(resource->gpu_memory_buffer); + DCHECK(resource->gl_id); + DCHECK(resource->allocated); + if (!resource->image_id) { + GLES2Interface* gl = ContextGL(); + DCHECK(gl); + +#if defined(OS_CHROMEOS) + // TODO(reveman): GL_COMMANDS_ISSUED_CHROMIUM is used for synchronization + // on ChromeOS to avoid some performance issues. This only works with + // shared memory backed buffers. crbug.com/436314 + DCHECK_EQ(resource->gpu_memory_buffer->GetHandle().type, + gfx::SHARED_MEMORY_BUFFER); +#endif + resource->image_id = gl->CreateImageCHROMIUM( + resource->gpu_memory_buffer->AsClientBuffer(), resource->size.width(), + resource->size.height(), GLInternalFormat(resource->format)); + } +} + void ResourceProvider::BindImageForSampling(Resource* resource) { GLES2Interface* gl = ContextGL(); DCHECK(resource->gl_id); DCHECK(resource->image_id); // Release image currently bound to texture. + gl->BindTexture(resource->target, resource->gl_id); if (resource->bound_image_id) gl->ReleaseTexImage2DCHROMIUM(resource->target, resource->bound_image_id); gl->BindTexImage2DCHROMIUM(resource->target, resource->image_id); diff --git a/cc/resources/resource_provider.h b/cc/resources/resource_provider.h index ae813f0..39240a1 100644 --- a/cc/resources/resource_provider.h +++ b/cc/resources/resource_provider.h @@ -87,6 +87,7 @@ class CC_EXPORT ResourceProvider BlockingTaskRunner* blocking_main_thread_task_runner, int highp_threshold_min, size_t id_allocation_chunk_size, + bool use_gpu_memory_buffer_resources, const std::vector<unsigned>& use_image_texture_targets); ~ResourceProvider() override; @@ -309,10 +310,7 @@ class CC_EXPORT ResourceProvider private: ResourceProvider* resource_provider_; ResourceProvider::Resource* resource_; - gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager_; - gfx::GpuMemoryBuffer* gpu_memory_buffer_; - gfx::Size size_; - ResourceFormat format_; + scoped_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer_; base::ThreadChecker thread_checker_; DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGpuMemoryBuffer); @@ -435,6 +433,7 @@ class CC_EXPORT ResourceProvider BlockingTaskRunner* blocking_main_thread_task_runner, int highp_threshold_min, size_t id_allocation_chunk_size, + bool use_gpu_memory_buffer_resources, const std::vector<unsigned>& use_image_texture_targets); void Initialize(); @@ -546,6 +545,7 @@ class CC_EXPORT ResourceProvider void DestroyChildInternal(ChildMap::iterator it, DeleteStyle style); void LazyCreate(Resource* resource); void LazyAllocate(Resource* resource); + void LazyCreateImage(Resource* resource); void BindImageForSampling(Resource* resource); // Binds the given GL resource to a texture target for sampling using the @@ -569,6 +569,7 @@ class CC_EXPORT ResourceProvider ChildMap children_; ResourceType default_resource_type_; + bool use_gpu_memory_buffer_resources_; bool use_texture_storage_ext_; bool use_texture_format_bgra_; bool use_texture_usage_hint_; diff --git a/cc/resources/resource_provider_unittest.cc b/cc/resources/resource_provider_unittest.cc index 26b6df4..2c567f7 100644 --- a/cc/resources/resource_provider_unittest.cc +++ b/cc/resources/resource_provider_unittest.cc @@ -436,11 +436,11 @@ class ResourceProviderTest resource_provider_ = ResourceProvider::Create( output_surface_.get(), shared_bitmap_manager_.get(), gpu_memory_buffer_manager_.get(), main_thread_task_runner_.get(), 0, 1, - use_image_texture_targets_); + use_gpu_memory_buffer_resources_, use_image_texture_targets_); child_resource_provider_ = ResourceProvider::Create( child_output_surface_.get(), shared_bitmap_manager_.get(), gpu_memory_buffer_manager_.get(), main_thread_task_runner_.get(), 0, 1, - use_image_texture_targets_); + use_gpu_memory_buffer_resources_, use_image_texture_targets_); } ResourceProviderTest() : ResourceProviderTest(true) {} @@ -501,11 +501,15 @@ class ResourceProviderTest } public: + static bool use_gpu_memory_buffer_resources() { + return use_gpu_memory_buffer_resources_; + } static std::vector<unsigned> use_image_texture_targets() { return use_image_texture_targets_; } protected: + static bool use_gpu_memory_buffer_resources_; static std::vector<unsigned> use_image_texture_targets_; scoped_ptr<ContextSharedData> shared_data_; ResourceProviderContext* context3d_; @@ -521,6 +525,8 @@ class ResourceProviderTest scoped_ptr<TestGpuMemoryBufferManager> gpu_memory_buffer_manager_; }; +bool ResourceProviderTest::use_gpu_memory_buffer_resources_ = false; + std::vector<unsigned> ResourceProviderTest::use_image_texture_targets_ = std::vector<unsigned>(static_cast<size_t>(gfx::BufferFormat::LAST) + 1, GL_TEXTURE_2D); @@ -1393,7 +1399,7 @@ TEST_P(ResourceProviderTest, TransferGLToSoftware) { scoped_ptr<ResourceProvider> child_resource_provider(ResourceProvider::Create( child_output_surface.get(), shared_bitmap_manager_.get(), gpu_memory_buffer_manager_.get(), NULL, 0, 1, - use_image_texture_targets_)); + use_gpu_memory_buffer_resources_, use_image_texture_targets_)); gfx::Size size(1, 1); ResourceFormat format = RGBA_8888; @@ -1877,6 +1883,7 @@ class ResourceProviderTestTextureFilters : public ResourceProviderTest { scoped_ptr<ResourceProvider> child_resource_provider( ResourceProvider::Create(child_output_surface.get(), shared_bitmap_manager.get(), NULL, NULL, 0, 1, + use_gpu_memory_buffer_resources_, use_image_texture_targets_)); scoped_ptr<TextureStateTrackingContext> parent_context_owned( @@ -1891,6 +1898,7 @@ class ResourceProviderTestTextureFilters : public ResourceProviderTest { scoped_ptr<ResourceProvider> parent_resource_provider( ResourceProvider::Create(parent_output_surface.get(), shared_bitmap_manager.get(), NULL, NULL, 0, 1, + use_gpu_memory_buffer_resources_, use_image_texture_targets_)); gfx::Size size(1, 1); @@ -2522,7 +2530,7 @@ TEST_P(ResourceProviderTest, ScopedSampler) { scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( output_surface.get(), shared_bitmap_manager_.get(), gpu_memory_buffer_manager_.get(), NULL, 0, 1, - use_image_texture_targets_)); + use_gpu_memory_buffer_resources_, use_image_texture_targets_)); gfx::Size size(1, 1); ResourceFormat format = RGBA_8888; @@ -2601,7 +2609,7 @@ TEST_P(ResourceProviderTest, ManagedResource) { scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( output_surface.get(), shared_bitmap_manager_.get(), gpu_memory_buffer_manager_.get(), NULL, 0, 1, - use_image_texture_targets_)); + use_gpu_memory_buffer_resources_, use_image_texture_targets_)); gfx::Size size(1, 1); ResourceFormat format = RGBA_8888; @@ -2644,7 +2652,7 @@ TEST_P(ResourceProviderTest, TextureWrapMode) { scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( output_surface.get(), shared_bitmap_manager_.get(), gpu_memory_buffer_manager_.get(), NULL, 0, 1, - use_image_texture_targets_)); + use_gpu_memory_buffer_resources_, use_image_texture_targets_)); gfx::Size size(1, 1); ResourceFormat format = RGBA_8888; @@ -2688,7 +2696,7 @@ TEST_P(ResourceProviderTest, TextureHint) { scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( output_surface.get(), shared_bitmap_manager_.get(), gpu_memory_buffer_manager_.get(), NULL, 0, 1, - use_image_texture_targets_)); + use_gpu_memory_buffer_resources_, use_image_texture_targets_)); gfx::Size size(1, 1); ResourceFormat format = RGBA_8888; @@ -2747,7 +2755,7 @@ TEST_P(ResourceProviderTest, TextureMailbox_SharedMemory) { scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( output_surface.get(), shared_bitmap_manager_.get(), gpu_memory_buffer_manager_.get(), main_thread_task_runner_.get(), 0, 1, - use_image_texture_targets_)); + use_gpu_memory_buffer_resources_, use_image_texture_targets_)); gpu::SyncToken release_sync_token; bool lost_resource = false; @@ -2795,7 +2803,8 @@ class ResourceProviderTestTextureMailboxGLFilters scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( output_surface.get(), shared_bitmap_manager, gpu_memory_buffer_manager, - main_thread_task_runner, 0, 1, use_image_texture_targets_)); + main_thread_task_runner, 0, 1, use_gpu_memory_buffer_resources_, + use_image_texture_targets_)); unsigned texture_id = 1; gpu::SyncToken sync_token(30); @@ -2938,7 +2947,7 @@ TEST_P(ResourceProviderTest, TextureMailbox_GLTextureExternalOES) { scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( output_surface.get(), shared_bitmap_manager_.get(), gpu_memory_buffer_manager_.get(), NULL, 0, 1, - use_image_texture_targets_)); + use_gpu_memory_buffer_resources_, use_image_texture_targets_)); gpu::SyncToken sync_token(30); unsigned target = GL_TEXTURE_EXTERNAL_OES; @@ -3008,7 +3017,7 @@ TEST_P(ResourceProviderTest, scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( output_surface.get(), shared_bitmap_manager_.get(), gpu_memory_buffer_manager_.get(), NULL, 0, 1, - use_image_texture_targets_)); + use_gpu_memory_buffer_resources_, use_image_texture_targets_)); gpu::SyncToken sync_token(30); unsigned target = GL_TEXTURE_2D; @@ -3062,7 +3071,7 @@ TEST_P(ResourceProviderTest, TextureMailbox_WaitSyncTokenIfNeeded_NoSyncToken) { scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( output_surface.get(), shared_bitmap_manager_.get(), gpu_memory_buffer_manager_.get(), NULL, 0, 1, - use_image_texture_targets_)); + use_gpu_memory_buffer_resources_, use_image_texture_targets_)); gpu::SyncToken sync_token; unsigned target = GL_TEXTURE_2D; @@ -3183,7 +3192,7 @@ TEST_P(ResourceProviderTest, TextureAllocation) { scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( output_surface.get(), shared_bitmap_manager_.get(), gpu_memory_buffer_manager_.get(), NULL, 0, 1, - use_image_texture_targets_)); + use_gpu_memory_buffer_resources_, use_image_texture_targets_)); gfx::Size size(2, 2); gfx::Vector2d offset(0, 0); @@ -3239,7 +3248,7 @@ TEST_P(ResourceProviderTest, TextureAllocationHint) { scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( output_surface.get(), shared_bitmap_manager_.get(), gpu_memory_buffer_manager_.get(), NULL, 0, 1, - use_image_texture_targets_)); + use_gpu_memory_buffer_resources_, use_image_texture_targets_)); gfx::Size size(2, 2); @@ -3295,7 +3304,7 @@ TEST_P(ResourceProviderTest, TextureAllocationHint_BGRA) { scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( output_surface.get(), shared_bitmap_manager_.get(), gpu_memory_buffer_manager_.get(), NULL, 0, 1, - use_image_texture_targets_)); + use_gpu_memory_buffer_resources_, use_image_texture_targets_)); gfx::Size size(2, 2); const ResourceFormat formats[2] = {RGBA_8888, BGRA_8888}; @@ -3354,7 +3363,7 @@ TEST_P(ResourceProviderTest, Image_GLTexture) { scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( output_surface.get(), shared_bitmap_manager_.get(), gpu_memory_buffer_manager_.get(), NULL, 0, 1, - use_image_texture_targets_)); + use_gpu_memory_buffer_resources_, use_image_texture_targets_)); id = resource_provider->CreateResource( size, ResourceProvider::TEXTURE_HINT_IMMUTABLE, format); @@ -3363,7 +3372,7 @@ TEST_P(ResourceProviderTest, Image_GLTexture) { .WillOnce(Return(kTextureId)) .RetiresOnSaturation(); EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)) - .Times(1) + .Times(3) .RetiresOnSaturation(); EXPECT_CALL(*context, createImageCHROMIUM(_, kWidth, kHeight, GL_RGBA)) .WillOnce(Return(kImageId)) @@ -3432,7 +3441,7 @@ TEST_P(ResourceProviderTest, CompressedTextureETC1Allocate) { scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( output_surface.get(), shared_bitmap_manager_.get(), gpu_memory_buffer_manager_.get(), NULL, 0, 1, - use_image_texture_targets_)); + use_gpu_memory_buffer_resources_, use_image_texture_targets_)); int texture_id = 123; ResourceId id = resource_provider->CreateResource( @@ -3464,7 +3473,7 @@ TEST_P(ResourceProviderTest, CompressedTextureETC1Upload) { scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( output_surface.get(), shared_bitmap_manager_.get(), gpu_memory_buffer_manager_.get(), NULL, 0, 1, - use_image_texture_targets_)); + use_gpu_memory_buffer_resources_, use_image_texture_targets_)); int texture_id = 123; uint8_t pixels[8]; @@ -3521,6 +3530,7 @@ TEST(ResourceProviderTest, TextureAllocationChunkSize) { scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( output_surface.get(), shared_bitmap_manager.get(), NULL, NULL, 0, kTextureAllocationChunkSize, + ResourceProviderTest::use_gpu_memory_buffer_resources(), ResourceProviderTest::use_image_texture_targets())); ResourceId id = resource_provider->CreateResource( @@ -3537,6 +3547,7 @@ TEST(ResourceProviderTest, TextureAllocationChunkSize) { scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( output_surface.get(), shared_bitmap_manager.get(), NULL, NULL, 0, kTextureAllocationChunkSize, + ResourceProviderTest::use_gpu_memory_buffer_resources(), ResourceProviderTest::use_image_texture_targets())); ResourceId id = resource_provider->CreateResource( diff --git a/cc/surfaces/display.cc b/cc/surfaces/display.cc index 7cd9d6d..31335ae 100644 --- a/cc/surfaces/display.cc +++ b/cc/surfaces/display.cc @@ -106,6 +106,7 @@ void Display::InitializeRenderer() { output_surface_.get(), bitmap_manager_, gpu_memory_buffer_manager_, nullptr, settings_.highp_threshold_min, settings_.texture_id_allocation_chunk_size, + settings_.use_gpu_memory_buffer_resources, std::vector<unsigned>(static_cast<size_t>(gfx::BufferFormat::LAST) + 1, GL_TEXTURE_2D)); if (!resource_provider) diff --git a/cc/test/fake_resource_provider.h b/cc/test/fake_resource_provider.h index 7b54072..4ad254f 100644 --- a/cc/test/fake_resource_provider.h +++ b/cc/test/fake_resource_provider.h @@ -16,7 +16,7 @@ class FakeResourceProvider : public ResourceProvider { OutputSurface* output_surface, SharedBitmapManager* shared_bitmap_manager) { scoped_ptr<FakeResourceProvider> provider(new FakeResourceProvider( - output_surface, shared_bitmap_manager, nullptr, nullptr, 0, 1, + output_surface, shared_bitmap_manager, nullptr, nullptr, 0, 1, false, std::vector<unsigned>(static_cast<size_t>(gfx::BufferFormat::LAST) + 1, GL_TEXTURE_2D))); provider->Initialize(); @@ -29,7 +29,7 @@ class FakeResourceProvider : public ResourceProvider { gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) { scoped_ptr<FakeResourceProvider> provider(new FakeResourceProvider( output_surface, shared_bitmap_manager, gpu_memory_buffer_manager, - nullptr, 0, 1, + nullptr, 0, 1, false, std::vector<unsigned>(static_cast<size_t>(gfx::BufferFormat::LAST) + 1, GL_TEXTURE_2D))); provider->Initialize(); @@ -43,6 +43,7 @@ class FakeResourceProvider : public ResourceProvider { BlockingTaskRunner* blocking_main_thread_task_runner, int highp_threshold_min, size_t id_allocation_chunk_size, + bool use_gpu_memory_buffer_resources, const std::vector<unsigned>& use_image_texture_targets) : ResourceProvider(output_surface, shared_bitmap_manager, @@ -50,6 +51,7 @@ class FakeResourceProvider : public ResourceProvider { blocking_main_thread_task_runner, highp_threshold_min, id_allocation_chunk_size, + use_gpu_memory_buffer_resources, use_image_texture_targets) {} }; diff --git a/cc/test/pixel_test.cc b/cc/test/pixel_test.cc index 75e4ea1..36a113f 100644 --- a/cc/test/pixel_test.cc +++ b/cc/test/pixel_test.cc @@ -136,6 +136,7 @@ void PixelTest::SetUpGLRenderer(bool use_skia_gpu_backend, resource_provider_ = ResourceProvider::Create( output_surface_.get(), shared_bitmap_manager_.get(), gpu_memory_buffer_manager_.get(), main_thread_task_runner_.get(), 0, 1, + settings_.renderer_settings.use_gpu_memory_buffer_resources, settings_.use_image_texture_targets); texture_mailbox_deleter_ = make_scoped_ptr( @@ -177,6 +178,7 @@ void PixelTest::SetUpSoftwareRenderer() { resource_provider_ = ResourceProvider::Create( output_surface_.get(), shared_bitmap_manager_.get(), gpu_memory_buffer_manager_.get(), main_thread_task_runner_.get(), 0, 1, + settings_.renderer_settings.use_gpu_memory_buffer_resources, settings_.use_image_texture_targets); renderer_ = SoftwareRenderer::Create(this, &settings_.renderer_settings, diff --git a/cc/trees/layer_tree_host_impl.cc b/cc/trees/layer_tree_host_impl.cc index 0590b35..bb63c28 100644 --- a/cc/trees/layer_tree_host_impl.cc +++ b/cc/trees/layer_tree_host_impl.cc @@ -2273,6 +2273,7 @@ bool LayerTreeHostImpl::InitializeRenderer(OutputSurface* output_surface) { task_runner_provider_->blocking_main_thread_task_runner(), settings_.renderer_settings.highp_threshold_min, settings_.renderer_settings.texture_id_allocation_chunk_size, + settings_.renderer_settings.use_gpu_memory_buffer_resources, settings_.use_image_texture_targets); CreateAndSetRenderer(); diff --git a/content/browser/gpu/compositor_util.cc b/content/browser/gpu/compositor_util.cc index c6aabfb..1b77f8b 100644 --- a/content/browser/gpu/compositor_util.cc +++ b/content/browser/gpu/compositor_util.cc @@ -216,6 +216,13 @@ bool IsPartialRasterEnabled() { return command_line.HasSwitch(switches::kEnablePartialRaster); } +bool IsGpuMemoryBufferCompositorResourcesEnabled() { + const base::CommandLine& command_line = + *base::CommandLine::ForCurrentProcess(); + return command_line.HasSwitch( + switches::kEnableGpuMemoryBufferCompositorResources); +} + bool IsGpuRasterizationEnabled() { const base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); diff --git a/content/browser/gpu/compositor_util.h b/content/browser/gpu/compositor_util.h index 82cd778..1dc495a 100644 --- a/content/browser/gpu/compositor_util.h +++ b/content/browser/gpu/compositor_util.h @@ -24,6 +24,9 @@ CONTENT_EXPORT bool IsZeroCopyUploadEnabled(); // Returns true if a partial raster is on (via flags). CONTENT_EXPORT bool IsPartialRasterEnabled(); +// Returns true if all compositor resources should use GPU memory buffers. +CONTENT_EXPORT bool IsGpuMemoryBufferCompositorResourcesEnabled(); + // Returns true if gpu rasterization is on (via flags) for the renderer. CONTENT_EXPORT bool IsGpuRasterizationEnabled(); diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index 5fdffef..892da51 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -1198,6 +1198,11 @@ static void AppendCompositorCommandLineFlags(base::CommandLine* command_line) { if (IsForceGpuRasterizationEnabled()) command_line->AppendSwitch(switches::kForceGpuRasterization); + if (IsGpuMemoryBufferCompositorResourcesEnabled()) { + command_line->AppendSwitch( + switches::kEnableGpuMemoryBufferCompositorResources); + } + // Persistent buffers may come at a performance hit (not all platform specific // buffers support it), so only enable them if partial raster is enabled and // we are actually going to use them. diff --git a/content/public/common/content_switches.cc b/content/public/common/content_switches.cc index 74ac83c..7c557ae 100644 --- a/content/public/common/content_switches.cc +++ b/content/public/common/content_switches.cc @@ -343,6 +343,10 @@ const char kEnableWebBluetooth[] = "enable-web-bluetooth"; // Enables TRACE for GL calls in the renderer. const char kEnableGpuClientTracing[] = "enable-gpu-client-tracing"; +// Specify that all compositor resources should be backed by GPU memory buffers. +const char kEnableGpuMemoryBufferCompositorResources[] = + "enable-gpu-memory-buffer-compositor-resources"; + // Enable GpuMemoryBuffer backed VideoFrames. const char kEnableGpuMemoryBufferVideoFrames[] = "enable-gpu-memory-buffer-video-frames"; diff --git a/content/public/common/content_switches.h b/content/public/common/content_switches.h index 66b4cc5..1f4d784 100644 --- a/content/public/common/content_switches.h +++ b/content/public/common/content_switches.h @@ -107,6 +107,7 @@ CONTENT_EXPORT extern const char kEnableExperimentalWebPlatformFeatures[]; CONTENT_EXPORT extern const char kEnableFeatures[]; CONTENT_EXPORT extern const char kEnableWebBluetooth[]; extern const char kEnableGpuClientTracing[]; +CONTENT_EXPORT extern const char kEnableGpuMemoryBufferCompositorResources[]; CONTENT_EXPORT extern const char kEnableGpuMemoryBufferVideoFrames[]; CONTENT_EXPORT extern const char kEnableGpuRasterization[]; CONTENT_EXPORT extern const char kGpuRasterizationMSAASampleCount[]; diff --git a/content/renderer/gpu/compositor_dependencies.h b/content/renderer/gpu/compositor_dependencies.h index 6647fa1..fd46a11 100644 --- a/content/renderer/gpu/compositor_dependencies.h +++ b/content/renderer/gpu/compositor_dependencies.h @@ -40,6 +40,7 @@ class CompositorDependencies { virtual bool IsDistanceFieldTextEnabled() = 0; virtual bool IsZeroCopyEnabled() = 0; virtual bool IsPartialRasterEnabled() = 0; + virtual bool IsGpuMemoryBufferCompositorResourcesEnabled() = 0; virtual bool IsElasticOverscrollEnabled() = 0; virtual std::vector<unsigned> GetImageTextureTargets() = 0; virtual scoped_refptr<base::SingleThreadTaskRunner> diff --git a/content/renderer/gpu/render_widget_compositor.cc b/content/renderer/gpu/render_widget_compositor.cc index e5f6e5d..f7ac509 100644 --- a/content/renderer/gpu/render_widget_compositor.cc +++ b/content/renderer/gpu/render_widget_compositor.cc @@ -300,6 +300,8 @@ void RenderWidgetCompositor::Initialize() { settings.use_partial_raster = compositor_deps_->IsPartialRasterEnabled(); settings.enable_elastic_overscroll = compositor_deps_->IsElasticOverscrollEnabled(); + settings.renderer_settings.use_gpu_memory_buffer_resources = + compositor_deps_->IsGpuMemoryBufferCompositorResourcesEnabled(); settings.use_image_texture_targets = compositor_deps_->GetImageTextureTargets(); settings.image_decode_tasks_enabled = diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc index 92b5bb0..a2a2508 100644 --- a/content/renderer/render_thread_impl.cc +++ b/content/renderer/render_thread_impl.cc @@ -705,6 +705,8 @@ void RenderThreadImpl::Init() { is_zero_copy_enabled_ = command_line.HasSwitch(switches::kEnableZeroCopy); is_partial_raster_enabled_ = command_line.HasSwitch(switches::kEnablePartialRaster); + is_gpu_memory_buffer_compositor_resources_enabled_ = command_line.HasSwitch( + switches::kEnableGpuMemoryBufferCompositorResources); #if defined(OS_MACOSX) && !defined(OS_IOS) is_elastic_overscroll_enabled_ = base::mac::IsOSLionOrLater(); @@ -1503,6 +1505,10 @@ bool RenderThreadImpl::IsPartialRasterEnabled() { return is_partial_raster_enabled_; } +bool RenderThreadImpl::IsGpuMemoryBufferCompositorResourcesEnabled() { + return is_gpu_memory_buffer_compositor_resources_enabled_; +} + bool RenderThreadImpl::IsElasticOverscrollEnabled() { return is_elastic_overscroll_enabled_; } diff --git a/content/renderer/render_thread_impl.h b/content/renderer/render_thread_impl.h index 236da9f..f7eef23 100644 --- a/content/renderer/render_thread_impl.h +++ b/content/renderer/render_thread_impl.h @@ -194,6 +194,7 @@ class CONTENT_EXPORT RenderThreadImpl bool IsDistanceFieldTextEnabled() override; bool IsZeroCopyEnabled() override; bool IsPartialRasterEnabled() override; + bool IsGpuMemoryBufferCompositorResourcesEnabled() override; bool IsElasticOverscrollEnabled() override; std::vector<unsigned> GetImageTextureTargets() override; scoped_refptr<base::SingleThreadTaskRunner> @@ -634,6 +635,7 @@ class CONTENT_EXPORT RenderThreadImpl bool is_distance_field_text_enabled_; bool is_zero_copy_enabled_; bool is_one_copy_enabled_; + bool is_gpu_memory_buffer_compositor_resources_enabled_; bool is_partial_raster_enabled_; bool is_elastic_overscroll_enabled_; std::vector<unsigned> use_image_texture_targets_; diff --git a/content/test/fake_compositor_dependencies.cc b/content/test/fake_compositor_dependencies.cc index 3cd5043..63a24d2 100644 --- a/content/test/fake_compositor_dependencies.cc +++ b/content/test/fake_compositor_dependencies.cc @@ -46,6 +46,10 @@ bool FakeCompositorDependencies::IsPartialRasterEnabled() { return false; } +bool FakeCompositorDependencies::IsGpuMemoryBufferCompositorResourcesEnabled() { + return false; +} + bool FakeCompositorDependencies::IsElasticOverscrollEnabled() { return false; } diff --git a/content/test/fake_compositor_dependencies.h b/content/test/fake_compositor_dependencies.h index 09e517c..8b9cf12 100644 --- a/content/test/fake_compositor_dependencies.h +++ b/content/test/fake_compositor_dependencies.h @@ -26,6 +26,7 @@ class FakeCompositorDependencies : public CompositorDependencies { bool IsDistanceFieldTextEnabled() override; bool IsZeroCopyEnabled() override; bool IsPartialRasterEnabled() override; + bool IsGpuMemoryBufferCompositorResourcesEnabled() override; bool IsElasticOverscrollEnabled() override; std::vector<unsigned> GetImageTextureTargets() override; scoped_refptr<base::SingleThreadTaskRunner> |