diff options
author | abarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-03 05:25:00 +0000 |
---|---|---|
committer | abarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-03 05:25:00 +0000 |
commit | 1cd366843381f5acea03d1bf9b2ed1bf0561f695 (patch) | |
tree | 5b01fb71c65344f2fc8be8d2a43d8f67b2466eb9 /mojo/services | |
parent | bbd7ee0092f40f1d6bee1567ef95297356d9f632 (diff) | |
download | chromium_src-1cd366843381f5acea03d1bf9b2ed1bf0561f695.zip chromium_src-1cd366843381f5acea03d1bf9b2ed1bf0561f695.tar.gz chromium_src-1cd366843381f5acea03d1bf9b2ed1bf0561f695.tar.bz2 |
Mojo should use a command buffer instead of raw GL
This CL switches the native_viewport from using raw GL calls to
using an in-process command buffer. I've plumbed the client
interface to the command buffer as far as the
NativeViewportController, but we really ought to plumb it all
the way into the sample_app.
Of course, once the sample_app moves out-of-process, we'll want
to switch to an out-of-process command buffer.
R=ben@chromium.org, jamesr@chromium.org
Review URL: https://codereview.chromium.org/56543002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@232669 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/services')
8 files changed, 99 insertions, 29 deletions
diff --git a/mojo/services/native_viewport/DEPS b/mojo/services/native_viewport/DEPS index 00b7d5c..39917a2 100644 --- a/mojo/services/native_viewport/DEPS +++ b/mojo/services/native_viewport/DEPS @@ -1,6 +1,6 @@ include_rules = [ "+base", + "+gpu/command_buffer/client", "+ui/events", "+ui/gfx", - "+ui/gl", ] diff --git a/mojo/services/native_viewport/android/mojo_viewport.cc b/mojo/services/native_viewport/android/mojo_viewport.cc index 15f868f..8530b7c 100644 --- a/mojo/services/native_viewport/android/mojo_viewport.cc +++ b/mojo/services/native_viewport/android/mojo_viewport.cc @@ -6,10 +6,10 @@ #include <android/native_window_jni.h> #include "base/android/jni_android.h" +#include "base/bind.h" +#include "base/location.h" +#include "base/single_thread_task_runner.h" #include "jni/MojoViewport_jni.h" -#include "ui/gl/gl_bindings.h" -#include "ui/gl/gl_context.h" -#include "ui/gl/scoped_make_current.h" namespace mojo { namespace services { @@ -49,29 +49,25 @@ void MojoViewport::Destroy(JNIEnv* env, jobject obj) { void MojoViewport::SurfaceCreated(JNIEnv* env, jobject obj, jobject jsurface) { base::android::ScopedJavaLocalRef<jobject> protector(env, jsurface); - DCHECK(jsurface); - window_ = ANativeWindow_fromSurface(env, jsurface); - DCHECK(window_); - - surface_ = new gfx::NativeViewGLSurfaceEGL(window_); - CHECK(surface_->Initialize()); - - gl_context_ = gfx::GLContext::CreateGLContext( - 0, surface_.get(), gfx::PreferDiscreteGpu); - ui::ScopedMakeCurrent make_current(gl_context_.get(), surface_.get()); - glClearColor(0, 1, 0, 0); - glClear(GL_COLOR_BUFFER_BIT); - surface_->SwapBuffers(); + ANativeWindow* window = ANativeWindow_fromSurface(env, jsurface); + + ui_runner_->PostTask(FROM_HERE, base::Bind( + &NativeViewportAndroid::OnNativeWindowCreated, + native_viewport_, + window)); } void MojoViewport::SurfaceDestroyed(JNIEnv* env, jobject obj) { - DCHECK(window_); - ANativeWindow_release(window_); - window_ = NULL; + ui_runner_->PostTask(FROM_HERE, base::Bind( + &NativeViewportAndroid::OnNativeWindowDestroyed, native_viewport_)); } void MojoViewport::SurfaceSetSize( JNIEnv* env, jobject obj, jint width, jint height) { + ui_runner_->PostTask(FROM_HERE, base::Bind( + &NativeViewportAndroid::OnResized, + native_viewport_, + gfx::Size(width, height))); } bool MojoViewport::Register(JNIEnv* env) { diff --git a/mojo/services/native_viewport/android/mojo_viewport.h b/mojo/services/native_viewport/android/mojo_viewport.h index f4dec23..6c60285 100644 --- a/mojo/services/native_viewport/android/mojo_viewport.h +++ b/mojo/services/native_viewport/android/mojo_viewport.h @@ -12,7 +12,6 @@ #include "base/memory/weak_ptr.h" #include "base/single_thread_task_runner.h" #include "mojo/services/native_viewport/native_viewport_android.h" -#include "ui/gl/gl_surface_egl.h" struct ANativeWindow; @@ -47,10 +46,6 @@ class MojoViewport { scoped_refptr<base::SingleThreadTaskRunner> ui_runner_; base::WeakPtr<NativeViewportAndroid> native_viewport_; - ANativeWindow* window_; - scoped_refptr<gfx::GLSurface> surface_; - scoped_refptr<gfx::GLContext> gl_context_; - DISALLOW_COPY_AND_ASSIGN(MojoViewport); }; diff --git a/mojo/services/native_viewport/native_viewport.h b/mojo/services/native_viewport/native_viewport.h index e39b435..f2f2692 100644 --- a/mojo/services/native_viewport/native_viewport.h +++ b/mojo/services/native_viewport/native_viewport.h @@ -11,6 +11,12 @@ namespace gfx { class Size; } +namespace gpu { +namespace gles2 { +class GLES2Interface; +} +} + namespace ui { class Event; } @@ -27,10 +33,10 @@ class NativeViewportDelegate { virtual ~NativeViewportDelegate() {} virtual bool OnEvent(ui::Event* event) = 0; - - virtual void OnResized(const gfx::Size& size) = 0; - virtual void OnDestroyed() = 0; + virtual void OnGLContextAvailable(gpu::gles2::GLES2Interface* gl) = 0; + virtual void OnGLContextLost() = 0; + virtual void OnResized(const gfx::Size& size) = 0; }; // Encapsulation of platform-specific Viewport. diff --git a/mojo/services/native_viewport/native_viewport_android.cc b/mojo/services/native_viewport/native_viewport_android.cc index a0d2455..753b8ed 100644 --- a/mojo/services/native_viewport/native_viewport_android.cc +++ b/mojo/services/native_viewport/native_viewport_android.cc @@ -4,6 +4,9 @@ #include "mojo/services/native_viewport/native_viewport_android.h" +#include <android/native_window_jni.h> +#include "gpu/command_buffer/client/gl_in_process_context.h" +#include "gpu/command_buffer/client/gles2_implementation.h" #include "mojo/services/native_viewport/android/mojo_viewport.h" #include "mojo/shell/context.h" @@ -12,10 +15,47 @@ namespace services { NativeViewportAndroid::NativeViewportAndroid(NativeViewportDelegate* delegate) : delegate_(delegate), + window_(NULL), weak_factory_(this) { } NativeViewportAndroid::~NativeViewportAndroid() { + if (window_) + ReleaseWindow(); +} + +void NativeViewportAndroid::OnNativeWindowCreated(ANativeWindow* window) { + DCHECK(!window_); + window_ = window; + + gpu::GLInProcessContextAttribs attribs; + gl_context_.reset(gpu::GLInProcessContext::CreateContext( + false, window_, size_, false, attribs, gfx::PreferDiscreteGpu)); + gl_context_->SetContextLostCallback(base::Bind( + &NativeViewportAndroid::OnGLContextLost, base::Unretained(this))); + + delegate_->OnGLContextAvailable(gl_context_->GetImplementation()); +} + +void NativeViewportAndroid::OnGLContextLost() { + gl_context_.reset(); + delegate_->OnGLContextLost(); +} + +void NativeViewportAndroid::OnNativeWindowDestroyed() { + DCHECK(window_); + ReleaseWindow(); +} + +void NativeViewportAndroid::OnResized(const gfx::Size& size) { + size_ = size; + delegate_->OnResized(size); +} + +void NativeViewportAndroid::ReleaseWindow() { + gl_context_.reset(); + ANativeWindow_release(window_); + window_ = NULL; } void NativeViewportAndroid::Close() { diff --git a/mojo/services/native_viewport/native_viewport_android.h b/mojo/services/native_viewport/native_viewport_android.h index a593de5..f1600cb 100644 --- a/mojo/services/native_viewport/native_viewport_android.h +++ b/mojo/services/native_viewport/native_viewport_android.h @@ -7,6 +7,13 @@ #include "base/memory/weak_ptr.h" #include "mojo/services/native_viewport/native_viewport.h" +#include "ui/gfx/size.h" + +namespace gpu { +class GLInProcessContext; +} + +struct ANativeWindow; namespace mojo { namespace services { @@ -20,11 +27,21 @@ class NativeViewportAndroid : public NativeViewport { return weak_factory_.GetWeakPtr(); } + void OnNativeWindowCreated(ANativeWindow* window); + void OnNativeWindowDestroyed(); + void OnResized(const gfx::Size& size); + private: // Overridden from NativeViewport: virtual void Close() OVERRIDE; + void OnGLContextLost(); + void ReleaseWindow(); + NativeViewportDelegate* delegate_; + ANativeWindow* window_; + gfx::Size size_; + scoped_ptr<gpu::GLInProcessContext> gl_context_; base::WeakPtrFactory<NativeViewportAndroid> weak_factory_; diff --git a/mojo/services/native_viewport/native_viewport_controller.cc b/mojo/services/native_viewport/native_viewport_controller.cc index 6fe515c..e234fab 100644 --- a/mojo/services/native_viewport/native_viewport_controller.cc +++ b/mojo/services/native_viewport/native_viewport_controller.cc @@ -6,6 +6,7 @@ #include "base/message_loop/message_loop.h" #include "base/strings/stringprintf.h" +#include "gpu/command_buffer/client/gles2_interface.h" #include "mojo/services/native_viewport/native_viewport.h" #include "ui/events/event.h" @@ -33,6 +34,19 @@ bool NativeViewportController::OnEvent(ui::Event* event) { return false; } +void NativeViewportController::OnGLContextAvailable( + gpu::gles2::GLES2Interface* gl) { + // TODO(abarth): Instead of drawing green, we want to send the context over + // pipe_ somehow. + gl->ClearColor(0, 1, 0, 0); + gl->Clear(GL_COLOR_BUFFER_BIT); + gl->SwapBuffers(); +} + +void NativeViewportController::OnGLContextLost() { + SendString("GL context lost"); +} + void NativeViewportController::OnResized(const gfx::Size& size) { SendString(base::StringPrintf("Sized to: %d x %d", size.width(), diff --git a/mojo/services/native_viewport/native_viewport_controller.h b/mojo/services/native_viewport/native_viewport_controller.h index 797b073..926d42f 100644 --- a/mojo/services/native_viewport/native_viewport_controller.h +++ b/mojo/services/native_viewport/native_viewport_controller.h @@ -27,8 +27,10 @@ class NativeViewportController : public services::NativeViewportDelegate { private: // Overridden from services::NativeViewportDelegate: virtual bool OnEvent(ui::Event* event) OVERRIDE; - virtual void OnResized(const gfx::Size& size) OVERRIDE; virtual void OnDestroyed() OVERRIDE; + virtual void OnGLContextAvailable(gpu::gles2::GLES2Interface*) OVERRIDE; + virtual void OnGLContextLost() OVERRIDE; + virtual void OnResized(const gfx::Size& size) OVERRIDE; void SendString(const std::string& string); |