Commit 856135eb authored by boliu@chromium.org's avatar boliu@chromium.org

Add create WGC3DInProcessCommandBuffer for on-screen context

The on-screen path will be by Android WebView for hardware draws.

BUG=166777

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@195162 0039d316-1c4b-4281-b951-d872f2087c98
parent 00b70e0e
...@@ -25,7 +25,7 @@ scoped_ptr<OutputSurface> LayerTreePixelTest::CreateOutputSurface() { ...@@ -25,7 +25,7 @@ scoped_ptr<OutputSurface> LayerTreePixelTest::CreateOutputSurface() {
using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl;
scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context3d( scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context3d(
new WebGraphicsContext3DInProcessCommandBufferImpl( WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext(
WebKit::WebGraphicsContext3D::Attributes())); WebKit::WebGraphicsContext3D::Attributes()));
return make_scoped_ptr( return make_scoped_ptr(
new OutputSurface(context3d.PassAs<WebKit::WebGraphicsContext3D>())); new OutputSurface(context3d.PassAs<WebKit::WebGraphicsContext3D>()));
......
...@@ -57,10 +57,10 @@ PixelTest::~PixelTest() {} ...@@ -57,10 +57,10 @@ PixelTest::~PixelTest() {}
void PixelTest::SetUp() { void PixelTest::SetUp() {
CHECK(gfx::InitializeGLBindings(gfx::kGLImplementationOSMesaGL)); CHECK(gfx::InitializeGLBindings(gfx::kGLImplementationOSMesaGL));
scoped_ptr<webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl> using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl;
context3d( scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context3d(
new webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl( WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext(
WebKit::WebGraphicsContext3D::Attributes())); WebKit::WebGraphicsContext3D::Attributes()));
output_surface_.reset(new OutputSurface( output_surface_.reset(new OutputSurface(
context3d.PassAs<WebKit::WebGraphicsContext3D>())); context3d.PassAs<WebKit::WebGraphicsContext3D>()));
resource_provider_ = ResourceProvider::Create(output_surface_.get(), 0); resource_provider_ = ResourceProvider::Create(output_surface_.get(), 0);
......
...@@ -59,8 +59,9 @@ bool ContextProviderInProcess::InitializeOnMainThread() { ...@@ -59,8 +59,9 @@ bool ContextProviderInProcess::InitializeOnMainThread() {
attributes.shareResources = true; attributes.shareResources = true;
attributes.noAutomaticFlushes = true; attributes.noAutomaticFlushes = true;
using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl;
context3d_.reset( context3d_.reset(
new webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl( WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext(
attributes)); attributes));
return context3d_; return context3d_;
......
...@@ -89,15 +89,12 @@ class GLInProcessContext { ...@@ -89,15 +89,12 @@ class GLInProcessContext {
void PumpCommands(); void PumpCommands();
bool GetBufferChanged(int32 transfer_buffer_id); bool GetBufferChanged(int32 transfer_buffer_id);
// Create a GLInProcessContext that renders to an offscreen frame buffer. If // Create a GLInProcessContext, if |is_offscreen| is true, renders to an
// parent is not NULL, that GLInProcessContext can access a copy of the // offscreen context. |attrib_list| must be NULL or a NONE-terminated list
// created GLInProcessContext's frame buffer that is updated every time // of attribute/value pairs.
// SwapBuffers is called. It is not as general as shared GLInProcessContexts static GLInProcessContext* CreateContext(
// in other implementations of OpenGL. If parent is not NULL, it must be used bool is_offscreen,
// on the same thread as the parent. A child GLInProcessContext may not gfx::AcceleratedWidget window,
// outlive its parent. attrib_list must be NULL or a NONE-terminated list of
// attribute/value pairs.
static GLInProcessContext* CreateOffscreenContext(
const gfx::Size& size, const gfx::Size& size,
bool share_resources, bool share_resources,
const char* allowed_extensions, const char* allowed_extensions,
...@@ -148,7 +145,9 @@ class GLInProcessContext { ...@@ -148,7 +145,9 @@ class GLInProcessContext {
private: private:
explicit GLInProcessContext(bool share_resources); explicit GLInProcessContext(bool share_resources);
bool Initialize(const gfx::Size& size, bool Initialize(bool is_offscreen,
gfx::AcceleratedWidget window,
const gfx::Size& size,
const char* allowed_extensions, const char* allowed_extensions,
const int32* attrib_list, const int32* attrib_list,
gfx::GpuPreference gpu_preference); gfx::GpuPreference gpu_preference);
...@@ -208,7 +207,9 @@ GLInProcessContext::~GLInProcessContext() { ...@@ -208,7 +207,9 @@ GLInProcessContext::~GLInProcessContext() {
Destroy(); Destroy();
} }
GLInProcessContext* GLInProcessContext::CreateOffscreenContext( GLInProcessContext* GLInProcessContext::CreateContext(
bool is_offscreen,
gfx::AcceleratedWidget window,
const gfx::Size& size, const gfx::Size& size,
bool share_resources, bool share_resources,
const char* allowed_extensions, const char* allowed_extensions,
...@@ -217,6 +218,8 @@ GLInProcessContext* GLInProcessContext::CreateOffscreenContext( ...@@ -217,6 +218,8 @@ GLInProcessContext* GLInProcessContext::CreateOffscreenContext(
scoped_ptr<GLInProcessContext> context( scoped_ptr<GLInProcessContext> context(
new GLInProcessContext(share_resources)); new GLInProcessContext(share_resources));
if (!context->Initialize( if (!context->Initialize(
is_offscreen,
window,
size, size,
allowed_extensions, allowed_extensions,
attrib_list, attrib_list,
...@@ -385,10 +388,13 @@ GLInProcessContext::GLInProcessContext(bool share_resources) ...@@ -385,10 +388,13 @@ GLInProcessContext::GLInProcessContext(bool share_resources)
context_lost_(false) { context_lost_(false) {
} }
bool GLInProcessContext::Initialize(const gfx::Size& size, bool GLInProcessContext::Initialize(
const char* allowed_extensions, bool is_offscreen,
const int32* attrib_list, gfx::AcceleratedWidget window,
gfx::GpuPreference gpu_preference) { const gfx::Size& size,
const char* allowed_extensions,
const int32* attrib_list,
gfx::GpuPreference gpu_preference) {
// Use one share group for all contexts. // Use one share group for all contexts.
CR_DEFINE_STATIC_LOCAL(scoped_refptr<gfx::GLShareGroup>, share_group, CR_DEFINE_STATIC_LOCAL(scoped_refptr<gfx::GLShareGroup>, share_group,
(new gfx::GLShareGroup)); (new gfx::GLShareGroup));
...@@ -461,7 +467,10 @@ bool GLInProcessContext::Initialize(const gfx::Size& size, ...@@ -461,7 +467,10 @@ bool GLInProcessContext::Initialize(const gfx::Size& size,
decoder_->set_engine(gpu_scheduler_.get()); decoder_->set_engine(gpu_scheduler_.get());
surface_ = gfx::GLSurface::CreateOffscreenGLSurface(false, gfx::Size(1, 1)); if (is_offscreen)
surface_ = gfx::GLSurface::CreateOffscreenGLSurface(false, size);
else
surface_ = gfx::GLSurface::CreateViewGLSurface(false, window);
if (!surface_.get()) { if (!surface_.get()) {
LOG(ERROR) << "Could not create GLSurface."; LOG(ERROR) << "Could not create GLSurface.";
...@@ -574,10 +583,32 @@ void GLInProcessContext::OnContextLost() { ...@@ -574,10 +583,32 @@ void GLInProcessContext::OnContextLost() {
context_lost_callback_.Run(); context_lost_callback_.Run();
} }
// static
WebGraphicsContext3DInProcessCommandBufferImpl*
WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext(
const WebKit::WebGraphicsContext3D::Attributes& attributes,
gfx::AcceleratedWidget window) {
return new WebGraphicsContext3DInProcessCommandBufferImpl(
attributes, false, window);
}
// static
WebGraphicsContext3DInProcessCommandBufferImpl*
WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext(
const WebKit::WebGraphicsContext3D::Attributes& attributes) {
return new WebGraphicsContext3DInProcessCommandBufferImpl(
attributes, true, gfx::kNullAcceleratedWidget);
}
WebGraphicsContext3DInProcessCommandBufferImpl:: WebGraphicsContext3DInProcessCommandBufferImpl::
WebGraphicsContext3DInProcessCommandBufferImpl( WebGraphicsContext3DInProcessCommandBufferImpl(
const WebKit::WebGraphicsContext3D::Attributes& attributes) const WebKit::WebGraphicsContext3D::Attributes& attributes,
: initialized_(false), bool is_offscreen,
gfx::AcceleratedWidget window)
: is_offscreen_(is_offscreen),
window_(window),
initialized_(false),
initialize_failed_(false), initialize_failed_(false),
context_(NULL), context_(NULL),
gl_(NULL), gl_(NULL),
...@@ -625,7 +656,9 @@ bool WebGraphicsContext3DInProcessCommandBufferImpl::MaybeInitializeGL() { ...@@ -625,7 +656,9 @@ bool WebGraphicsContext3DInProcessCommandBufferImpl::MaybeInitializeGL() {
// discrete GPU is created, or the last one is destroyed. // discrete GPU is created, or the last one is destroyed.
gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu;
context_ = GLInProcessContext::CreateOffscreenContext( context_ = GLInProcessContext::CreateContext(
is_offscreen_,
window_,
gfx::Size(1, 1), gfx::Size(1, 1),
attributes_.shareResources, attributes_.shareResources,
preferred_extensions, preferred_extensions,
......
...@@ -45,9 +45,15 @@ class GLInProcessContext; ...@@ -45,9 +45,15 @@ class GLInProcessContext;
class WEBKIT_GPU_EXPORT WebGraphicsContext3DInProcessCommandBufferImpl class WEBKIT_GPU_EXPORT WebGraphicsContext3DInProcessCommandBufferImpl
: public NON_EXPORTED_BASE(WebKit::WebGraphicsContext3D) { : public NON_EXPORTED_BASE(WebKit::WebGraphicsContext3D) {
public: public:
static WebGraphicsContext3DInProcessCommandBufferImpl*
CreateViewContext(
const WebKit::WebGraphicsContext3D::Attributes& attributes,
gfx::AcceleratedWidget window);
static WebGraphicsContext3DInProcessCommandBufferImpl*
CreateOffscreenContext(
const WebKit::WebGraphicsContext3D::Attributes& attributes);
explicit WebGraphicsContext3DInProcessCommandBufferImpl(
const WebKit::WebGraphicsContext3D::Attributes& attributes);
virtual ~WebGraphicsContext3DInProcessCommandBufferImpl(); virtual ~WebGraphicsContext3DInProcessCommandBufferImpl();
//---------------------------------------------------------------------- //----------------------------------------------------------------------
...@@ -526,6 +532,11 @@ class WEBKIT_GPU_EXPORT WebGraphicsContext3DInProcessCommandBufferImpl ...@@ -526,6 +532,11 @@ class WEBKIT_GPU_EXPORT WebGraphicsContext3DInProcessCommandBufferImpl
virtual GrGLInterface* onCreateGrGLInterface(); virtual GrGLInterface* onCreateGrGLInterface();
private: private:
WebGraphicsContext3DInProcessCommandBufferImpl(
const WebKit::WebGraphicsContext3D::Attributes& attributes,
bool is_offscreen,
gfx::AcceleratedWidget window);
// SwapBuffers callback. // SwapBuffers callback.
void OnSwapBuffersComplete(); void OnSwapBuffersComplete();
virtual void OnContextLost(); virtual void OnContextLost();
...@@ -536,6 +547,11 @@ class WEBKIT_GPU_EXPORT WebGraphicsContext3DInProcessCommandBufferImpl ...@@ -536,6 +547,11 @@ class WEBKIT_GPU_EXPORT WebGraphicsContext3DInProcessCommandBufferImpl
// instead of going through WebGraphicsContext3D. // instead of going through WebGraphicsContext3D.
void ClearContext(); void ClearContext();
bool is_offscreen_;
// Only used when not offscreen.
gfx::AcceleratedWidget window_;
bool initialized_; bool initialized_;
bool initialize_failed_; bool initialize_failed_;
......
...@@ -371,7 +371,8 @@ WebKit::WebGraphicsContext3D* ...@@ -371,7 +371,8 @@ WebKit::WebGraphicsContext3D*
TestWebKitPlatformSupport::createOffscreenGraphicsContext3D( TestWebKitPlatformSupport::createOffscreenGraphicsContext3D(
const WebKit::WebGraphicsContext3D::Attributes& attributes) { const WebKit::WebGraphicsContext3D::Attributes& attributes) {
using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl;
return new WebGraphicsContext3DInProcessCommandBufferImpl(attributes); return WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext(
attributes);
} }
WebKit::WebGraphicsContext3D* WebKit::WebGraphicsContext3D*
......
...@@ -266,7 +266,8 @@ WebKit::WebIDBFactory* TestShellWebKitInit::idbFactory() { ...@@ -266,7 +266,8 @@ WebKit::WebIDBFactory* TestShellWebKitInit::idbFactory() {
WebKit::WebGraphicsContext3D* WebKit::WebGraphicsContext3D*
TestShellWebKitInit::createOffscreenGraphicsContext3D( TestShellWebKitInit::createOffscreenGraphicsContext3D(
const WebKit::WebGraphicsContext3D::Attributes& attributes) { const WebKit::WebGraphicsContext3D::Attributes& attributes) {
return new webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl( using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl;
return WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext(
attributes); attributes);
} }
......
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