Skip to content

Commit

Permalink
Merge pull request flutter#896 from jamesr/gpu_bindings
Browse files Browse the repository at this point in the history
Use C bindings to Mojo GL entry points exclusively
  • Loading branch information
jamesr committed Aug 27, 2015
2 parents d866471 + 8b4bdd2 commit 790e5c2
Show file tree
Hide file tree
Showing 11 changed files with 214 additions and 66 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

vars = {
'chromium_git': 'https://chromium.googlesource.com',
'mojo_sdk_revision': 'eb7dac2f90187db12c0d29792a0bd999bc96cbe5',
'mojo_sdk_revision': 'f9c33d6eb1106c0f9edbbfb607da94fb76245238',
'mojo_devtools_revision': '2feda37728d3e551ef543b8f6c4f4b20eaa2d81f',
'skia_revision': '6904d1d3f1a2903fcaa4c4bd17b07d5f10af2e8e',
'dart_revision': 'cab003366785773ace16b5305ac1f33c228cac54',
Expand Down
6 changes: 0 additions & 6 deletions mojo/gpu/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ source_set("gpu") {
"gl_context_owner.h",
"gl_texture.cc",
"gl_texture.h",
"mojo_context_support.cc",
"mojo_context_support.h",
"mojo_gles2_impl_autogen.cc",
"mojo_gles2_impl_autogen.h",
"texture_cache.cc",
"texture_cache.h",
"texture_uploader.cc",
Expand All @@ -24,8 +20,6 @@ source_set("gpu") {

deps = [
"//base",
"//gpu/command_buffer/client:gles2_interface",
"//gpu/command_buffer/common",
"//mojo/environment:chromium",
"//mojo/public/c/gles2",
"//mojo/public/c/gpu",
Expand Down
18 changes: 9 additions & 9 deletions mojo/gpu/gl_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "mojo/public/cpp/application/connect.h"
#include "mojo/public/interfaces/application/shell.mojom.h"
#include "mojo/services/gpu/public/interfaces/gpu.mojom.h"
#include "mojo/gpu/mojo_gles2_impl_autogen.h"

namespace mojo {

Expand All @@ -22,30 +21,31 @@ GLContext::GLContext(Shell* shell) : weak_factory_(this) {
ConnectToService(native_viewport.get(), &gpu_service);
CommandBufferPtr command_buffer;
gpu_service->CreateOffscreenGLES2Context(GetProxy(&command_buffer));
context_ = MojoGLES2CreateContext(
context_ = MGLCreateContext(MGL_API_VERSION_GLES2,
command_buffer.PassInterface().PassHandle().release().value(),
MGL_NO_CONTEXT,
&ContextLostThunk, this, Environment::GetDefaultAsyncWaiter());
gl_impl_.reset(new MojoGLES2Impl(context_));
DCHECK(context_ != MGL_NO_CONTEXT);
}

GLContext::~GLContext() {
MojoGLES2DestroyContext(context_);
MGLDestroyContext(context_);
}

base::WeakPtr<GLContext> GLContext::Create(Shell* shell) {
return (new GLContext(shell))->weak_factory_.GetWeakPtr();
}

void GLContext::MakeCurrent() {
MojoGLES2MakeCurrent(context_);
MGLMakeCurrent(context_);
}

void GLContext::Destroy() {
delete this;
bool GLContext::IsCurrent() {
return context_ == MGLGetCurrentContext();
}

gpu::gles2::GLES2Interface* GLContext::gl() const {
return gl_impl_.get();
void GLContext::Destroy() {
delete this;
}

void GLContext::AddObserver(Observer* observer) {
Expand Down
15 changes: 3 additions & 12 deletions mojo/gpu/gl_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,9 @@
#include "base/basictypes.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "mojo/public/c/gles2/gles2.h"

namespace gpu {
namespace gles2 {
class GLES2Interface;
}
}
#include "mojo/public/c/gpu/MGL/mgl.h"

namespace mojo {
class MojoGLES2Impl;
class Shell;

class GLContext {
Expand All @@ -33,10 +26,9 @@ class GLContext {
static base::WeakPtr<GLContext> Create(Shell* shell);

void MakeCurrent();
bool IsCurrent();
void Destroy();

gpu::gles2::GLES2Interface* gl() const;

void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);

Expand All @@ -47,8 +39,7 @@ class GLContext {
static void ContextLostThunk(void* self);
void OnContextLost();

MojoGLES2Context context_;
scoped_ptr<MojoGLES2Impl> gl_impl_;
MGLContext context_;

base::ObserverList<Observer> observers_;
base::WeakPtrFactory<GLContext> weak_factory_;
Expand Down
17 changes: 14 additions & 3 deletions mojo/skia/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

static_library("skia") {
source_set("skia") {
sources = [
"ganesh_context.cc",
"ganesh_context.h",
Expand All @@ -11,10 +11,21 @@ static_library("skia") {
]

deps = [
":skia_bindings",
"//base",
"//gpu/command_buffer/client:gles2_c_lib",
"//gpu/skia_bindings",
"//mojo/gpu",
"//mojo/public/c/gpu",
"//skia",
]
}

source_set("skia_bindings") {
sources = [
"gl_bindings_skia.cc",
"gl_bindings_skia.h",
]
deps = [
"//mojo/public/c/gpu",
"//skia",
]
}
26 changes: 7 additions & 19 deletions mojo/skia/ganesh_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#include "mojo/skia/ganesh_context.h"

#include "gpu/command_buffer/client/gles2_lib.h"
#include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h"
#include "mojo/public/c/gpu/MGL/mgl.h"
#include "mojo/skia/gl_bindings_skia.h"
#include "third_party/skia/include/gpu/gl/GrGLInterface.h"

namespace mojo {
Expand All @@ -19,37 +19,25 @@ const int kMaxGaneshResourceCacheCount = 2048;
// GPU cache.
const size_t kMaxGaneshResourceCacheBytes = 96 * 1024 * 1024;

void EnsureInitialized() {
static bool initialized;
if (initialized)
return;
gles2::Initialize();
initialized = true;
}
}

GaneshContext::Scope::Scope(GaneshContext* context)
: previous_(gles2::GetGLContext()) {
auto gl = context->gl_context_->gl();
DCHECK(gl);
gles2::SetGLContext(gl);
DCHECK(gles2::GetGLContext());
: previous_(MGLGetCurrentContext()) {
context->gl_context_->MakeCurrent();
}

GaneshContext::Scope::~Scope() {
gles2::SetGLContext(previous_);
MGLMakeCurrent(previous_);
}

GaneshContext::GaneshContext(base::WeakPtr<GLContext> gl_context)
: gl_context_(gl_context) {
EnsureInitialized();

DCHECK(gl_context_);
gl_context_->AddObserver(this);
Scope scope(this);

skia::RefPtr<GrGLInterface> interface =
skia::AdoptRef(skia_bindings::CreateCommandBufferSkiaGLBinding());
skia::AdoptRef(skia_bindings::CreateMojoSkiaGLBinding());
DCHECK(interface);

context_ = skia::AdoptRef(GrContext::Create(
Expand All @@ -69,7 +57,7 @@ GaneshContext::~GaneshContext() {
}

bool GaneshContext::InScope() const {
return gles2::GetGLContext() == gl_context_->gl();
return gl_context_->IsCurrent();
}

void GaneshContext::OnContextLost() {
Expand Down
12 changes: 3 additions & 9 deletions mojo/skia/ganesh_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,23 @@
#include "skia/ext/refptr.h"
#include "third_party/skia/include/gpu/GrContext.h"

namespace gpu {
namespace gles2 {
class GLES2Interface;
}
}

namespace mojo {

class GaneshContext : public GLContext::Observer {
public:
class Scope {
public:
explicit Scope(GaneshContext*);
explicit Scope(GaneshContext* context);
~Scope();

private:
gpu::gles2::GLES2Interface* previous_;
MGLContext previous_;
};

explicit GaneshContext(base::WeakPtr<GLContext> gl_context);
~GaneshContext() override;

// Note: You must be in a GaneshContext::Scope to use GrContext.
void MakeCurrent();
GrContext* gr() const {
DCHECK(InScope());
return context_.get();
Expand Down
152 changes: 152 additions & 0 deletions mojo/skia/gl_bindings_skia.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "mojo/skia/gl_bindings_skia.h"

#ifndef GL_GLEXT_PROTOTYPES
#define GL_GLEXT_PROTOTYPES
#endif
#include "mojo/public/c/gpu/GLES2/gl2.h"
#include "mojo/public/c/gpu/GLES2/gl2ext.h"
#include "mojo/public/c/gpu/GLES2/gl2extmojo.h"
#include "third_party/skia/include/gpu/gl/GrGLInterface.h"

namespace skia_bindings {

GrGLInterface* CreateMojoSkiaGLBinding() {
GrGLInterface* interface = new GrGLInterface;
interface->fStandard = kGLES_GrGLStandard;
interface->fExtensions.init(kGLES_GrGLStandard,
glGetString,
nullptr,
glGetIntegerv);

GrGLInterface::Functions* functions = &interface->fFunctions;
functions->fActiveTexture = glActiveTexture;
functions->fAttachShader = glAttachShader;
functions->fBindAttribLocation = glBindAttribLocation;
functions->fBindBuffer = glBindBuffer;
functions->fBindTexture = glBindTexture;
functions->fBindVertexArray = glBindVertexArrayOES;
functions->fBlendEquation = glBlendEquation;
functions->fBlendBarrier = glBlendBarrierKHR;
functions->fBlendColor = glBlendColor;
functions->fBlendFunc = glBlendFunc;
functions->fBufferData = glBufferData;
functions->fBufferSubData = glBufferSubData;
functions->fClear = glClear;
functions->fClearColor = glClearColor;
functions->fClearStencil = glClearStencil;
functions->fColorMask = glColorMask;
functions->fCompileShader = glCompileShader;
functions->fCompressedTexImage2D = glCompressedTexImage2D;
functions->fCopyTexSubImage2D = glCopyTexSubImage2D;
functions->fCreateProgram = glCreateProgram;
functions->fCreateShader = glCreateShader;
functions->fCullFace = glCullFace;
functions->fDeleteBuffers = glDeleteBuffers;
functions->fDeleteProgram = glDeleteProgram;
functions->fDeleteShader = glDeleteShader;
functions->fDeleteTextures = glDeleteTextures;
functions->fDeleteVertexArrays = glDeleteVertexArraysOES;
functions->fDepthMask = glDepthMask;
functions->fDisable = glDisable;
functions->fDisableVertexAttribArray = glDisableVertexAttribArray;
functions->fDiscardFramebuffer = glDiscardFramebufferEXT;
functions->fDrawArrays = glDrawArrays;
functions->fDrawElements = glDrawElements;
functions->fEnable = glEnable;
functions->fEnableVertexAttribArray = glEnableVertexAttribArray;
functions->fFinish = glFinish;
functions->fFlush = glFlush;
functions->fFrontFace = glFrontFace;
functions->fGenBuffers = glGenBuffers;
functions->fGenTextures = glGenTextures;
functions->fGenVertexArrays = glGenVertexArraysOES;
functions->fGetBufferParameteriv = glGetBufferParameteriv;
functions->fGetError = glGetError;
functions->fGetIntegerv = glGetIntegerv;
functions->fGetProgramInfoLog = glGetProgramInfoLog;
functions->fGetProgramiv = glGetProgramiv;
functions->fGetShaderInfoLog = glGetShaderInfoLog;
functions->fGetShaderiv = glGetShaderiv;
functions->fGetShaderPrecisionFormat = glGetShaderPrecisionFormat;
functions->fGetString = glGetString;
functions->fGetUniformLocation = glGetUniformLocation;
functions->fInsertEventMarker = glInsertEventMarkerEXT;
functions->fLineWidth = glLineWidth;
functions->fLinkProgram = glLinkProgram;
functions->fMapBufferSubData = glMapBufferSubDataCHROMIUM;
functions->fMapTexSubImage2D = glMapTexSubImage2DCHROMIUM;
functions->fPixelStorei = glPixelStorei;
functions->fPopGroupMarker = glPopGroupMarkerEXT;
functions->fPushGroupMarker = glPushGroupMarkerEXT;
functions->fReadPixels = glReadPixels;
functions->fScissor = glScissor;
functions->fShaderSource = glShaderSource;
functions->fStencilFunc = glStencilFunc;
functions->fStencilFuncSeparate = glStencilFuncSeparate;
functions->fStencilMask = glStencilMask;
functions->fStencilMaskSeparate = glStencilMaskSeparate;
functions->fStencilOp = glStencilOp;
functions->fStencilOpSeparate = glStencilOpSeparate;
functions->fTexImage2D = glTexImage2D;
functions->fTexParameteri = glTexParameteri;
functions->fTexParameteriv = glTexParameteriv;
functions->fTexStorage2D = glTexStorage2DEXT;
functions->fTexSubImage2D = glTexSubImage2D;
functions->fUniform1f = glUniform1f;
functions->fUniform1i = glUniform1i;
functions->fUniform1fv = glUniform1fv;
functions->fUniform1iv = glUniform1iv;
functions->fUniform2f = glUniform2f;
functions->fUniform2i = glUniform2i;
functions->fUniform2fv = glUniform2fv;
functions->fUniform2iv = glUniform2iv;
functions->fUniform3f = glUniform3f;
functions->fUniform3i = glUniform3i;
functions->fUniform3fv = glUniform3fv;
functions->fUniform3iv = glUniform3iv;
functions->fUniform4f = glUniform4f;
functions->fUniform4i = glUniform4i;
functions->fUniform4fv = glUniform4fv;
functions->fUniform4iv = glUniform4iv;
functions->fUniformMatrix2fv = glUniformMatrix2fv;
functions->fUniformMatrix3fv = glUniformMatrix3fv;
functions->fUniformMatrix4fv = glUniformMatrix4fv;
functions->fUnmapBufferSubData = glUnmapBufferSubDataCHROMIUM;
functions->fUnmapTexSubImage2D = glUnmapTexSubImage2DCHROMIUM;
functions->fUseProgram = glUseProgram;
functions->fVertexAttrib1f = glVertexAttrib1f;
functions->fVertexAttrib2fv = glVertexAttrib2fv;
functions->fVertexAttrib3fv = glVertexAttrib3fv;
functions->fVertexAttrib4fv = glVertexAttrib4fv;
functions->fVertexAttribPointer = glVertexAttribPointer;
functions->fViewport = glViewport;
functions->fBindFramebuffer = glBindFramebuffer;
functions->fBindRenderbuffer = glBindRenderbuffer;
functions->fCheckFramebufferStatus = glCheckFramebufferStatus;
functions->fDeleteFramebuffers = glDeleteFramebuffers;
functions->fDeleteRenderbuffers = glDeleteRenderbuffers;
functions->fFramebufferRenderbuffer = glFramebufferRenderbuffer;
functions->fFramebufferTexture2D = glFramebufferTexture2D;
functions->fFramebufferTexture2DMultisample =
glFramebufferTexture2DMultisampleEXT;
functions->fGenFramebuffers = glGenFramebuffers;
functions->fGenRenderbuffers = glGenRenderbuffers;
functions->fGetFramebufferAttachmentParameteriv =
glGetFramebufferAttachmentParameteriv;
functions->fGetRenderbufferParameteriv = glGetRenderbufferParameteriv;
functions->fRenderbufferStorage = glRenderbufferStorage;
functions->fRenderbufferStorageMultisample = nullptr; // TODO: Implement.
functions->fRenderbufferStorageMultisampleES2EXT =
glRenderbufferStorageMultisampleEXT;
functions->fBindUniformLocation = glBindUniformLocationCHROMIUM;
functions->fBlitFramebuffer = nullptr; // TODO: Implement.
functions->fGenerateMipmap = glGenerateMipmap;

return interface;
}

} // namespace skia
Loading

0 comments on commit 790e5c2

Please sign in to comment.