Chromium Code Reviews| Index: cc/resources/resource_provider.cc |
| diff --git a/cc/resources/resource_provider.cc b/cc/resources/resource_provider.cc |
| index cf79940c44f36c87384c99fc9730c20d19e9411c..c60e1cf04a86d07390f23b2f61df1133deb65abc 100644 |
| --- a/cc/resources/resource_provider.cc |
| +++ b/cc/resources/resource_provider.cc |
| @@ -134,7 +134,7 @@ class ScopedSetActiveTexture { |
| public: |
| ScopedSetActiveTexture(GLES2Interface* gl, GLenum unit) |
| : gl_(gl), unit_(unit) { |
| - DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(gl_)); |
| + DCHECK_EQ(GL_TEXTURE0, ResourceHelper::GetActiveTextureUnit(gl_)); |
| if (unit_ != GL_TEXTURE0) |
| GLC(gl_, gl_->ActiveTexture(unit_)); |
| @@ -459,7 +459,8 @@ skia::RefPtr<SkSurface> ResourceProvider::GpuRasterBuffer::CreateSurface() { |
| DCHECK_EQ(GLTexture, resource()->type); |
| DCHECK(resource()->gl_id); |
| - class GrContext* gr_context = resource_provider()->GrContext(); |
| + class GrContext* gr_context = |
| + resource_provider()->GetResourceHelper()->GrContext(); |
| // TODO(alokp): Implement TestContextProvider::GrContext(). |
| if (!gr_context) |
| return skia::RefPtr<SkSurface>(); |
| @@ -596,7 +597,7 @@ scoped_ptr<ResourceProvider> ResourceProvider::Create( |
| id_allocation_chunk_size, |
| use_distance_field_text)); |
| - if (resource_provider->ContextGL()) |
| + if (resource_provider->GetResourceHelper()->ContextGL()) |
| resource_provider->InitializeGL(); |
| else |
| resource_provider->InitializeSoftware(); |
| @@ -748,7 +749,7 @@ ResourceProvider::ResourceId ResourceProvider::CreateResourceFromIOSurface( |
| TextureUsageAny, |
| RGBA_8888); |
| LazyCreate(&resource); |
| - GLES2Interface* gl = ContextGL(); |
| + GLES2Interface* gl = resource_helper_->ContextGL(); |
| DCHECK(gl); |
| gl->BindTexture(GL_TEXTURE_RECTANGLE_ARB, resource.gl_id); |
| gl->TexImageIOSurface2DCHROMIUM( |
| @@ -836,25 +837,25 @@ void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it, |
| if (resource->image_id) { |
| DCHECK(resource->origin == Resource::Internal); |
| - GLES2Interface* gl = ContextGL(); |
| + GLES2Interface* gl = resource_helper_->ContextGL(); |
| DCHECK(gl); |
| GLC(gl, gl->DestroyImageCHROMIUM(resource->image_id)); |
| } |
| if (resource->gl_upload_query_id) { |
| DCHECK(resource->origin == Resource::Internal); |
| - GLES2Interface* gl = ContextGL(); |
| + GLES2Interface* gl = resource_helper_->ContextGL(); |
| DCHECK(gl); |
| GLC(gl, gl->DeleteQueriesEXT(1, &resource->gl_upload_query_id)); |
| } |
| if (resource->gl_read_lock_query_id) { |
| DCHECK(resource->origin == Resource::Internal); |
| - GLES2Interface* gl = ContextGL(); |
| + GLES2Interface* gl = resource_helper_->ContextGL(); |
| DCHECK(gl); |
| GLC(gl, gl->DeleteQueriesEXT(1, &resource->gl_read_lock_query_id)); |
| } |
| if (resource->gl_pixel_buffer_id) { |
| DCHECK(resource->origin == Resource::Internal); |
| - GLES2Interface* gl = ContextGL(); |
| + GLES2Interface* gl = resource_helper_->ContextGL(); |
| DCHECK(gl); |
| GLC(gl, gl->DeleteBuffers(1, &resource->gl_pixel_buffer_id)); |
| } |
| @@ -864,7 +865,7 @@ void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it, |
| if (resource->type == GLTexture) { |
| DCHECK(resource->mailbox.IsTexture()); |
| lost_resource |= lost_output_surface_; |
| - GLES2Interface* gl = ContextGL(); |
| + GLES2Interface* gl = resource_helper_->ContextGL(); |
| DCHECK(gl); |
| if (resource->gl_id) { |
| GLC(gl, gl->DeleteTextures(1, &resource->gl_id)); |
| @@ -885,7 +886,7 @@ void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it, |
| resource->release_callback.Run(sync_point, lost_resource); |
| } |
| if (resource->gl_id) { |
| - GLES2Interface* gl = ContextGL(); |
| + GLES2Interface* gl = resource_helper_->ContextGL(); |
| DCHECK(gl); |
| GLC(gl, gl->DeleteTextures(1, &resource->gl_id)); |
| resource->gl_id = 0; |
| @@ -925,7 +926,7 @@ void ResourceProvider::SetPixels(ResourceId id, |
| DCHECK(resource->gl_id); |
| DCHECK(!resource->pending_set_pixels); |
| DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); |
| - GLES2Interface* gl = ContextGL(); |
| + GLES2Interface* gl = resource_helper_->ContextGL(); |
| DCHECK(gl); |
| DCHECK(texture_uploader_.get()); |
| gl->BindTexture(GL_TEXTURE_2D, resource->gl_id); |
| @@ -1015,30 +1016,6 @@ base::TimeTicks ResourceProvider::EstimatedUploadCompletionTime( |
| return gfx::FrameTime::Now() + upload_one_texture_time * total_uploads; |
| } |
| -void ResourceProvider::Flush() { |
| - DCHECK(thread_checker_.CalledOnValidThread()); |
| - GLES2Interface* gl = ContextGL(); |
| - if (gl) |
| - gl->Flush(); |
| -} |
| - |
| -void ResourceProvider::Finish() { |
| - DCHECK(thread_checker_.CalledOnValidThread()); |
| - GLES2Interface* gl = ContextGL(); |
| - if (gl) |
| - gl->Finish(); |
| -} |
| - |
| -bool ResourceProvider::ShallowFlushIfSupported() { |
| - DCHECK(thread_checker_.CalledOnValidThread()); |
| - GLES2Interface* gl = ContextGL(); |
| - if (!gl) |
| - return false; |
| - |
| - gl->ShallowFlushCHROMIUM(); |
| - return true; |
| -} |
| - |
| ResourceProvider::Resource* ResourceProvider::GetResource(ResourceId id) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| ResourceMap::iterator it = resources_.find(id); |
| @@ -1061,7 +1038,7 @@ const ResourceProvider::Resource* ResourceProvider::LockForRead(ResourceId id) { |
| if (resource->type == GLTexture && !resource->gl_id) { |
| DCHECK(resource->origin != Resource::Internal); |
| DCHECK(resource->mailbox.IsTexture()); |
| - GLES2Interface* gl = ContextGL(); |
| + GLES2Interface* gl = resource_helper_->ContextGL(); |
| DCHECK(gl); |
| if (resource->mailbox.sync_point()) { |
| GLC(gl, gl->WaitSyncPointCHROMIUM(resource->mailbox.sync_point())); |
| @@ -1229,16 +1206,6 @@ ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() { |
| resource_provider_->UnlockForWrite(resource_id_); |
| } |
| -ResourceProvider::ScopedGpuRaster::ScopedGpuRaster( |
| - ResourceProvider* resource_provider) |
| - : resource_provider_(resource_provider) { |
| - resource_provider_->BeginGpuRaster(); |
| -} |
| - |
| -ResourceProvider::ScopedGpuRaster::~ScopedGpuRaster() { |
| - resource_provider_->EndGpuRaster(); |
| -} |
| - |
| ResourceProvider::ResourceProvider(OutputSurface* output_surface, |
| SharedBitmapManager* shared_bitmap_manager, |
| int highp_threshold_min, |
| @@ -1260,7 +1227,8 @@ ResourceProvider::ResourceProvider(OutputSurface* output_surface, |
| use_rgba_4444_texture_format_(use_rgba_4444_texture_format), |
| id_allocation_chunk_size_(id_allocation_chunk_size), |
| use_sync_query_(false), |
| - use_distance_field_text_(use_distance_field_text) { |
| + use_distance_field_text_(use_distance_field_text), |
| + resource_helper_(new ResourceHelper(output_surface)) { |
| DCHECK(output_surface_->HasClient()); |
| DCHECK(id_allocation_chunk_size_); |
| } |
| @@ -1295,7 +1263,7 @@ void ResourceProvider::InitializeGL() { |
| use_compressed_texture_etc1_ = caps.gpu.texture_format_etc1; |
| use_sync_query_ = caps.gpu.sync_query; |
| - GLES2Interface* gl = ContextGL(); |
| + GLES2Interface* gl = resource_helper_->ContextGL(); |
| DCHECK(gl); |
| texture_uploader_ = TextureUploader::Create(gl); |
| @@ -1310,7 +1278,7 @@ void ResourceProvider::InitializeGL() { |
| } |
| void ResourceProvider::CleanUpGLIfNeeded() { |
| - GLES2Interface* gl = ContextGL(); |
| + GLES2Interface* gl = resource_helper_->ContextGL(); |
| if (default_resource_type_ != GLTexture) { |
| // We are not in GL mode, but double check before returning. |
| DCHECK(!gl); |
| @@ -1331,7 +1299,7 @@ void ResourceProvider::CleanUpGLIfNeeded() { |
| texture_uploader_.reset(); |
| texture_id_allocator_.reset(); |
| buffer_id_allocator_.reset(); |
| - Finish(); |
| + GetResourceHelper()->Finish(); |
|
danakj
2014/07/09 16:01:33
can we just call gl->Finish() directly?
sohanjg
2014/07/10 15:11:06
Done.
|
| } |
| int ResourceProvider::CreateChild(const ReturnCallback& return_callback) { |
| @@ -1386,7 +1354,7 @@ const ResourceProvider::ResourceIdMap& ResourceProvider::GetChildToParentMap( |
| void ResourceProvider::PrepareSendToParent(const ResourceIdArray& resources, |
| TransferableResourceArray* list) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| - GLES2Interface* gl = ContextGL(); |
| + GLES2Interface* gl = resource_helper_->ContextGL(); |
| bool need_sync_point = false; |
| for (ResourceIdArray::const_iterator it = resources.begin(); |
| it != resources.end(); |
| @@ -1412,7 +1380,7 @@ void ResourceProvider::PrepareSendToParent(const ResourceIdArray& resources, |
| void ResourceProvider::ReceiveFromChild( |
| int child, const TransferableResourceArray& resources) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| - GLES2Interface* gl = ContextGL(); |
| + GLES2Interface* gl = resource_helper_->ContextGL(); |
| Child& child_info = children_.find(child)->second; |
| DCHECK(!child_info.marked_for_deletion); |
| for (TransferableResourceArray::const_iterator it = resources.begin(); |
| @@ -1514,7 +1482,7 @@ bool ResourceProvider::CompareResourceMapIteratorsByChildId( |
| void ResourceProvider::ReceiveReturnsFromParent( |
| const ReturnedResourceArray& resources) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| - GLES2Interface* gl = ContextGL(); |
| + GLES2Interface* gl = resource_helper_->ContextGL(); |
| int child_id = 0; |
| ResourceIdArray resources_for_child; |
| @@ -1673,7 +1641,7 @@ void ResourceProvider::DeleteAndReturnUnusedResourcesToChild( |
| ReturnedResourceArray to_return; |
| - GLES2Interface* gl = ContextGL(); |
| + GLES2Interface* gl = resource_helper_->ContextGL(); |
| bool need_sync_point = false; |
| for (size_t i = 0; i < unused.size(); ++i) { |
| ResourceId local_id = unused[i]; |
| @@ -1818,7 +1786,7 @@ void ResourceProvider::AcquirePixelBuffer(Resource* resource) { |
| DCHECK_NE(ETC1, resource->format); |
| DCHECK_EQ(GLTexture, resource->type); |
| - GLES2Interface* gl = ContextGL(); |
| + GLES2Interface* gl = resource_helper_->ContextGL(); |
| DCHECK(gl); |
| if (!resource->gl_pixel_buffer_id) |
| resource->gl_pixel_buffer_id = buffer_id_allocator_->NextId(); |
| @@ -1856,7 +1824,7 @@ void ResourceProvider::ReleasePixelBuffer(Resource* resource) { |
| DCHECK_EQ(GLTexture, resource->type); |
| if (!resource->gl_pixel_buffer_id) |
| return; |
| - GLES2Interface* gl = ContextGL(); |
| + GLES2Interface* gl = resource_helper_->ContextGL(); |
| DCHECK(gl); |
| gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| resource->gl_pixel_buffer_id); |
| @@ -1876,7 +1844,7 @@ uint8_t* ResourceProvider::MapPixelBuffer(const Resource* resource, |
| *stride = 0; |
| DCHECK_EQ(GLTexture, resource->type); |
| - GLES2Interface* gl = ContextGL(); |
| + GLES2Interface* gl = resource_helper_->ContextGL(); |
| DCHECK(gl); |
| DCHECK(resource->gl_pixel_buffer_id); |
| gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| @@ -1898,7 +1866,7 @@ void ResourceProvider::UnmapPixelBuffer(const Resource* resource) { |
| DCHECK(!resource->image_id); |
| DCHECK_EQ(GLTexture, resource->type); |
| - GLES2Interface* gl = ContextGL(); |
| + GLES2Interface* gl = resource_helper_->ContextGL(); |
| DCHECK(gl); |
| DCHECK(resource->gl_pixel_buffer_id); |
| gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| @@ -1912,7 +1880,7 @@ GLenum ResourceProvider::BindForSampling( |
| GLenum unit, |
| GLenum filter) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| - GLES2Interface* gl = ContextGL(); |
| + GLES2Interface* gl = resource_helper_->ContextGL(); |
| ResourceMap::iterator it = resources_.find(resource_id); |
| DCHECK(it != resources_.end()); |
| Resource* resource = &it->second; |
| @@ -1953,7 +1921,7 @@ void ResourceProvider::BeginSetPixels(ResourceId id) { |
| DCHECK_EQ(GLTexture, resource->type); |
| DCHECK(resource->gl_id); |
| - GLES2Interface* gl = ContextGL(); |
| + GLES2Interface* gl = resource_helper_->ContextGL(); |
| DCHECK(gl); |
| DCHECK(resource->gl_pixel_buffer_id); |
| DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); |
| @@ -2002,7 +1970,7 @@ void ResourceProvider::ForceSetPixelsToComplete(ResourceId id) { |
| DCHECK(!resource->set_pixels_completion_forced); |
| if (resource->gl_id) { |
| - GLES2Interface* gl = ContextGL(); |
| + GLES2Interface* gl = resource_helper_->ContextGL(); |
| GLC(gl, gl->BindTexture(GL_TEXTURE_2D, resource->gl_id)); |
| GLC(gl, gl->WaitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)); |
| GLC(gl, gl->BindTexture(GL_TEXTURE_2D, 0)); |
| @@ -2020,7 +1988,7 @@ bool ResourceProvider::DidSetPixelsComplete(ResourceId id) { |
| DCHECK(resource->pending_set_pixels); |
| if (resource->gl_id) { |
| - GLES2Interface* gl = ContextGL(); |
| + GLES2Interface* gl = resource_helper_->ContextGL(); |
| DCHECK(gl); |
| DCHECK(resource->gl_upload_query_id); |
| GLuint complete = 1; |
| @@ -2057,7 +2025,7 @@ void ResourceProvider::LazyCreate(Resource* resource) { |
| DCHECK(!resource->mailbox.IsValid()); |
| resource->gl_id = texture_id_allocator_->NextId(); |
| - GLES2Interface* gl = ContextGL(); |
| + GLES2Interface* gl = resource_helper_->ContextGL(); |
| DCHECK(gl); |
| // Create and set texture properties. Allocation is delayed until needed. |
| @@ -2095,7 +2063,7 @@ void ResourceProvider::LazyAllocate(Resource* resource) { |
| if (resource->allocated || !resource->gl_id) |
| return; |
| resource->allocated = true; |
| - GLES2Interface* gl = ContextGL(); |
| + GLES2Interface* gl = resource_helper_->ContextGL(); |
| gfx::Size& size = resource->size; |
| DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); |
| ResourceFormat format = resource->format; |
| @@ -2124,7 +2092,7 @@ void ResourceProvider::LazyAllocate(Resource* resource) { |
| } |
| void ResourceProvider::BindImageForSampling(Resource* resource) { |
| - GLES2Interface* gl = ContextGL(); |
| + GLES2Interface* gl = resource_helper_->ContextGL(); |
| DCHECK(resource->gl_id); |
| DCHECK(resource->image_id); |
| @@ -2153,7 +2121,7 @@ void ResourceProvider::AcquireImage(Resource* resource) { |
| return; |
| resource->allocated = true; |
| - GLES2Interface* gl = ContextGL(); |
| + GLES2Interface* gl = resource_helper_->ContextGL(); |
| DCHECK(gl); |
| resource->image_id = |
| gl->CreateImageCHROMIUM(resource->size.width(), |
| @@ -2170,7 +2138,7 @@ void ResourceProvider::ReleaseImage(Resource* resource) { |
| if (!resource->image_id) |
| return; |
| - GLES2Interface* gl = ContextGL(); |
| + GLES2Interface* gl = resource_helper_->ContextGL(); |
| DCHECK(gl); |
| gl->DestroyImageCHROMIUM(resource->image_id); |
| resource->image_id = 0; |
| @@ -2186,7 +2154,7 @@ uint8_t* ResourceProvider::MapImage(const Resource* resource, int* stride) { |
| if (resource->type == GLTexture) { |
| DCHECK(resource->image_id); |
| - GLES2Interface* gl = ContextGL(); |
| + GLES2Interface* gl = resource_helper_->ContextGL(); |
| DCHECK(gl); |
| // MapImageCHROMIUM should be called prior to GetImageParameterivCHROMIUM. |
| uint8_t* pixels = |
| @@ -2205,7 +2173,7 @@ void ResourceProvider::UnmapImage(const Resource* resource) { |
| DCHECK_EQ(resource->exported_count, 0); |
| if (resource->image_id) { |
| - GLES2Interface* gl = ContextGL(); |
| + GLES2Interface* gl = resource_helper_->ContextGL(); |
| DCHECK(gl); |
| gl->UnmapImageCHROMIUM(resource->image_id); |
| } |
| @@ -2233,7 +2201,7 @@ void ResourceProvider::CopyResource(ResourceId source_id, ResourceId dest_id) { |
| DCHECK(source_resource->size == dest_resource->size); |
| if (source_resource->type == GLTexture) { |
| - GLES2Interface* gl = ContextGL(); |
| + GLES2Interface* gl = resource_helper_->ContextGL(); |
| DCHECK(gl); |
| if (source_resource->image_id && source_resource->dirty_image) { |
| gl->BindTexture(source_resource->target, source_resource->gl_id); |
| @@ -2267,48 +2235,4 @@ void ResourceProvider::CopyResource(ResourceId source_id, ResourceId dest_id) { |
| } |
| } |
| -GLint ResourceProvider::GetActiveTextureUnit(GLES2Interface* gl) { |
| - GLint active_unit = 0; |
| - gl->GetIntegerv(GL_ACTIVE_TEXTURE, &active_unit); |
| - return active_unit; |
| -} |
| - |
| -GLES2Interface* ResourceProvider::ContextGL() const { |
| - ContextProvider* context_provider = output_surface_->context_provider(); |
| - return context_provider ? context_provider->ContextGL() : NULL; |
| -} |
| - |
| -class GrContext* ResourceProvider::GrContext() const { |
| - ContextProvider* context_provider = output_surface_->context_provider(); |
| - return context_provider ? context_provider->GrContext() : NULL; |
| -} |
| - |
| -void ResourceProvider::BeginGpuRaster() { |
| - GLES2Interface* gl = ContextGL(); |
| - DCHECK(gl); |
| - |
| - // TODO(alokp): Use a trace macro to push/pop markers. |
| - // Using push/pop functions directly incurs cost to evaluate function |
| - // arguments even when tracing is disabled. |
| - gl->PushGroupMarkerEXT(0, "GpuRasterization"); |
| - |
| - class GrContext* gr_context = GrContext(); |
| - if (gr_context) |
| - gr_context->resetContext(); |
| -} |
| - |
| -void ResourceProvider::EndGpuRaster() { |
| - GLES2Interface* gl = ContextGL(); |
| - DCHECK(gl); |
| - |
| - class GrContext* gr_context = GrContext(); |
| - if (gr_context) |
| - gr_context->flush(); |
| - |
| - // TODO(alokp): Use a trace macro to push/pop markers. |
| - // Using push/pop functions directly incurs cost to evaluate function |
| - // arguments even when tracing is disabled. |
| - gl->PopGroupMarkerEXT(); |
| -} |
| - |
| } // namespace cc |