Chromium Code Reviews| Index: cc/resources/resource_provider.cc |
| diff --git a/cc/resources/resource_provider.cc b/cc/resources/resource_provider.cc |
| index 35457f70bb16657d25d438ef4d3bd52f8a73ce46..57ae12d7bbdf3bc00eaef4d8cbb5bb4d7fcf2bc0 100644 |
| --- a/cc/resources/resource_provider.cc |
| +++ b/cc/resources/resource_provider.cc |
| @@ -85,6 +85,7 @@ ResourceProvider::Resource::Resource() |
| size(), |
| format(0), |
| filter(0), |
| + image_id(0), |
| type(static_cast<ResourceType>(0)) {} |
| ResourceProvider::Resource::~Resource() {} |
| @@ -109,6 +110,7 @@ ResourceProvider::Resource::Resource( |
| size(size), |
| format(format), |
| filter(filter), |
| + image_id(0), |
| type(GLTexture) {} |
| ResourceProvider::Resource::Resource( |
| @@ -131,6 +133,7 @@ ResourceProvider::Resource::Resource( |
| size(size), |
| format(format), |
| filter(filter), |
| + image_id(0), |
| type(Bitmap) {} |
| ResourceProvider::Child::Child() {} |
| @@ -308,6 +311,12 @@ void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it, |
| if (style == ForShutdown && resource->exported) |
| lost_resource = true; |
| + if (resource->image_id) { |
| + WebGraphicsContext3D* context3d = output_surface_->context3d(); |
| + DCHECK(context3d); |
| + GLC(context3d, context3d->destroyImageCHROMIUM(resource->image_id)); |
| + } |
| + |
| if (resource->gl_id && !resource->external) { |
| WebGraphicsContext3D* context3d = output_surface_->context3d(); |
| DCHECK(context3d); |
| @@ -369,6 +378,7 @@ void ResourceProvider::SetPixels(ResourceId id, |
| DCHECK(!resource->external); |
| DCHECK(!resource->exported); |
| DCHECK(ReadLockFenceHasPassed(resource)); |
| + DCHECK(!resource->image_id); |
| LazyAllocate(resource); |
| if (resource->gl_id) { |
| @@ -631,7 +641,9 @@ ResourceProvider::ResourceProvider(OutputSurface* output_surface) |
| use_texture_usage_hint_(false), |
| use_shallow_flush_(false), |
| max_texture_size_(0), |
| - best_texture_format_(0) {} |
| + best_texture_format_(0), |
| + use_gpu_memory_buffers_(false) { |
| +} |
| bool ResourceProvider::Initialize(int highp_threshold_min) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| @@ -859,6 +871,7 @@ bool ResourceProvider::TransferResource(WebGraphicsContext3D* context, |
| DCHECK(!source->lock_for_read_count); |
| DCHECK(!source->external || (source->external && !source->mailbox.IsEmpty())); |
| DCHECK(source->allocated); |
| + DCHECK(!source->image_id); |
| if (source->exported) |
| return false; |
| resource->id = id; |
| @@ -895,17 +908,23 @@ void ResourceProvider::AcquirePixelBuffer(ResourceId id) { |
| if (resource->gl_id) { |
| WebGraphicsContext3D* context3d = output_surface_->context3d(); |
| DCHECK(context3d); |
| - if (!resource->gl_pixel_buffer_id) |
| - resource->gl_pixel_buffer_id = context3d->createBuffer(); |
| - context3d->bindBuffer( |
| - GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| - resource->gl_pixel_buffer_id); |
| - context3d->bufferData( |
| - GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| - resource->size.width() * resource->size.height() * 4, |
| - NULL, |
| - GL_DYNAMIC_DRAW); |
| - context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| + if (!use_gpu_memory_buffers_) { |
| + if (!resource->gl_pixel_buffer_id) |
| + resource->gl_pixel_buffer_id = context3d->createBuffer(); |
| + context3d->bindBuffer( |
| + GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| + resource->gl_pixel_buffer_id); |
| + context3d->bufferData( |
| + GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| + resource->size.width() * resource->size.height() * 4, |
| + NULL, |
| + GL_DYNAMIC_DRAW); |
| + context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| + } else { |
| + DCHECK_EQ(0u, resource->image_id); |
| + resource->image_id = context3d->createImageCHROMIUM( |
| + resource->size.width(), resource->size.height(), GL_RGBA8_OES); |
|
reveman
2013/05/17 01:48:08
please put this in a new AcquireImage() function i
kaanb
2013/05/17 21:27:36
Done.
|
| + } |
| } |
| if (resource->pixels) { |
| @@ -926,19 +945,25 @@ void ResourceProvider::ReleasePixelBuffer(ResourceId id) { |
| DCHECK(!resource->exported); |
| if (resource->gl_id) { |
| - if (!resource->gl_pixel_buffer_id) |
| + if (!resource->gl_pixel_buffer_id && resource->image_id == 0) |
| return; |
| WebGraphicsContext3D* context3d = output_surface_->context3d(); |
| DCHECK(context3d); |
| - context3d->bindBuffer( |
| - GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| - resource->gl_pixel_buffer_id); |
| - context3d->bufferData( |
| - GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| - 0, |
| - NULL, |
| - GL_DYNAMIC_DRAW); |
| - context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| + if (resource->image_id == 0) { |
| + DCHECK(resource->gl_pixel_buffer_id); |
| + context3d->bindBuffer( |
| + GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| + resource->gl_pixel_buffer_id); |
| + context3d->bufferData( |
| + GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| + 0, |
| + NULL, |
| + GL_DYNAMIC_DRAW); |
| + context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| + } else { |
| + context3d->destroyImageCHROMIUM(resource->image_id); |
| + resource->image_id = 0; |
|
reveman
2013/05/17 01:48:08
and this in ReleaseImage()
kaanb
2013/05/17 21:27:36
Done.
|
| + } |
| } |
| if (resource->pixels) { |
| @@ -960,15 +985,20 @@ uint8_t* ResourceProvider::MapPixelBuffer(ResourceId id) { |
| if (resource->gl_id) { |
| WebGraphicsContext3D* context3d = output_surface_->context3d(); |
| DCHECK(context3d); |
| - DCHECK(resource->gl_pixel_buffer_id); |
| - context3d->bindBuffer( |
| - GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| - resource->gl_pixel_buffer_id); |
| - uint8_t* image = static_cast<uint8_t*>( |
| - context3d->mapBufferCHROMIUM( |
| - GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, GL_WRITE_ONLY)); |
| - context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| - return image; |
| + if (resource->image_id == 0) { |
| + DCHECK(resource->gl_pixel_buffer_id); |
| + context3d->bindBuffer( |
| + GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| + resource->gl_pixel_buffer_id); |
| + uint8_t* image = static_cast<uint8_t*>( |
| + context3d->mapBufferCHROMIUM( |
| + GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, GL_WRITE_ONLY)); |
| + context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| + return image; |
| + } else { |
| + return static_cast<uint8_t*>( |
| + context3d->mapImageCHROMIUM(resource->image_id, GL_READ_WRITE)); |
|
reveman
2013/05/17 01:48:08
and I prefer this in a MapImage() function. We mig
kaanb
2013/05/17 21:27:36
Done.
|
| + } |
| } |
| if (resource->pixels) |
| @@ -988,13 +1018,17 @@ void ResourceProvider::UnmapPixelBuffer(ResourceId id) { |
| if (resource->gl_id) { |
| WebGraphicsContext3D* context3d = output_surface_->context3d(); |
| DCHECK(context3d); |
| - DCHECK(resource->gl_pixel_buffer_id); |
| - context3d->bindBuffer( |
| - GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| - resource->gl_pixel_buffer_id); |
| - context3d->unmapBufferCHROMIUM( |
| - GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM); |
| - context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| + if (resource->image_id == 0) { |
| + DCHECK(resource->gl_pixel_buffer_id); |
| + context3d->bindBuffer( |
| + GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| + resource->gl_pixel_buffer_id); |
| + context3d->unmapBufferCHROMIUM( |
| + GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM); |
| + context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| + } else { |
| + context3d->unmapImageCHROMIUM(resource->image_id); |
|
reveman
2013/05/17 01:48:08
UnmapImage.
kaanb
2013/05/17 21:27:36
Done.
|
| + } |
| } |
| } |
| @@ -1008,6 +1042,7 @@ void ResourceProvider::SetPixelsFromBuffer(ResourceId id) { |
| DCHECK(!resource->external); |
| DCHECK(!resource->exported); |
| DCHECK(ReadLockFenceHasPassed(resource)); |
| + DCHECK(!resource->image_id); |
|
reveman
2013/05/17 01:48:08
I don't think this DCHECK should be here.
kaanb
2013/05/17 21:27:36
Done.
|
| LazyAllocate(resource); |
| if (resource->gl_id) { |
| @@ -1081,39 +1116,44 @@ void ResourceProvider::BeginSetPixels(ResourceId id) { |
| if (resource->gl_id) { |
| WebGraphicsContext3D* context3d = output_surface_->context3d(); |
| DCHECK(context3d); |
| - DCHECK(resource->gl_pixel_buffer_id); |
| - context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); |
| - context3d->bindBuffer( |
| - GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| - resource->gl_pixel_buffer_id); |
| - if (!resource->gl_upload_query_id) |
| - resource->gl_upload_query_id = context3d->createQueryEXT(); |
| - context3d->beginQueryEXT( |
| - GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM, |
| - resource->gl_upload_query_id); |
| - if (allocate) { |
| - context3d->asyncTexImage2DCHROMIUM(GL_TEXTURE_2D, |
| - 0, /* level */ |
| - resource->format, |
| - resource->size.width(), |
| - resource->size.height(), |
| - 0, /* border */ |
| - resource->format, |
| - GL_UNSIGNED_BYTE, |
| - NULL); |
| + if (resource->image_id == 0) { |
| + DCHECK(resource->gl_pixel_buffer_id); |
| + context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); |
| + context3d->bindBuffer( |
| + GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| + resource->gl_pixel_buffer_id); |
| + if (!resource->gl_upload_query_id) |
| + resource->gl_upload_query_id = context3d->createQueryEXT(); |
| + context3d->beginQueryEXT( |
| + GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM, |
| + resource->gl_upload_query_id); |
| + if (allocate) { |
| + context3d->asyncTexImage2DCHROMIUM(GL_TEXTURE_2D, |
| + 0, /* level */ |
| + resource->format, |
| + resource->size.width(), |
| + resource->size.height(), |
| + 0, /* border */ |
| + resource->format, |
| + GL_UNSIGNED_BYTE, |
| + NULL); |
| + } else { |
| + context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D, |
| + 0, /* level */ |
| + 0, /* x */ |
| + 0, /* y */ |
| + resource->size.width(), |
| + resource->size.height(), |
| + resource->format, |
| + GL_UNSIGNED_BYTE, |
| + NULL); |
| + } |
| + context3d->endQueryEXT(GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM); |
| + context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| } else { |
| - context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D, |
| - 0, /* level */ |
| - 0, /* x */ |
| - 0, /* y */ |
| - resource->size.width(), |
| - resource->size.height(), |
| - resource->format, |
| - GL_UNSIGNED_BYTE, |
| - NULL); |
| + context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); |
| + context3d->bindTexImage2DCHROMIUM(GL_TEXTURE_2D, resource->image_id); |
|
reveman
2013/05/17 01:48:08
please add a BindImage() function for this instead
kaanb
2013/05/17 21:27:36
Done.
|
| } |
| - context3d->endQueryEXT(GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM); |
| - context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| } |
| if (resource->pixels) |
| @@ -1132,7 +1172,7 @@ void ResourceProvider::ForceSetPixelsToComplete(ResourceId id) { |
| DCHECK(resource->pending_set_pixels); |
| DCHECK(!resource->set_pixels_completion_forced); |
| - if (resource->gl_id) { |
| + if (resource->gl_id && resource->image_id == 0) { |
| WebGraphicsContext3D* context3d = output_surface_->context3d(); |
| GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); |
| GLC(context3d, context3d->waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)); |
| @@ -1150,7 +1190,7 @@ bool ResourceProvider::DidSetPixelsComplete(ResourceId id) { |
| DCHECK(resource->locked_for_write); |
| DCHECK(resource->pending_set_pixels); |
| - if (resource->gl_id) { |
| + if (resource->gl_id && resource->image_id == 0) { |
| WebGraphicsContext3D* context3d = output_surface_->context3d(); |
| DCHECK(context3d); |
| DCHECK(resource->gl_upload_query_id); |
| @@ -1180,12 +1220,20 @@ void ResourceProvider::AbortSetPixels(ResourceId id) { |
| if (resource->gl_id) { |
| WebGraphicsContext3D* context3d = output_surface_->context3d(); |
| DCHECK(context3d); |
| - DCHECK(resource->gl_upload_query_id); |
| - // CHROMIUM_async_pixel_transfers currently doesn't have a way to |
| - // abort an upload. The best we can do is delete the query and |
| - // the texture. |
| - context3d->deleteQueryEXT(resource->gl_upload_query_id); |
| - resource->gl_upload_query_id = 0; |
| + if (resource->image_id == 0) { |
| + DCHECK(resource->gl_upload_query_id); |
| + // CHROMIUM_async_pixel_transfers currently doesn't have a way to |
| + // abort an upload. The best we can do is delete the query and |
| + // the texture. |
| + context3d->deleteQueryEXT(resource->gl_upload_query_id); |
| + resource->gl_upload_query_id = 0; |
| + } else { |
| + // CHROMIUM_map_image doesn't have a way to abort an upload either. |
| + // So we just destroy the image. |
| + DCHECK(resource->image_id); |
| + context3d->destroyImageCHROMIUM(resource->image_id); |
| + resource->image_id = 0; |
|
reveman
2013/05/17 01:48:08
no need for any of these changes.
kaanb
2013/05/17 21:27:36
Done.
|
| + } |
| context3d->deleteTexture(resource->gl_id); |
| resource->gl_id = CreateTextureId(context3d); |
| resource->allocated = false; |
| @@ -1212,6 +1260,7 @@ void ResourceProvider::LazyAllocate(Resource* resource) { |
| WebGraphicsContext3D* context3d = output_surface_->context3d(); |
| gfx::Size& size = resource->size; |
| GLenum format = resource->format; |
| + |
| GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); |
| if (use_texture_storage_ext_ && IsTextureFormatSupportedForStorage(format)) { |
| GLenum storage_format = TextureToStorageFormat(format); |
| @@ -1221,6 +1270,8 @@ void ResourceProvider::LazyAllocate(Resource* resource) { |
| size.width(), |
| size.height())); |
| } else { |
| + // TODO(kaanb): Check with reviewers if we want this call |
| + // for GpuMemoryBuffers? |
|
reveman
2013/05/17 01:48:08
I don't think this affects zero-copy. just like it
kaanb
2013/05/17 21:27:36
Acknowledged.
|
| GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, |
| 0, |
| format, |
| @@ -1242,4 +1293,8 @@ void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, |
| resource->enable_read_lock_fences = enable; |
| } |
| +void ResourceProvider::SetUseGpuMemoryBuffers(bool use_gpu_memory_buffers) { |
| + use_gpu_memory_buffers_ = use_gpu_memory_buffers; |
| +} |
| + |
| } // namespace cc |