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

Unified Diff: ui/compositor/test/in_process_context_provider.cc

Issue 853353003: ui/compositor: Provide its own 'in process' ContextProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove GrContextForWebGraphicsContext3D usage Created 5 years, 11 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
Index: ui/compositor/test/in_process_context_provider.cc
diff --git a/webkit/common/gpu/context_provider_in_process.cc b/ui/compositor/test/in_process_context_provider.cc
similarity index 61%
copy from webkit/common/gpu/context_provider_in_process.cc
copy to ui/compositor/test/in_process_context_provider.cc
index a12493c85996b80743acac9535c9d4c3f0092199..fdd77256ba0eb3dfdffb652de7d1f7e29d401d0f 100644
--- a/webkit/common/gpu/context_provider_in_process.cc
+++ b/ui/compositor/test/in_process_context_provider.cc
@@ -2,27 +2,49 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "webkit/common/gpu/context_provider_in_process.h"
+#include "ui/compositor/test/in_process_context_provider.h"
#include <set>
#include "base/bind.h"
#include "base/callback_helpers.h"
+#include "base/debug/trace_event.h"
+#include "base/lazy_instance.h"
#include "base/strings/stringprintf.h"
#include "cc/output/managed_memory_policy.h"
#include "gpu/blink/webgraphicscontext3d_in_process_command_buffer_impl.h"
#include "gpu/command_buffer/client/gles2_implementation.h"
-#include "webkit/common/gpu/grcontext_for_webgraphicscontext3d.h"
+#include "gpu/command_buffer/client/gles2_lib.h"
+#include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h"
+#include "third_party/skia/include/gpu/GrContext.h"
+#include "third_party/skia/include/gpu/gl/GrGLInterface.h"
using gpu_blink::WebGraphicsContext3DInProcessCommandBufferImpl;
-namespace webkit {
-namespace gpu {
+namespace ui {
-class ContextProviderInProcess::LostContextCallbackProxy
+namespace {
+
+// Singleton used to initialize and terminate the gles2 library.
+class GLES2Initializer {
+ public:
+ GLES2Initializer() { gles2::Initialize(); }
+
+ ~GLES2Initializer() { gles2::Terminate(); }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(GLES2Initializer);
+};
+
+base::LazyInstance<GLES2Initializer> g_gles2_initializer =
+ LAZY_INSTANCE_INITIALIZER;
+
+} // namespace
+
+class InProcessContextProvider::LostContextCallbackProxy
: public blink::WebGraphicsContext3D::WebGraphicsContextLostCallback {
public:
- explicit LostContextCallbackProxy(ContextProviderInProcess* provider)
+ explicit LostContextCallbackProxy(InProcessContextProvider* provider)
: provider_(provider) {
provider_->context3d_->setContextLostCallback(this);
}
@@ -36,21 +58,21 @@ class ContextProviderInProcess::LostContextCallbackProxy
}
private:
- ContextProviderInProcess* provider_;
+ InProcessContextProvider* provider_;
};
// static
-scoped_refptr<ContextProviderInProcess> ContextProviderInProcess::Create(
+scoped_refptr<InProcessContextProvider> InProcessContextProvider::Create(
scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context3d,
const std::string& debug_name) {
if (!context3d)
return NULL;
- return new ContextProviderInProcess(context3d.Pass(), debug_name);
+ return new InProcessContextProvider(context3d.Pass(), debug_name);
}
// static
-scoped_refptr<ContextProviderInProcess>
-ContextProviderInProcess::CreateOffscreen(
+scoped_refptr<InProcessContextProvider>
+InProcessContextProvider::CreateOffscreen(
bool lose_context_when_out_of_memory) {
blink::WebGraphicsContext3D::Attributes attributes;
attributes.depth = false;
@@ -65,7 +87,7 @@ ContextProviderInProcess::CreateOffscreen(
"Offscreen");
}
-ContextProviderInProcess::ContextProviderInProcess(
+InProcessContextProvider::InProcessContextProvider(
scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context3d,
const std::string& debug_name)
: context3d_(context3d.Pass()),
@@ -76,19 +98,12 @@ ContextProviderInProcess::ContextProviderInProcess(
context_thread_checker_.DetachFromThread();
}
-ContextProviderInProcess::~ContextProviderInProcess() {
+InProcessContextProvider::~InProcessContextProvider() {
DCHECK(main_thread_checker_.CalledOnValidThread() ||
context_thread_checker_.CalledOnValidThread());
}
-blink::WebGraphicsContext3D* ContextProviderInProcess::WebContext3D() {
- DCHECK(lost_context_callback_proxy_); // Is bound to thread.
- DCHECK(context_thread_checker_.CalledOnValidThread());
-
- return context3d_.get();
-}
-
-bool ContextProviderInProcess::BindToCurrentThread() {
+bool InProcessContextProvider::BindToCurrentThread() {
DCHECK(context3d_);
// This is called on the thread the context will be used.
@@ -111,7 +126,7 @@ bool ContextProviderInProcess::BindToCurrentThread() {
return true;
}
-void ContextProviderInProcess::InitializeCapabilities() {
+void InProcessContextProvider::InitializeCapabilities() {
capabilities_.gpu = context3d_->GetImplementation()->capabilities();
size_t mapped_memory_limit = context3d_->GetMappedMemoryLimit();
@@ -123,13 +138,13 @@ void ContextProviderInProcess::InitializeCapabilities() {
}
cc::ContextProvider::Capabilities
-ContextProviderInProcess::ContextCapabilities() {
+InProcessContextProvider::ContextCapabilities() {
DCHECK(lost_context_callback_proxy_); // Is bound to thread.
DCHECK(context_thread_checker_.CalledOnValidThread());
return capabilities_;
}
-::gpu::gles2::GLES2Interface* ContextProviderInProcess::ContextGL() {
+::gpu::gles2::GLES2Interface* InProcessContextProvider::ContextGL() {
DCHECK(context3d_);
DCHECK(lost_context_callback_proxy_); // Is bound to thread.
DCHECK(context_thread_checker_.CalledOnValidThread());
@@ -137,7 +152,7 @@ ContextProviderInProcess::ContextCapabilities() {
return context3d_->GetGLInterface();
}
-::gpu::ContextSupport* ContextProviderInProcess::ContextSupport() {
+::gpu::ContextSupport* InProcessContextProvider::ContextSupport() {
DCHECK(context3d_);
if (!lost_context_callback_proxy_)
return NULL; // Not bound to anything.
@@ -147,25 +162,44 @@ ContextProviderInProcess::ContextCapabilities() {
return context3d_->GetContextSupport();
}
-class GrContext* ContextProviderInProcess::GrContext() {
+static void BindGrContextCallback(const GrGLInterface* interface) {
+ cc::ContextProvider* context_provider =
+ reinterpret_cast<InProcessContextProvider*>(interface->fCallbackData);
+
+ gles2::SetGLContext(context_provider->ContextGL());
+}
+
+class GrContext* InProcessContextProvider::GrContext() {
DCHECK(lost_context_callback_proxy_); // Is bound to thread.
DCHECK(context_thread_checker_.CalledOnValidThread());
if (gr_context_)
- return gr_context_->get();
+ return gr_context_.get();
- gr_context_.reset(new GrContextForWebGraphicsContext3D(context3d_.get()));
- return gr_context_->get();
+ // The GrGLInterface factory will make GL calls using the C GLES2 interface.
+ // Make sure the gles2 library is initialized first on exactly one thread.
+ g_gles2_initializer.Get();
+ gles2::SetGLContext(ContextGL());
+
+ skia::RefPtr<GrGLInterface> interface =
+ skia::AdoptRef(skia_bindings::CreateCommandBufferSkiaGLBinding());
+ interface->fCallback = BindGrContextCallback;
+ interface->fCallbackData = reinterpret_cast<GrGLInterfaceCallbackData>(this);
+
+ gr_context_ = skia::AdoptRef(GrContext::Create(
+ kOpenGL_GrBackend, reinterpret_cast<GrBackendContext>(interface.get())));
+
+ return gr_context_.get();
}
-bool ContextProviderInProcess::IsContextLost() {
+bool InProcessContextProvider::IsContextLost() {
DCHECK(lost_context_callback_proxy_); // Is bound to thread.
DCHECK(context_thread_checker_.CalledOnValidThread());
return context3d_->isContextLost();
}
-void ContextProviderInProcess::VerifyContexts() {
+void InProcessContextProvider::VerifyContexts() {
DCHECK(lost_context_callback_proxy_); // Is bound to thread.
DCHECK(context_thread_checker_.CalledOnValidThread());
@@ -173,14 +207,17 @@ void ContextProviderInProcess::VerifyContexts() {
OnLostContext();
}
-void ContextProviderInProcess::DeleteCachedResources() {
+void InProcessContextProvider::DeleteCachedResources() {
DCHECK(context_thread_checker_.CalledOnValidThread());
- if (gr_context_)
- gr_context_->FreeGpuResources();
+ if (gr_context_) {
+ TRACE_EVENT_INSTANT0("gpu", "GrContext::freeGpuResources", \
piman 2015/01/21 02:07:36 nit: no need for \
+ TRACE_EVENT_SCOPE_THREAD);
+ gr_context_->freeGpuResources();
+ }
}
-void ContextProviderInProcess::OnLostContext() {
+void InProcessContextProvider::OnLostContext() {
DCHECK(context_thread_checker_.CalledOnValidThread());
{
base::AutoLock lock(destroyed_lock_);
@@ -191,17 +228,17 @@ void ContextProviderInProcess::OnLostContext() {
if (!lost_context_callback_.is_null())
base::ResetAndReturn(&lost_context_callback_).Run();
if (gr_context_)
- gr_context_->OnLostContext();
+ gr_context_->abandonContext();
}
-bool ContextProviderInProcess::DestroyedOnMainThread() {
+bool InProcessContextProvider::DestroyedOnMainThread() {
DCHECK(main_thread_checker_.CalledOnValidThread());
base::AutoLock lock(destroyed_lock_);
return destroyed_;
}
-void ContextProviderInProcess::SetLostContextCallback(
+void InProcessContextProvider::SetLostContextCallback(
const LostContextCallback& lost_context_callback) {
DCHECK(context_thread_checker_.CalledOnValidThread());
DCHECK(lost_context_callback_.is_null() ||
@@ -209,10 +246,9 @@ void ContextProviderInProcess::SetLostContextCallback(
lost_context_callback_ = lost_context_callback;
}
-void ContextProviderInProcess::SetMemoryPolicyChangedCallback(
+void InProcessContextProvider::SetMemoryPolicyChangedCallback(
const MemoryPolicyChangedCallback& memory_policy_changed_callback) {
// There's no memory manager for the in-process implementation.
}
-} // namespace gpu
-} // namespace webkit
+} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698