summaryrefslogtreecommitdiffstats
path: root/content/renderer
diff options
context:
space:
mode:
authorapatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-29 20:02:01 +0000
committerapatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-29 20:02:01 +0000
commitde472286527828640709fe3dfcfb48d074e63098 (patch)
tree4873318953ce9b06f7e3742430f865df70893267 /content/renderer
parentcf0a77e1e18f547316c8da0a55c3ddeedae18263 (diff)
downloadchromium_src-de472286527828640709fe3dfcfb48d074e63098.zip
chromium_src-de472286527828640709fe3dfcfb48d074e63098.tar.gz
chromium_src-de472286527828640709fe3dfcfb48d074e63098.tar.bz2
Allow the renderer process to map textures from one context into another.
This is on an individual resource basis rather than general share groups in order to hide be able to hide the full namespace from untrusted plugins. Accelerated 2D canvas now no longer needs to copy its backing store on every page composite and the redundant backing texture is not needed, saving video memory. Unit tests for the GPU service to follow. Patch to delete copyTextureToParentTexture extensions from gpu/ to follow. BUG=90714 Review URL: http://codereview.chromium.org/7529015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@94743 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/renderer')
-rw-r--r--content/renderer/gpu/command_buffer_proxy.cc21
-rw-r--r--content/renderer/gpu/command_buffer_proxy.h6
-rw-r--r--content/renderer/gpu/renderer_gl_context.cc69
-rw-r--r--content/renderer/gpu/renderer_gl_context.h29
-rw-r--r--content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.cc5
5 files changed, 97 insertions, 33 deletions
diff --git a/content/renderer/gpu/command_buffer_proxy.cc b/content/renderer/gpu/command_buffer_proxy.cc
index c4ec7a7..8c0967b 100644
--- a/content/renderer/gpu/command_buffer_proxy.cc
+++ b/content/renderer/gpu/command_buffer_proxy.cc
@@ -349,6 +349,27 @@ void CommandBufferProxy::OnSwapBuffers() {
swap_buffers_callback_->Run();
}
+bool CommandBufferProxy::MapExternalResource(
+ gpu::resource_type::ResourceType resource_type,
+ uint32 resource_source_id,
+ CommandBufferProxy* source_command_buffer,
+ uint32 resource_dest_id) {
+ if (last_state_.error != gpu::error::kNoError)
+ return false;
+
+ if (!Send(new GpuCommandBufferMsg_MapExternalResource(
+ route_id_,
+ resource_type,
+ resource_source_id,
+ source_command_buffer ?
+ source_command_buffer->route_id() : MSG_ROUTING_NONE,
+ resource_dest_id))) {
+ return false;
+ }
+
+ return true;
+}
+
bool CommandBufferProxy::SetParent(CommandBufferProxy* parent_command_buffer,
uint32 parent_texture_id) {
if (last_state_.error != gpu::error::kNoError)
diff --git a/content/renderer/gpu/command_buffer_proxy.h b/content/renderer/gpu/command_buffer_proxy.h
index c8600f8..028581e 100644
--- a/content/renderer/gpu/command_buffer_proxy.h
+++ b/content/renderer/gpu/command_buffer_proxy.h
@@ -15,6 +15,7 @@
#include "base/memory/linked_ptr.h"
#include "base/memory/scoped_ptr.h"
#include "content/renderer/gpu/gpu_video_decode_accelerator_host.h"
+#include "gpu/command_buffer/common/constants.h"
#include "gpu/command_buffer/common/command_buffer.h"
#include "ipc/ipc_channel.h"
#include "ipc/ipc_message.h"
@@ -64,6 +65,11 @@ class CommandBufferProxy : public gpu::CommandBuffer,
virtual void SetContextLostReason(gpu::error::ContextLostReason reason);
virtual void OnSwapBuffers();
+ bool MapExternalResource(gpu::resource_type::ResourceType resource_type,
+ uint32 resource_source_id,
+ CommandBufferProxy* source_command_buffer,
+ uint32 resource_dest_id);
+
// Reparent a command buffer. TODO(apatrick): going forward, the notion of
// the parent / child relationship between command buffers is going away in
// favor of the notion of surfaces that can be drawn to in one command buffer
diff --git a/content/renderer/gpu/renderer_gl_context.cc b/content/renderer/gpu/renderer_gl_context.cc
index 894a950..1627810 100644
--- a/content/renderer/gpu/renderer_gl_context.cc
+++ b/content/renderer/gpu/renderer_gl_context.cc
@@ -134,6 +134,38 @@ RendererGLContext* RendererGLContext::CreateOffscreenContext(
#endif
}
+bool RendererGLContext::MapExternalResource(
+ gpu::resource_type::ResourceType resource_type,
+ uint32 resource_source_id,
+ RendererGLContext* source_context,
+ uint32 resource_dest_id) {
+ if (!command_buffer_)
+ return false;
+
+ return command_buffer_->MapExternalResource(
+ resource_type,
+ resource_source_id,
+ source_context ? source_context->command_buffer_ : NULL,
+ resource_dest_id);
+}
+
+bool RendererGLContext::MapExternalResourceToParent(
+ gpu::resource_type::ResourceType resource_type,
+ uint32 resource_source_id,
+ uint32 resource_dest_id) {
+ if (!command_buffer_)
+ return false;
+
+ if (!parent_.get())
+ return false;
+
+ return parent_->MapExternalResource(
+ resource_type,
+ resource_source_id,
+ this,
+ resource_dest_id);
+}
+
bool RendererGLContext::SetParent(RendererGLContext* new_parent) {
if (parent_.get() == new_parent)
return true;
@@ -195,45 +227,18 @@ uint32 RendererGLContext::GetParentTextureId() {
}
uint32 RendererGLContext::CreateParentTexture(const gfx::Size& size) {
- // Allocate a texture ID with respect to the parent.
if (parent_.get()) {
- if (!MakeCurrent(parent_.get()))
- return 0;
- uint32 texture_id = parent_->gles2_implementation_->MakeTextureId();
- parent_->gles2_implementation_->BindTexture(GL_TEXTURE_2D, texture_id);
- parent_->gles2_implementation_->TexParameteri(
- GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- parent_->gles2_implementation_->TexParameteri(
- GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- parent_->gles2_implementation_->TexParameteri(
- GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- parent_->gles2_implementation_->TexParameteri(
- GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-
- parent_->gles2_implementation_->TexImage2D(GL_TEXTURE_2D,
- 0, // mip level
- GL_RGBA,
- size.width(),
- size.height(),
- 0, // border
- GL_RGBA,
- GL_UNSIGNED_BYTE,
- NULL);
- // Make sure that the parent texture's storage is allocated before we let
- // the caller attempt to use it.
- int32 token = parent_->gles2_helper_->InsertToken();
- parent_->gles2_helper_->WaitForToken(token);
- return texture_id;
+ // Reserve a parent texture ID on the client side.
+ uint32 parent_texture_id = 0;
+ parent_->gles2_implementation_->GenTextures(1, &parent_texture_id);
+ return parent_texture_id;
}
return 0;
}
void RendererGLContext::DeleteParentTexture(uint32 texture) {
- if (parent_.get()) {
- if (!MakeCurrent(parent_.get()))
- return;
+ if (parent_.get())
parent_->gles2_implementation_->DeleteTextures(1, &texture);
- }
}
void RendererGLContext::SetSwapBuffersCallback(Callback0::Type* callback) {
diff --git a/content/renderer/gpu/renderer_gl_context.h b/content/renderer/gpu/renderer_gl_context.h
index 911e0c6..833d124 100644
--- a/content/renderer/gpu/renderer_gl_context.h
+++ b/content/renderer/gpu/renderer_gl_context.h
@@ -15,6 +15,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "build/build_config.h"
+#include "gpu/command_buffer/common/constants.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/size.h"
@@ -124,6 +125,34 @@ class RendererGLContext : public base::SupportsWeakPtr<RendererGLContext> {
const int32* attrib_list,
const GURL& active_url);
+ // Map a resource from an external context into this context. The source
+ // context need not be in the same share group from the client's point of
+ // view, allowing safe sharing between an "untrusted" context, like Pepper
+ // and a compositor context.
+ //
+ // Currently only texture resources are supported. TODO(apatrick): generalize
+ // this as appropriate.
+ //
+ // To unmap a previously mapped external resource, delete it in the
+ // destination context group. This will not delete the underlying texture
+ // object, just disassociate it with the id in the destination context group.
+ //
+ // The lifetime of the external resource is managed by the context group it
+ // was originally created in. When the last context in that group is destroyed
+ // the resource becomes invalid in all other context groups it is mapped into.
+ bool MapExternalResource(gpu::resource_type::ResourceType resource_type,
+ uint32 resource_source_id,
+ RendererGLContext* source_context,
+ uint32 resource_dest_id);
+
+ // TODO(apatrick): this is a workaround until the parent / child relationship
+ // between contexts is removed. MapExternalResource has no such restrictions
+ // on the relationship between contexts. Use it instead.
+ bool MapExternalResourceToParent(
+ gpu::resource_type::ResourceType resource_type,
+ uint32 resource_source_id,
+ uint32 resource_dest_id);
+
// Sets the parent context. If any parent textures have been created for
// another parent, it is important to delete them before changing the parent.
bool SetParent(RendererGLContext* parent);
diff --git a/content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.cc b/content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.cc
index 8d4d0c8..a39a118 100644
--- a/content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.cc
+++ b/content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.cc
@@ -333,8 +333,11 @@ void WebGraphicsContext3DCommandBufferImpl::unmapTexSubImage2DCHROMIUM(
void WebGraphicsContext3DCommandBufferImpl::copyTextureToParentTextureCHROMIUM(
WebGLId texture, WebGLId parentTexture) {
TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::copyTextureToCompositor");
- gl_->CopyTextureToParentTextureCHROMIUM(texture, parentTexture);
+
gl_->Flush();
+ context_->MapExternalResourceToParent(gpu::resource_type::kTexture,
+ texture,
+ parentTexture);
}
void WebGraphicsContext3DCommandBufferImpl::