Commit 25d47817 authored by apatrick@chromium.org's avatar apatrick@chromium.org

Use 3D graphics context shareResources flag to decide whether a context should share resources.

Before, it abused the noExtensions flag to determine to disable share groups for WebGL, which was awful.

This patch is dependent on https://bugs.webkit.org/show_bug.cgi?id=66516.

See also http://codereview.chromium.org/7669072 where I perpetrated the aforementioned hack.

BUG=92356
Review URL: http://codereview.chromium.org/7669072

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98527 0039d316-1c4b-4281-b951-d872f2087c98
parent 583844c2
......@@ -82,7 +82,6 @@ RendererGLContext::~RendererGLContext() {
RendererGLContext* RendererGLContext::CreateViewContext(
GpuChannelHost* channel,
int render_view_id,
bool share_resources,
RendererGLContext* share_group,
const char* allowed_extensions,
const int32* attrib_list,
......@@ -93,8 +92,6 @@ RendererGLContext* RendererGLContext::CreateViewContext(
true,
render_view_id,
gfx::Size(),
share_resources,
false,
share_group,
allowed_extensions,
attrib_list,
......@@ -110,7 +107,6 @@ RendererGLContext* RendererGLContext::CreateViewContext(
RendererGLContext* RendererGLContext::CreateOffscreenContext(
GpuChannelHost* channel,
const gfx::Size& size,
bool share_resources,
RendererGLContext* share_group,
const char* allowed_extensions,
const int32* attrib_list,
......@@ -121,8 +117,6 @@ RendererGLContext* RendererGLContext::CreateOffscreenContext(
false,
0,
size,
share_resources,
false,
share_group,
allowed_extensions,
attrib_list,
......@@ -291,8 +285,6 @@ RendererGLContext::RendererGLContext(GpuChannelHost* channel)
bool RendererGLContext::Initialize(bool onscreen,
int render_view_id,
const gfx::Size& size,
bool share_resources,
bool bind_generates_resource,
RendererGLContext* share_group,
const char* allowed_extensions,
const int32* attrib_list,
......@@ -307,6 +299,8 @@ bool RendererGLContext::Initialize(bool onscreen,
// Ensure the gles2 library is initialized first in a thread safe way.
g_gles2_initializer.Get();
bool share_resources = true;
bool bind_generates_resources = true;
std::vector<int32> attribs;
while (attrib_list) {
int32 attrib = *attrib_list++;
......@@ -323,6 +317,12 @@ bool RendererGLContext::Initialize(bool onscreen,
attribs.push_back(attrib);
attribs.push_back(*attrib_list++);
break;
case SHARE_RESOURCES:
share_resources = !!(*attrib_list++);
break;
case BIND_GENERATES_RESOURCES:
bind_generates_resources = !!(*attrib_list++);
break;
case NONE:
attribs.push_back(attrib);
attrib_list = NULL;
......@@ -408,7 +408,7 @@ bool RendererGLContext::Initialize(bool onscreen,
transfer_buffer.ptr,
transfer_buffer_id_,
share_resources,
bind_generates_resource);
bind_generates_resources);
return true;
}
......
......@@ -35,27 +35,30 @@ class RendererGLContext : public base::SupportsWeakPtr<RendererGLContext> {
public:
// These are the same error codes as used by EGL.
enum Error {
SUCCESS = 0x3000,
NOT_INITIALIZED = 0x3001,
BAD_ATTRIBUTE = 0x3004,
BAD_RendererGLContext = 0x3006,
CONTEXT_LOST = 0x300E
SUCCESS = 0x3000,
NOT_INITIALIZED = 0x3001,
BAD_ATTRIBUTE = 0x3004,
BAD_RendererGLContext = 0x3006,
CONTEXT_LOST = 0x300E
};
// RendererGLContext configuration attributes. These are the same as used by
// EGL. Attributes are matched using a closest fit algorithm.
// RendererGLContext configuration attributes. Those in the 16-bit range are
// the same as used by EGL. Those outside the 16-bit range are unique to
// Chromium. Attributes are matched using a closest fit algorithm.
enum Attribute {
ALPHA_SIZE = 0x3021,
BLUE_SIZE = 0x3022,
GREEN_SIZE = 0x3023,
RED_SIZE = 0x3024,
DEPTH_SIZE = 0x3025,
STENCIL_SIZE = 0x3026,
SAMPLES = 0x3031,
SAMPLE_BUFFERS = 0x3032,
HEIGHT = 0x3056,
WIDTH = 0x3057,
NONE = 0x3038 // Attrib list = terminator
ALPHA_SIZE = 0x3021,
BLUE_SIZE = 0x3022,
GREEN_SIZE = 0x3023,
RED_SIZE = 0x3024,
DEPTH_SIZE = 0x3025,
STENCIL_SIZE = 0x3026,
SAMPLES = 0x3031,
SAMPLE_BUFFERS = 0x3032,
HEIGHT = 0x3056,
WIDTH = 0x3057,
NONE = 0x3038, // Attrib list = terminator
SHARE_RESOURCES = 0x10000,
BIND_GENERATES_RESOURCES = 0x10001
};
// Reasons that a lost context might have been provoked.
......@@ -100,7 +103,6 @@ class RendererGLContext : public base::SupportsWeakPtr<RendererGLContext> {
static RendererGLContext* CreateViewContext(
GpuChannelHost* channel,
int render_view_id,
bool share_resources,
RendererGLContext* share_group,
const char* allowed_extensions,
const int32* attrib_list,
......@@ -117,7 +119,6 @@ class RendererGLContext : public base::SupportsWeakPtr<RendererGLContext> {
static RendererGLContext* CreateOffscreenContext(
GpuChannelHost* channel,
const gfx::Size& size,
bool share_resources,
RendererGLContext* share_group,
const char* allowed_extensions,
const int32* attrib_list,
......@@ -179,8 +180,6 @@ class RendererGLContext : public base::SupportsWeakPtr<RendererGLContext> {
bool Initialize(bool onscreen,
int render_view_id,
const gfx::Size& size,
bool share_resources,
bool bind_generates_resource,
RendererGLContext* share_group,
const char* allowed_extensions,
const int32* attrib_list,
......
......@@ -33,7 +33,7 @@
#include "webkit/glue/gl_bindings_skia_cmd_buffer.h"
static base::LazyInstance<std::set<WebGraphicsContext3DCommandBufferImpl*> >
g_all_contexts(base::LINKER_INITIALIZED);
g_all_shared_contexts(base::LINKER_INITIALIZED);
WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl()
: context_(NULL),
......@@ -54,7 +54,7 @@ WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl()
WebGraphicsContext3DCommandBufferImpl::
~WebGraphicsContext3DCommandBufferImpl() {
g_all_contexts.Pointer()->erase(this);
g_all_shared_contexts.Pointer()->erase(this);
delete context_;
}
......@@ -95,6 +95,8 @@ bool WebGraphicsContext3DCommandBufferImpl::initialize(
RendererGLContext::STENCIL_SIZE, stencil_size,
RendererGLContext::SAMPLES, samples,
RendererGLContext::SAMPLE_BUFFERS, sample_buffers,
RendererGLContext::SHARE_RESOURCES, attributes.shareResources ? 1 : 0,
RendererGLContext::BIND_GENERATES_RESOURCES, 0,
RendererGLContext::NONE,
};
......@@ -115,14 +117,10 @@ bool WebGraphicsContext3DCommandBufferImpl::initialize(
if (web_view && web_view->mainFrame())
active_url = GURL(web_view->mainFrame()->document().url());
// HACK: Assume this is a WebGL context by looking for the noExtensions
// attribute. WebGL contexts must not go in the share group because they
// rely on destruction of the context to clean up owned resources. Putting
// them in a share group would prevent this from happening.
RendererGLContext* share_group = NULL;
if (!attributes.noExtensions) {
share_group = g_all_contexts.Pointer()->empty() ?
NULL : (*g_all_contexts.Pointer()->begin())->context_;
if (attributes.shareResources) {
share_group = g_all_shared_contexts.Pointer()->empty() ?
NULL : (*g_all_shared_contexts.Pointer()->begin())->context_;
}
render_directly_to_web_view_ = render_directly_to_web_view;
......@@ -136,7 +134,6 @@ bool WebGraphicsContext3DCommandBufferImpl::initialize(
context_ = RendererGLContext::CreateViewContext(
host,
renderview->routing_id(),
!attributes.noExtensions,
share_group,
preferred_extensions,
attribs,
......@@ -150,7 +147,6 @@ bool WebGraphicsContext3DCommandBufferImpl::initialize(
context_ = RendererGLContext::CreateOffscreenContext(
host,
gfx::Size(1, 1),
!attributes.noExtensions,
share_group,
preferred_extensions,
attribs,
......@@ -190,8 +186,8 @@ bool WebGraphicsContext3DCommandBufferImpl::initialize(
attributes_.antialias = samples > 0;
}
if (!attributes.noExtensions)
g_all_contexts.Pointer()->insert(this);
if (attributes.shareResources)
g_all_shared_contexts.Pointer()->insert(this);
return true;
}
......
......@@ -344,12 +344,13 @@ void RenderWidgetFullscreenPepper::CreateContext() {
RendererGLContext::STENCIL_SIZE, 0,
RendererGLContext::SAMPLES, 0,
RendererGLContext::SAMPLE_BUFFERS, 0,
RendererGLContext::SHARE_RESOURCES, 0,
RendererGLContext::BIND_GENERATES_RESOURCES, 1,
RendererGLContext::NONE,
};
context_ = RendererGLContext::CreateViewContext(
host,
routing_id(),
false,
NULL,
"GL_OES_packed_depth_stencil GL_OES_depth24",
attribs,
......
......@@ -198,8 +198,8 @@ const int32 kCommandBufferSize = 1024 * 1024;
const int32 kTransferBufferSize = 1024 * 1024;
static base::LazyInstance<
std::set<WebGraphicsContext3DInProcessCommandBufferImpl*> > g_all_contexts(
base::LINKER_INITIALIZED);
std::set<WebGraphicsContext3DInProcessCommandBufferImpl*> >
g_all_shared_contexts(base::LINKER_INITIALIZED);
// Singleton used to initialize and terminate the gles2 library.
class GLES2Initializer {
......@@ -575,7 +575,7 @@ WebGraphicsContext3DInProcessCommandBufferImpl::
WebGraphicsContext3DInProcessCommandBufferImpl::
~WebGraphicsContext3DInProcessCommandBufferImpl() {
g_all_contexts.Pointer()->erase(this);
g_all_shared_contexts.Pointer()->erase(this);
}
// This string should only be passed for WebGL contexts. Nothing ELSE!!!
......@@ -627,14 +627,10 @@ bool WebGraphicsContext3DInProcessCommandBufferImpl::initialize(
}
}
// HACK: Assume this is a WebGL context by looking for the noExtensions
// attribute. WebGL contexts must not go in the share group because they
// rely on destruction of the context to clean up owned resources. Putting
// them in a share group would prevent this from happening.
WebGraphicsContext3DInProcessCommandBufferImpl* context_group = NULL;
if (!attributes.noExtensions)
context_group = g_all_contexts.Pointer()->empty() ?
NULL : *g_all_contexts.Pointer()->begin();
if (attributes.shareResources)
context_group = g_all_shared_contexts.Pointer()->empty() ?
NULL : *g_all_shared_contexts.Pointer()->begin();
context_ = GLInProcessContext::CreateOffscreenContext(
parent_context,
......@@ -672,8 +668,8 @@ bool WebGraphicsContext3DInProcessCommandBufferImpl::initialize(
}
makeContextCurrent();
if (!attributes.noExtensions)
g_all_contexts.Pointer()->insert(this);
if (attributes.shareResources)
g_all_shared_contexts.Pointer()->insert(this);
return true;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment