Skip to content

Commit

Permalink
gpu: Change Produce/ConsumeTexture to allow texture sharing
Browse files Browse the repository at this point in the history
This changes the semantics of ProduceTexture to not replacing the current texture by a dud, but instead keeping the existing one, that it also puts into the mailbox. It changes the semantics of ConsumeTexture to deleting the current texture, and replacing it by the mailbox contents (without taking it out of the mailbox). The texture becomes shared. The mailbox is now effectively a weak pointer onto the texture.

BUG=230137

Review URL: https://chromiumcodereview.appspot.com/14188053

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@202992 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
piman@chromium.org committed May 29, 2013
1 parent 150c18a commit 62e65f0
Show file tree
Hide file tree
Showing 22 changed files with 573 additions and 898 deletions.
268 changes: 106 additions & 162 deletions content/common/gpu/texture_image_transport_surface.cc

Large diffs are not rendered by default.

25 changes: 10 additions & 15 deletions content/common/gpu/texture_image_transport_surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "content/common/gpu/gpu_command_buffer_stub.h"
#include "content/common/gpu/image_transport_surface.h"
#include "gpu/command_buffer/service/mailbox_manager.h"
#include "gpu/command_buffer/service/texture_definition.h"
#include "gpu/command_buffer/service/texture_manager.h"
#include "ui/gl/gl_context.h"
#include "ui/gl/gl_surface.h"
Expand All @@ -33,7 +32,6 @@ class TextureImageTransportSurface
virtual bool Initialize() OVERRIDE;
virtual void Destroy() OVERRIDE;
virtual bool DeferDraws() OVERRIDE;
virtual bool Resize(const gfx::Size& size) OVERRIDE;
virtual bool IsOffscreen() OVERRIDE;
virtual bool SwapBuffers() OVERRIDE;
virtual gfx::Size GetSize() OVERRIDE;
Expand All @@ -42,7 +40,6 @@ class TextureImageTransportSurface
virtual std::string GetExtensions() OVERRIDE;
virtual unsigned int GetBackingFrameBufferObject() OVERRIDE;
virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE;
virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE;
virtual bool SetBackbufferAllocation(bool allocated) OVERRIDE;
virtual void SetFrontbufferAllocation(bool allocated) OVERRIDE;
virtual void* GetShareHandle() OVERRIDE;
Expand All @@ -64,31 +61,32 @@ class TextureImageTransportSurface
private:

gfx::Size backbuffer_size() const {
return gfx::Size(backbuffer_->level_infos()[0][0].width,
backbuffer_->level_infos()[0][0].height);
DCHECK(backbuffer_);
GLsizei width = 0;
GLsizei height = 0;
backbuffer_->texture()->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height);
return gfx::Size(width, height);
}

virtual ~TextureImageTransportSurface();
void CreateBackTexture();
void AttachBackTextureToFBO();
void ReleaseBackTexture();
void ReleaseFrontTexture();
void BufferPresentedImpl(const std::string& mailbox_name);
void ProduceTexture();
void ConsumeTexture();

static gpu::gles2::TextureDefinition* CreateTextureDefinition(gfx::Size size,
int service_id);

// The framebuffer that represents this surface (service id). Allocated lazily
// in OnMakeCurrent.
uint32 fbo_id_;

// The current backbuffer.
scoped_ptr<gpu::gles2::TextureDefinition> backbuffer_;
scoped_refptr<gpu::gles2::TextureRef> backbuffer_;
scoped_refptr<gpu::gles2::TextureRef> frontbuffer_;

// The mailbox name for the current backbuffer texture. Needs to be unique per
// GL texture and is invalid while service_id is zero.
gpu::gles2::MailboxName mailbox_name_;
gpu::gles2::MailboxName back_mailbox_name_;
gpu::gles2::MailboxName front_mailbox_name_;

// The current size of the GLSurface. Used to disambiguate from the current
// texture size which might be outdated (since we use two buffers).
Expand All @@ -108,9 +106,6 @@ class TextureImageTransportSurface
// the actual rendering is always redirected to an FBO.
scoped_refptr<gfx::GLSurface> surface_;

// Holds a reference to the underlying context for cleanup.
scoped_refptr<gfx::GLContext> context_;

// Whether a SwapBuffers is pending.
bool is_swap_buffers_pending_;

Expand Down
69 changes: 35 additions & 34 deletions gpu/GLES2/extensions/CHROMIUM/CHROMIUM_texture_mailbox.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ Overview
objects in different contexts where the contexts would not normally share
texture resources. Three new functions are exported. glGenMailboxCHROMIUM
generates a name that can be used to identify texture image data outside
the scope of a context group. glProduceMailboxCHROMIUM moves texture image
data out of a texture object and into a mailbox. glConsumeMailboxCHROMIUM
moves texture image data out of a mailbox and into a texture object.
the scope of a context group. glProduceMailboxCHROMIUM associates a texture
object with a global mailbox name. glConsumeMailboxCHROMIUM associates the
texture object referenced by a mailbox name to a texture name.

New Procedures and Functions

Expand All @@ -38,18 +38,19 @@ New Procedures and Functions

void glProduceTextureCHROMIUM (GLenum target, const GLbyte *mailbox)

Moves the image data and parameters of the currently bound texture object
into the mailbox. The texture object is redefined as though all its levels
had been resized to zero by zero and the texture object is therefore
incomplete. The texture object parameters are undefined. The texture
object is no longer immutable. If the mailbox previously contained image
data, the old image data is deleted.
Associates the currently bound texture object with the mailbox name. A
given texture object can be associated with several mailbox names. If a
mailbox name was previously associated with a texture object, that
previous association is broken. The currently bound texture object is not
modified by the operation.

If glProduceTextureCHROMIUM generates an error, the associated image data
and state is preserved in the texture object.
If glProduceTextureCHROMIUM generates an error, the mailbox name keeps its
current association, if any.

The mailbox is emptied and the texture image data deleted if the context
is destroyed before being consumed. See glConsumeTextureCHROMIUM.
The mailbox does not keep a reference to the texture object. When the
texture object is destroyed (deleted from all context groups, and unbound
from all texture units and framebuffer attachments), the mailbox is
disassociated from the texture object.

<target> uses the same parameters as TexImage2D.

Expand All @@ -58,10 +59,6 @@ New Procedures and Functions

INVALID_OPERATION is generated if <target> is not a valid target.

INVALID_OPERATION is generated if the texture is attached to a framebuffer.

INVALID_OPERATION is generated if the texture is immutable.

INVALID_OPERATION is generated if <mailbox> is invalid.


Expand All @@ -71,30 +68,32 @@ New Procedures and Functions

<mailbox> identifies a GL_MAILBOX_SIZE_CHROMIUM byte sized name returned by
glGenMailboxCHROMIUM.

Redefines the image data and parameters of the currently bound texture
object with the image data and parameters in the mailbox and empties the
mailbox. All levels are redefined, and the immutable state is set according
to the contents of the mailbox.

If glConsumeTextureCHROMIUM generates an error, the associated image data
is preserved in the texture object.

Deletes the currently bound texture object, and redefines its texture name
to point to the texture object associated with the mailbox name. All the
contexts that have consumed the texture object, as well as produced it share
the texture object, as if the contexts were part of the share group. The
texture object is deleted once all contexts have deleted the texture name
associated with the texture object, and detached it from all framebuffer
objects as well as texture unit bindings. See Appendix C of the OpenGL ES
2.0 specification for details relative to visibility in one context of
changes to the shared texture object in another context.

If glConsumeTextureCHROMIUM generates an error, the currently bound texture
object is preserved.

INVALID_OPERATION is generated if <target> is not a valid target.

INVALID_OPERATION is generated if <mailbox> is empty.

INVALID_OPERATION is generated if <mailbox> is not in the scope of the
context.

INVALID_OPERATION is generated if <mailbox> is invalid.

INVALID_OPERATION is generated if the texture is attached to a framebuffer.
INVALID_OPERATION is generated if <mailbox> is not associated with a texture
object.

INVALID_OPERATION is generated if the texture is immutable.
INVALID_OPERATION is generated if the texture object associated with
<mailbox> has a different target than <target>.

INVALID_OPERATION is generated if the image data is invalid in the current
context.
INVALID_OPERATION is generated if the currently bound texture was previously
deleted (for example in another context), hence doesn't have a name.

New Tokens

Expand All @@ -117,3 +116,5 @@ New State
Revision History

4/25/2011 Documented the extension
5/23/2013 Major revision in Produce/Consume semantics, introducing
sharing.
2 changes: 0 additions & 2 deletions gpu/command_buffer/service/context_group.cc
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,6 @@ void ContextGroup::Destroy(GLES2Decoder* decoder, bool have_context) {
}

if (texture_manager_ != NULL) {
mailbox_manager_->DestroyOwnedTextures(texture_manager_.get(),
have_context);
texture_manager_->Destroy(have_context);
texture_manager_.reset();
}
Expand Down
8 changes: 8 additions & 0 deletions gpu/command_buffer/service/framebuffer_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ class RenderbufferAttachment
return renderbuffer_->samples();
}

virtual GLuint object_name() const OVERRIDE {
return renderbuffer_->client_id();
}

virtual bool cleared() const OVERRIDE {
return renderbuffer_->cleared();
}
Expand Down Expand Up @@ -149,6 +153,10 @@ class TextureAttachment
return 0;
}

virtual GLuint object_name() const OVERRIDE {
return texture_ref_->client_id();
}

virtual bool cleared() const OVERRIDE {
return texture_ref_->texture()->IsLevelCleared(target_, level_);
}
Expand Down
1 change: 1 addition & 0 deletions gpu/command_buffer/service/framebuffer_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class GPU_EXPORT Framebuffer : public base::RefCounted<Framebuffer> {
virtual GLsizei height() const = 0;
virtual GLenum internal_format() const = 0;
virtual GLsizei samples() const = 0;
virtual GLuint object_name() const = 0;
virtual bool cleared() const = 0;
virtual void SetCleared(
RenderbufferManager* renderbuffer_manager,
Expand Down
4 changes: 2 additions & 2 deletions gpu/command_buffer/service/gl_context_virtual.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ void GLContextVirtual::ReleaseCurrent(gfx::GLSurface* surface) {
bool GLContextVirtual::IsCurrent(gfx::GLSurface* surface) {
// If it's a real surface it needs to be current.
if (surface &&
!surface->GetBackingFrameBufferObject() &&
!surface->IsOffscreen())
!surface->IsOffscreen() &&
!surface->GetBackingFrameBufferObject())
return shared_context_->IsCurrent(surface);

// Otherwise, only insure the context itself is current.
Expand Down
Loading

0 comments on commit 62e65f0

Please sign in to comment.