| Index: cc/resources/resource_provider.cc
|
| diff --git a/cc/resources/resource_provider.cc b/cc/resources/resource_provider.cc
|
| index 35457f70bb16657d25d438ef4d3bd52f8a73ce46..4562ca6b6e989ed615ccd71d2062072b60963b2c 100644
|
| --- a/cc/resources/resource_provider.cc
|
| +++ b/cc/resources/resource_provider.cc
|
| @@ -83,6 +83,7 @@ ResourceProvider::Resource::Resource()
|
| enable_read_lock_fences(false),
|
| read_lock_fence(NULL),
|
| size(),
|
| + shared_memory(NULL),
|
| format(0),
|
| filter(0),
|
| type(static_cast<ResourceType>(0)) {}
|
| @@ -107,6 +108,7 @@ ResourceProvider::Resource::Resource(
|
| enable_read_lock_fences(false),
|
| read_lock_fence(NULL),
|
| size(size),
|
| + shared_memory(NULL),
|
| format(format),
|
| filter(filter),
|
| type(GLTexture) {}
|
| @@ -129,6 +131,7 @@ ResourceProvider::Resource::Resource(
|
| enable_read_lock_fences(false),
|
| read_lock_fence(NULL),
|
| size(size),
|
| + shared_memory(NULL),
|
| format(format),
|
| filter(filter),
|
| type(Bitmap) {}
|
| @@ -273,12 +276,21 @@ ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox(
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| // Just store the information. Mailbox will be consumed in LockForRead().
|
| ResourceId id = next_id_++;
|
| - unsigned texture_id = 0;
|
| - Resource resource(texture_id, gfx::Size(), 0, GL_LINEAR);
|
| - resource.external = true;
|
| - resource.allocated = true;
|
| - resource.mailbox = mailbox;
|
| - resources_[id] = resource;
|
| + if (mailbox.IsTexture()) {
|
| + unsigned texture_id = 0;
|
| + Resource resource(texture_id, gfx::Size(), 0, GL_LINEAR);
|
| + resource.external = true;
|
| + resource.allocated = true;
|
| + resource.mailbox = mailbox;
|
| + resources_[id] = resource;
|
| + } else if (mailbox.IsSharedMemory()) {
|
| + uint8_t *pixels = NULL;
|
| + Resource resource(pixels, mailbox.size(), 0, GL_LINEAR);
|
| + resource.external = true;
|
| + resource.allocated = true;
|
| + resource.mailbox = mailbox;
|
| + resources_[id] = resource;
|
| + }
|
| return id;
|
| }
|
|
|
| @@ -323,20 +335,30 @@ void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it,
|
| DCHECK(context3d);
|
| GLC(context3d, context3d->deleteBuffer(resource->gl_pixel_buffer_id));
|
| }
|
| - if (!resource->mailbox.IsEmpty() && resource->external) {
|
| - WebGraphicsContext3D* context3d = output_surface_->context3d();
|
| - DCHECK(context3d);
|
| + if (resource->mailbox.IsValid() && resource->external) {
|
| unsigned sync_point = resource->mailbox.sync_point();
|
| - if (!lost_resource && resource->gl_id) {
|
| - GLC(context3d, context3d->bindTexture(
|
| - resource->mailbox.target(), resource->gl_id));
|
| - GLC(context3d, context3d->produceTextureCHROMIUM(
|
| - resource->mailbox.target(), resource->mailbox.data()));
|
| + if (resource->mailbox.IsTexture()) {
|
| + WebGraphicsContext3D* context3d = output_surface_->context3d();
|
| + DCHECK(context3d);
|
| + if (!lost_resource && resource->gl_id) {
|
| + GLC(context3d, context3d->bindTexture(
|
| + resource->mailbox.target(), resource->gl_id));
|
| + GLC(context3d, context3d->produceTextureCHROMIUM(
|
| + resource->mailbox.target(), resource->mailbox.data()));
|
| + }
|
| + if (resource->gl_id)
|
| + GLC(context3d, context3d->deleteTexture(resource->gl_id));
|
| + if (!lost_resource && resource->gl_id)
|
| + sync_point = context3d->insertSyncPoint();
|
| + } else {
|
| + DCHECK(resource->mailbox.IsSharedMemory());
|
| + if (resource->shared_memory) {
|
| + DCHECK(resource->shared_memory->memory() == resource->pixels);
|
| + delete resource->shared_memory;
|
| + resource->shared_memory = NULL;
|
| + resource->pixels = NULL;
|
| + }
|
| }
|
| - if (resource->gl_id)
|
| - GLC(context3d, context3d->deleteTexture(resource->gl_id));
|
| - if (!lost_resource && resource->gl_id)
|
| - sync_point = context3d->insertSyncPoint();
|
| resource->mailbox.RunReleaseCallback(sync_point, lost_resource);
|
| }
|
| if (resource->pixels)
|
| @@ -478,18 +500,32 @@ const ResourceProvider::Resource* ResourceProvider::LockForRead(ResourceId id) {
|
| // Uninitialized! Call SetPixels or LockForWrite first.
|
| DCHECK(resource->allocated);
|
|
|
| - if (!resource->gl_id && resource->external && !resource->mailbox.IsEmpty()) {
|
| - WebGraphicsContext3D* context3d = output_surface_->context3d();
|
| - DCHECK(context3d);
|
| - if (resource->mailbox.sync_point()) {
|
| - GLC(context3d, context3d->waitSyncPoint(resource->mailbox.sync_point()));
|
| - resource->mailbox.ResetSyncPoint();
|
| + if (resource->external) {
|
| + if (!resource->gl_id && resource->mailbox.IsTexture()) {
|
| + WebGraphicsContext3D* context3d = output_surface_->context3d();
|
| + DCHECK(context3d);
|
| + if (resource->mailbox.sync_point()) {
|
| + GLC(context3d,
|
| + context3d->waitSyncPoint(resource->mailbox.sync_point()));
|
| + resource->mailbox.ResetSyncPoint();
|
| + }
|
| + resource->gl_id = context3d->createTexture();
|
| + GLC(context3d, context3d->bindTexture(
|
| + resource->mailbox.target(), resource->gl_id));
|
| + GLC(context3d, context3d->consumeTextureCHROMIUM(
|
| + resource->mailbox.target(), resource->mailbox.data()));
|
| + } else if (!resource->shared_memory && resource->mailbox.IsSharedMemory()) {
|
| + CHECK(!resource->pixels);
|
| + resource->size = resource->mailbox.size();
|
| + resource->shared_memory = new base::SharedMemory(
|
| + resource->mailbox.handle(), false);
|
| + const size_t size = 4 * resource->size.GetArea();
|
| + bool success = resource->shared_memory->Map(size);
|
| + CHECK(success);
|
| + resource->format = GL_RGBA;
|
| + resource->pixels =
|
| + reinterpret_cast<uint8_t*>(resource->shared_memory->memory());
|
| }
|
| - resource->gl_id = context3d->createTexture();
|
| - GLC(context3d, context3d->bindTexture(
|
| - resource->mailbox.target(), resource->gl_id));
|
| - GLC(context3d, context3d->consumeTextureCHROMIUM(
|
| - resource->mailbox.target(), resource->mailbox.data()));
|
| }
|
|
|
| resource->lock_for_read_count++;
|
| @@ -857,7 +893,7 @@ bool ResourceProvider::TransferResource(WebGraphicsContext3D* context,
|
| Resource* source = &it->second;
|
| DCHECK(!source->locked_for_write);
|
| DCHECK(!source->lock_for_read_count);
|
| - DCHECK(!source->external || (source->external && !source->mailbox.IsEmpty()));
|
| + DCHECK(!source->external || (source->external && source->mailbox.IsValid()));
|
| DCHECK(source->allocated);
|
| if (source->exported)
|
| return false;
|
| @@ -866,7 +902,8 @@ bool ResourceProvider::TransferResource(WebGraphicsContext3D* context,
|
| resource->filter = source->filter;
|
| resource->size = source->size;
|
|
|
| - if (source->mailbox.IsEmpty()) {
|
| + // TODO(skaslev) Implement this path for shared memory resources.
|
| + if (!source->mailbox.IsTexture()) {
|
| GLC(context3d, context3d->genMailboxCHROMIUM(resource->mailbox.name));
|
| source->mailbox.SetName(resource->mailbox);
|
| } else {
|
|
|