Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(976)

Unified Diff: content/browser/renderer_host/compositor_impl_android.cc

Issue 20185002: ContextProvider in OutputSurface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: contextprovider: fix android output surface impls Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/aura/reflector_impl.cc ('k') | content/common/gpu/client/context_provider_command_buffer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/renderer_host/compositor_impl_android.cc
diff --git a/content/browser/renderer_host/compositor_impl_android.cc b/content/browser/renderer_host/compositor_impl_android.cc
index 94ab1393c847f00e27463f931fdf3503a3250741..d57e7c0c8be80b359afdfa529c3881b83aa12990 100644
--- a/content/browser/renderer_host/compositor_impl_android.cc
+++ b/content/browser/renderer_host/compositor_impl_android.cc
@@ -48,8 +48,9 @@ namespace {
// Used for drawing directly to the screen. Bypasses resizing and swaps.
class DirectOutputSurface : public cc::OutputSurface {
public:
- DirectOutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d)
- : cc::OutputSurface(context3d.Pass()) {
+ DirectOutputSurface(
+ const scoped_refptr<cc::ContextProvider>& context_provider)
+ : cc::OutputSurface(context_provider) {
capabilities_.adjust_deadline_for_parent = false;
}
@@ -57,28 +58,31 @@ class DirectOutputSurface : public cc::OutputSurface {
surface_size_ = size;
}
virtual void SwapBuffers(cc::CompositorFrame*) OVERRIDE {
- context3d()->shallowFlushCHROMIUM();
+ context_provider_->Context3d()->shallowFlushCHROMIUM();
}
};
// Used to override capabilities_.adjust_deadline_for_parent to false
class OutputSurfaceWithoutParent : public cc::OutputSurface {
public:
- OutputSurfaceWithoutParent(scoped_ptr<WebKit::WebGraphicsContext3D> context3d)
- : cc::OutputSurface(context3d.Pass()) {
+ OutputSurfaceWithoutParent(
+ const scoped_refptr<ContextProviderCommandBuffer>& context_provider)
+ : cc::OutputSurface(context_provider),
+ command_buffer_context_(context_provider->Context3d()) {
capabilities_.adjust_deadline_for_parent = false;
}
virtual void SwapBuffers(cc::CompositorFrame* frame) OVERRIDE {
- content::WebGraphicsContext3DCommandBufferImpl* command_buffer =
- static_cast<content::WebGraphicsContext3DCommandBufferImpl*>(context3d());
content::CommandBufferProxyImpl* command_buffer_proxy =
- command_buffer->GetCommandBufferProxy();
+ command_buffer_context_->GetCommandBufferProxy();
DCHECK(command_buffer_proxy);
command_buffer_proxy->SetLatencyInfo(frame->metadata.latency_info);
OutputSurface::SwapBuffers(frame);
}
+
+ private:
+ WebGraphicsContext3DCommandBufferImpl* command_buffer_context_;
};
static bool g_initialized = false;
@@ -358,6 +362,46 @@ bool CompositorImpl::CopyTextureToBitmap(WebKit::WebGLId texture_id,
return true;
}
+static scoped_ptr<WebKit::WebGraphicsContext3D> CreateInProcessViewContext(
+ const WebKit::WebGraphicsContext3D::Attributes attributes
+ ANativeWindow* window) {
+ using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl;
+ return WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext(
+ attributes, window).PassAs<WebKit::WebGraphicsContext3D>();
+}
+
+static scoped_ptr<WebKit::WebGraphicsContext3D> CreateGpuProcessViewContext(
+ const WebKit::WebGraphicsContext3D::Attributes attributes
+ int surface_id) {
+ GpuChannelHostFactory* factory = BrowserGpuChannelHostFactory::instance();
+ GURL url("chrome://gpu/Compositor::createContext3D");
+ scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
+ new WebGraphicsContext3DCommandBufferImpl(surface_id_,
+ url,
+ factory,
+ weak_factory_.GetWeakPtr()));
+ static const size_t kBytesPerPixel = 4;
+ gfx::DeviceDisplayInfo display_info;
+ size_t full_screen_texture_size_in_bytes =
+ display_info.GetDisplayHeight() *
+ display_info.GetDisplayWidth() *
+ kBytesPerPixel;
+ if (!context->Initialize(
+ attrs,
+ false,
+ CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE,
+ 64 * 1024, // command buffer size
+ std::min(full_screen_texture_size_in_bytes,
+ kDefaultStartTransferBufferSize),
+ kDefaultMinTransferBufferSize,
+ std::min(3 * full_screen_texture_size_in_bytes,
+ kDefaultMaxTransferBufferSize))) {
+ LOG(ERROR) << "Failed to create 3D context for compositor.";
+ return scoped_ptr<WebKit::WebGraphicsContext3D>();
+ }
+ return context.PassAs<WebKit::WebGraphicsContext3D>();
+}
+
scoped_ptr<cc::OutputSurface> CompositorImpl::CreateOutputSurface(
bool fallback) {
WebKit::WebGraphicsContext3D::Attributes attrs;
@@ -365,47 +409,29 @@ scoped_ptr<cc::OutputSurface> CompositorImpl::CreateOutputSurface(
attrs.noAutomaticFlushes = true;
if (g_use_direct_gl) {
- scoped_ptr<WebKit::WebGraphicsContext3D> context(
- webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl::
- CreateViewContext(attrs, window_));
- if (!window_) {
- return scoped_ptr<cc::OutputSurface>(
- new DirectOutputSurface(context.Pass()));
- }
+ scoped_refptr<webkit::gpu::ContextProviderInProcess> context_provider =
+ webkit::gpu::ContextProviderInProcess::Create(
+ base::Bind(&CreateInProcessViewContext, attrs, window_));
+
+ scoped_ptr<cc::OutputSurface> output_surface;
+ if (!window_)
+ output_surface.reset(new DirectOutputSurface(context_provider));
+ else
+ output_surface.reset(new cc::OutputSurface(context_provider));
+ return output_surface.Pass();
+ }
- return make_scoped_ptr(new cc::OutputSurface(context.Pass()));
- } else {
- DCHECK(window_ && surface_id_);
- GpuChannelHostFactory* factory = BrowserGpuChannelHostFactory::instance();
- GURL url("chrome://gpu/Compositor::createContext3D");
- scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
- new WebGraphicsContext3DCommandBufferImpl(surface_id_,
- url,
- factory,
- weak_factory_.GetWeakPtr()));
- static const size_t kBytesPerPixel = 4;
- gfx::DeviceDisplayInfo display_info;
- size_t full_screen_texture_size_in_bytes =
- display_info.GetDisplayHeight() *
- display_info.GetDisplayWidth() *
- kBytesPerPixel;
- if (!context->Initialize(
- attrs,
- false,
- CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE,
- 64 * 1024, // command buffer size
- std::min(full_screen_texture_size_in_bytes,
- kDefaultStartTransferBufferSize),
- kDefaultMinTransferBufferSize,
- std::min(3 * full_screen_texture_size_in_bytes,
- kDefaultMaxTransferBufferSize))) {
- LOG(ERROR) << "Failed to create 3D context for compositor.";
- return scoped_ptr<cc::OutputSurface>();
- }
- return scoped_ptr<cc::OutputSurface>(
- new OutputSurfaceWithoutParent(
- context.PassAs<WebKit::WebGraphicsContext3D>()));
+ DCHECK(window_ && surface_id_);
aelias_OOO_until_Jul13 2013/08/14 21:44:10 nit: split into two DCHECKs
danakj 2013/08/14 21:46:07 Absolutely.
+
+ scoped_refptr<ContextProviderCommandBuffer> context_provider =
+ ContextProviderCommandBuffer::Create(
+ base::Bind(&CreateGpuProcessViewContext, attrs, surface_id_));
+ if (!context_provider.get()) {
+ LOG(ERROR) << "Failed to create 3D context for compositor.";
+ return scoped_ptr<cc::OutputSurface>();
}
+ return scoped_ptr<cc::OutputSurface>(
+ new OutputSurfaceWithoutParent(context_provider));
}
void CompositorImpl::OnLostResources() {
« no previous file with comments | « content/browser/aura/reflector_impl.cc ('k') | content/common/gpu/client/context_provider_command_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698