aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu
diff options
context:
space:
mode:
authorGravatar kkinnunen <kkinnunen@nvidia.com>2014-06-30 06:36:31 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-06-30 06:36:31 -0700
commit80549fcdd50269d7e069d6db02b395fca128056c (patch)
treef190d563157d1e5e41f26e0bc1cf724b17a7f3c4 /src/gpu
parentb8562be65510ea2703e1e34029da8c8f501c340c (diff)
Support using OpenGL ES context on desktop
Support using OpenGL ES context on desktop for unix and Android platforms. This is mainly useful in development. Add --gpuAPI flag to gm, dm, bench, bench_pictures and render_pictures. The possible parameters for the flag are "gl" and "gles". R=bsalomon@google.com, mtklein@google.com, robertphillips@google.com Author: kkinnunen@nvidia.com Review URL: https://codereview.chromium.org/319043005
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/gl/GrGLAssembleGLESInterface.h256
-rw-r--r--src/gpu/gl/SkGLContextHelper.cpp5
-rw-r--r--src/gpu/gl/SkNullGLContext.cpp5
-rw-r--r--src/gpu/gl/android/GrGLCreateNativeInterface_android.cpp245
-rw-r--r--src/gpu/gl/android/SkNativeGLContext_android.cpp13
-rw-r--r--src/gpu/gl/angle/SkANGLEGLContext.cpp5
-rw-r--r--src/gpu/gl/debug/SkDebugGLContext.cpp6
-rw-r--r--src/gpu/gl/iOS/SkNativeGLContext_iOS.mm8
-rw-r--r--src/gpu/gl/mac/SkNativeGLContext_mac.cpp5
-rw-r--r--src/gpu/gl/mesa/SkMesaGLContext.cpp6
-rw-r--r--src/gpu/gl/nacl/SkNativeGLContext_nacl.cpp2
-rw-r--r--src/gpu/gl/unix/GrGLCreateNativeInterface_unix.cpp21
-rw-r--r--src/gpu/gl/unix/SkNativeGLContext_unix.cpp86
-rw-r--r--src/gpu/gl/win/GrGLCreateNativeInterface_win.cpp22
-rw-r--r--src/gpu/gl/win/SkNativeGLContext_win.cpp10
15 files changed, 402 insertions, 293 deletions
diff --git a/src/gpu/gl/GrGLAssembleGLESInterface.h b/src/gpu/gl/GrGLAssembleGLESInterface.h
new file mode 100644
index 0000000000..30602c12d5
--- /dev/null
+++ b/src/gpu/gl/GrGLAssembleGLESInterface.h
@@ -0,0 +1,256 @@
+
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* This file is meant to be included "inline" the implementation that is using the function.
+ * The platform native GL implementation header file should be included before this file.
+ * Following macros should be defined before this file is included:
+ * GET_PROC and GET_PROC_SUFFIX
+ * Call the get function and assign to the interface instance
+ * GET_PROC_LOCAL
+ * Call the get function and assign to a local variable
+ * GET_LINKED and GET_LINKED_SUFFIX
+ * Get the link-time address of the function and assign it to the interface instance. If
+ * using the linked addresses is not intended, can be the same as GET_PROC.
+ */
+
+/**
+ * Generic function for creating a GrGLInterface for an OpenGL ES (but not Open GL) context. It
+ * calls get() to get each function address. ctx is a generic ptr passed to and interpreted by
+ * get().
+ */
+static const GrGLInterface* GrGLAssembleGLESInterface(void* ctx, GrGLGetProc get) {
+ const char* verStr = reinterpret_cast<const char*>(glGetString(GR_GL_VERSION));
+ GrGLVersion version = GrGLGetVersionFromString(verStr);
+
+ if (version < GR_GL_VER(2,0)) {
+ return NULL;
+ }
+
+ GET_PROC_LOCAL(GetIntegerv);
+ GET_PROC_LOCAL(GetStringi);
+ GrGLExtensions extensions;
+ if (!extensions.init(kGLES_GrGLStandard, glGetString, GetStringi, GetIntegerv)) {
+ return NULL;
+ }
+
+ GrGLInterface* interface = SkNEW(GrGLInterface);
+ GrGLInterface::Functions* functions = &interface->fFunctions;
+
+ GET_LINKED(ActiveTexture);
+ GET_LINKED(AttachShader);
+ GET_LINKED(BindAttribLocation);
+ GET_LINKED(BindBuffer);
+ GET_LINKED(BindTexture);
+ GET_LINKED_SUFFIX(BindVertexArray, OES);
+ GET_LINKED(BlendColor);
+ GET_LINKED(BlendFunc);
+ GET_LINKED(BufferData);
+ GET_LINKED(BufferSubData);
+ GET_LINKED(Clear);
+ GET_LINKED(ClearColor);
+ GET_LINKED(ClearStencil);
+ GET_LINKED(ColorMask);
+ GET_LINKED(CompileShader);
+ GET_LINKED(CompressedTexImage2D);
+ GET_LINKED(CompressedTexSubImage2D);
+ GET_LINKED(CopyTexSubImage2D);
+ GET_LINKED(CreateProgram);
+ GET_LINKED(CreateShader);
+ GET_LINKED(CullFace);
+ GET_LINKED(DeleteBuffers);
+ GET_LINKED(DeleteProgram);
+ GET_LINKED(DeleteShader);
+ GET_LINKED(DeleteTextures);
+ GET_LINKED_SUFFIX(DeleteVertexArrays, OES);
+ GET_LINKED(DepthMask);
+ GET_LINKED(Disable);
+ GET_LINKED(DisableVertexAttribArray);
+ GET_LINKED(DrawArrays);
+ GET_LINKED(DrawElements);
+ GET_LINKED(Enable);
+ GET_LINKED(EnableVertexAttribArray);
+ GET_LINKED(Finish);
+ GET_LINKED(Flush);
+ GET_LINKED(FrontFace);
+ GET_LINKED(GenBuffers);
+ GET_LINKED(GenerateMipmap);
+ GET_LINKED(GenTextures);
+ GET_LINKED_SUFFIX(GenVertexArrays, OES);
+ GET_LINKED(GetBufferParameteriv);
+ GET_LINKED(GetError);
+ GET_LINKED(GetIntegerv);
+ GET_LINKED(GetProgramInfoLog);
+ GET_LINKED(GetProgramiv);
+ GET_LINKED(GetShaderInfoLog);
+ GET_LINKED(GetShaderiv);
+ GET_LINKED(GetString);
+#if GL_ES_VERSION_3_0
+ GET_LINKED(GetStringi);
+#else
+ GET_PROC(GetStringi);
+#endif
+ GET_LINKED(GetUniformLocation);
+ GET_LINKED(LineWidth);
+ GET_LINKED(LinkProgram);
+ GET_LINKED(PixelStorei);
+ GET_LINKED(ReadPixels);
+ GET_LINKED(Scissor);
+#if GR_GL_USE_NEW_SHADER_SOURCE_SIGNATURE
+ functions->fShaderSource = (GrGLShaderSourceProc) glShaderSource;
+#else
+ GET_LINKED(ShaderSource);
+#endif
+ GET_LINKED(StencilFunc);
+ GET_LINKED(StencilFuncSeparate);
+ GET_LINKED(StencilMask);
+ GET_LINKED(StencilMaskSeparate);
+ GET_LINKED(StencilOp);
+ GET_LINKED(StencilOpSeparate);
+ GET_LINKED(TexImage2D);
+ GET_LINKED(TexParameteri);
+ GET_LINKED(TexParameteriv);
+ GET_LINKED(TexSubImage2D);
+
+ if (version >= GR_GL_VER(3,0)) {
+#if GL_ES_VERSION_3_0
+ GET_LINKED(TexStorage2D);
+#else
+ GET_PROC(TexStorage2D);
+#endif
+ } else {
+#if GL_EXT_texture_storage
+ GET_LINKED_SUFFIX(TexStorage2D, EXT);
+#else
+ GET_PROC_SUFFIX(TexStorage2D, EXT);
+#endif
+ }
+
+#if GL_EXT_discard_framebuffer
+ GET_LINKED_SUFFIX(DiscardFramebuffer, EXT);
+#endif
+ GET_LINKED(Uniform1f);
+ GET_LINKED(Uniform1i);
+ GET_LINKED(Uniform1fv);
+ GET_LINKED(Uniform1iv);
+ GET_LINKED(Uniform2f);
+ GET_LINKED(Uniform2i);
+ GET_LINKED(Uniform2fv);
+ GET_LINKED(Uniform2iv);
+ GET_LINKED(Uniform3f);
+ GET_LINKED(Uniform3i);
+ GET_LINKED(Uniform3fv);
+ GET_LINKED(Uniform3iv);
+ GET_LINKED(Uniform4f);
+ GET_LINKED(Uniform4i);
+ GET_LINKED(Uniform4fv);
+ GET_LINKED(Uniform4iv);
+ GET_LINKED(UniformMatrix2fv);
+ GET_LINKED(UniformMatrix3fv);
+ GET_LINKED(UniformMatrix4fv);
+ GET_LINKED(UseProgram);
+ GET_LINKED(VertexAttrib4fv);
+ GET_LINKED(VertexAttribPointer);
+ GET_LINKED(Viewport);
+ GET_LINKED(BindFramebuffer);
+ GET_LINKED(BindRenderbuffer);
+ GET_LINKED(CheckFramebufferStatus);
+ GET_LINKED(DeleteFramebuffers);
+ GET_LINKED(DeleteRenderbuffers);
+ GET_LINKED(FramebufferRenderbuffer);
+ GET_LINKED(FramebufferTexture2D);
+
+ if (version >= GR_GL_VER(3,0)) {
+#if GL_ES_VERSION_3_0
+ GET_LINKED(RenderbufferStorageMultisample);
+ GET_LINKED(BlitFramebuffer);
+#else
+ GET_PROC(RenderbufferStorageMultisample);
+ GET_PROC(BlitFramebuffer);
+#endif
+ }
+
+ if (extensions.has("GL_EXT_multisampled_render_to_texture")) {
+#if GL_EXT_multisampled_render_to_texture
+ GET_LINKED_SUFFIX(FramebufferTexture2DMultisample, EXT);
+ functions->fRenderbufferStorageMultisampleES2EXT = glRenderbufferStorageMultisampleEXT;
+#else
+ GET_PROC_SUFFIX(FramebufferTexture2DMultisample, EXT);
+ functions->fRenderbufferStorageMultisampleES2EXT = (GrGLRenderbufferStorageMultisampleProc) get(ctx, "glRenderbufferStorageMultisampleEXT");
+#endif
+ } else if (extensions.has("GL_IMG_multisampled_render_to_texture")) {
+#if GL_IMG_multisampled_render_to_texture
+ GET_LINKED_SUFFIX(FramebufferTexture2DMultisample, IMG);
+ functions->fRenderbufferStorageMultisampleES2EXT = glRenderbufferStorageMultisampleIMG;
+#else
+ GET_PROC_SUFFIX(FramebufferTexture2DMultisample, IMG);
+ functions->fRenderbufferStorageMultisampleES2EXT = (GrGLRenderbufferStorageMultisampleProc) get(ctx, "glRenderbufferStorageMultisampleIMG");
+#endif
+ }
+
+ GET_LINKED(GenFramebuffers);
+ GET_LINKED(GenRenderbuffers);
+ GET_LINKED(GetFramebufferAttachmentParameteriv);
+ GET_LINKED(GetRenderbufferParameteriv);
+ GET_LINKED(RenderbufferStorage);
+
+#if GL_OES_mapbuffer
+ GET_LINKED_SUFFIX(MapBuffer, OES);
+ GET_LINKED_SUFFIX(UnmapBuffer, OES);
+#else
+ GET_PROC_SUFFIX(MapBuffer, OES);
+ GET_PROC_SUFFIX(UnmapBuffer, OES);
+#endif
+
+ if (version >= GR_GL_VER(3,0)) {
+#if GL_ES_VERSION_3_0
+ GET_LINKED(MapBufferRange);
+ GET_LINKED(FlushMappedBufferRange);
+#else
+ GET_PROC(MapBufferRange);
+ GET_PROC(FlushMappedBufferRange);
+#endif
+ } else if (extensions.has("GL_EXT_map_buffer_range")) {
+#if GL_EXT_map_buffer_range
+ GET_LINKED_SUFFIX(MapBufferRange, EXT);
+ GET_LINKED_SUFFIX(FlushMappedBufferRange, EXT);
+#else
+ GET_PROC_SUFFIX(MapBufferRange, EXT);
+ GET_PROC_SUFFIX(FlushMappedBufferRange, EXT);
+#endif
+ }
+
+ if (extensions.has("GL_EXT_debug_marker")) {
+ GET_PROC(InsertEventMarker);
+ GET_PROC(PushGroupMarker);
+ GET_PROC(PopGroupMarker);
+ // The below check is here because a device has been found that has the extension string but
+ // returns NULL from the eglGetProcAddress for the functions
+ if (NULL == functions->fInsertEventMarker ||
+ NULL == functions->fPushGroupMarker ||
+ NULL == functions->fPopGroupMarker) {
+ extensions.remove("GL_EXT_debug_marker");
+ }
+ }
+
+#if GL_ES_VERSION_3_0
+ GET_LINKED(InvalidateFramebuffer);
+ GET_LINKED(InvalidateSubFramebuffer);
+#else
+ GET_PROC(InvalidateFramebuffer);
+ GET_PROC(InvalidateSubFramebuffer);
+#endif
+ GET_PROC(InvalidateBufferData);
+ GET_PROC(InvalidateBufferSubData);
+ GET_PROC(InvalidateTexImage);
+ GET_PROC(InvalidateTexSubImage);
+
+ interface->fStandard = kGLES_GrGLStandard;
+ interface->fExtensions.swap(&extensions);
+
+ return interface;
+}
diff --git a/src/gpu/gl/SkGLContextHelper.cpp b/src/gpu/gl/SkGLContextHelper.cpp
index b06f755f67..2381a84519 100644
--- a/src/gpu/gl/SkGLContextHelper.cpp
+++ b/src/gpu/gl/SkGLContextHelper.cpp
@@ -27,13 +27,14 @@ SkGLContextHelper::~SkGLContextHelper() {
SkSafeUnref(fGL);
}
-bool SkGLContextHelper::init(int width, int height) {
+bool SkGLContextHelper::init(GrGLStandard forcedGpuAPI, int width,
+ int height) {
if (fGL) {
fGL->unref();
this->destroyGLContext();
}
- fGL = this->createGLContext();
+ fGL = this->createGLContext(forcedGpuAPI);
if (fGL) {
const GrGLubyte* temp;
diff --git a/src/gpu/gl/SkNullGLContext.cpp b/src/gpu/gl/SkNullGLContext.cpp
index 86c09b2045..576ee526f1 100644
--- a/src/gpu/gl/SkNullGLContext.cpp
+++ b/src/gpu/gl/SkNullGLContext.cpp
@@ -8,6 +8,9 @@
#include "gl/SkNullGLContext.h"
-const GrGLInterface* SkNullGLContext::createGLContext() {
+const GrGLInterface* SkNullGLContext::createGLContext(GrGLStandard forcedGpuAPI) {
+ if (kGLES_GrGLStandard == forcedGpuAPI) {
+ return NULL;
+ }
return GrGLCreateNullInterface();
};
diff --git a/src/gpu/gl/android/GrGLCreateNativeInterface_android.cpp b/src/gpu/gl/android/GrGLCreateNativeInterface_android.cpp
index 781e29bc9d..df212b1995 100644
--- a/src/gpu/gl/android/GrGLCreateNativeInterface_android.cpp
+++ b/src/gpu/gl/android/GrGLCreateNativeInterface_android.cpp
@@ -18,258 +18,29 @@
#include <EGL/egl.h>
-static GrGLInterface* create_es_interface(GrGLVersion version,
- GrGLExtensions* extensions) {
- if (version < GR_GL_VER(2,0)) {
- return NULL;
- }
-
- GrGLInterface* interface = SkNEW(GrGLInterface);
- interface->fStandard = kGLES_GrGLStandard;
- GrGLInterface::Functions* functions = &interface->fFunctions;
-
- functions->fActiveTexture = glActiveTexture;
- functions->fAttachShader = glAttachShader;
- functions->fBindAttribLocation = glBindAttribLocation;
- functions->fBindBuffer = glBindBuffer;
- functions->fBindTexture = glBindTexture;
- functions->fBindVertexArray = glBindVertexArrayOES;
- 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->fCompressedTexSubImage2D = glCompressedTexSubImage2D;
- 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->fDrawArrays = glDrawArrays;
- functions->fDrawElements = glDrawElements;
- functions->fEnable = glEnable;
- functions->fEnableVertexAttribArray = glEnableVertexAttribArray;
- functions->fFinish = glFinish;
- functions->fFlush = glFlush;
- functions->fFrontFace = glFrontFace;
- functions->fGenBuffers = glGenBuffers;
- functions->fGenerateMipmap = glGenerateMipmap;
- 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->fGetString = glGetString;
-#if GL_ES_VERSION_3_0
- functions->fGetStringi = glGetStringi;
-#else
- functions->fGetStringi = (GrGLGetStringiProc) eglGetProcAddress("glGetStringi");
-#endif
- functions->fGetUniformLocation = glGetUniformLocation;
- functions->fLineWidth = glLineWidth;
- functions->fLinkProgram = glLinkProgram;
- functions->fPixelStorei = glPixelStorei;
- functions->fReadPixels = glReadPixels;
- functions->fScissor = glScissor;
-#if GR_GL_USE_NEW_SHADER_SOURCE_SIGNATURE
- functions->fShaderSource = (GrGLShaderSourceProc) glShaderSource;
-#else
- functions->fShaderSource = glShaderSource;
-#endif
- 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->fTexSubImage2D = glTexSubImage2D;
-
- if (version >= GR_GL_VER(3,0)) {
-#if GL_ES_VERSION_3_0
- functions->fTexStorage2D = glTexStorage2D;
-#else
- functions->fTexStorage2D = (GrGLTexStorage2DProc) eglGetProcAddress("glTexStorage2D");
-#endif
- } else {
-#if GL_EXT_texture_storage
- functions->fTexStorage2D = glTexStorage2DEXT;
-#else
- functions->fTexStorage2D = (GrGLTexStorage2DProc) eglGetProcAddress("glTexStorage2DEXT");
-#endif
- }
-
-#if GL_EXT_discard_framebuffer
- functions->fDiscardFramebuffer = glDiscardFramebufferEXT;
-#endif
- 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->fUseProgram = glUseProgram;
- 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;
-
- if (version >= GR_GL_VER(3,0)) {
-#if GL_ES_VERSION_3_0
- functions->fRenderbufferStorageMultisample = glRenderbufferStorageMultisample;
- functions->fBlitFramebuffer = glBlitFramebuffer;
-#else
- functions->fRenderbufferStorageMultisample = (GrGLRenderbufferStorageMultisampleProc) eglGetProcAddress("glRenderbufferStorageMultisample");
- functions->fBlitFramebuffer = (GrGLBlitFramebufferProc) eglGetProcAddress("glBlitFramebuffer");
-#endif
- }
-
- if (extensions->has("GL_EXT_multisampled_render_to_texture")) {
-#if GL_EXT_multisampled_render_to_texture
- functions->fFramebufferTexture2DMultisample = glFramebufferTexture2DMultisampleEXT;
- functions->fRenderbufferStorageMultisampleES2EXT = glRenderbufferStorageMultisampleEXT;
-#else
- functions->fFramebufferTexture2DMultisample = (GrGLFramebufferTexture2DMultisampleProc) eglGetProcAddress("glFramebufferTexture2DMultisampleEXT");
- functions->fRenderbufferStorageMultisampleES2EXT = (GrGLRenderbufferStorageMultisampleProc) eglGetProcAddress("glRenderbufferStorageMultisampleEXT");
-#endif
- } else if (extensions->has("GL_IMG_multisampled_render_to_texture")) {
-#if GL_IMG_multisampled_render_to_texture
- functions->fFramebufferTexture2DMultisample = glFramebufferTexture2DMultisampleIMG;
- functions->fRenderbufferStorageMultisampleES2EXT = glRenderbufferStorageMultisampleIMG;
-#else
- functions->fFramebufferTexture2DMultisample = (GrGLFramebufferTexture2DMultisampleProc) eglGetProcAddress("glFramebufferTexture2DMultisampleIMG");
- functions->fRenderbufferStorageMultisampleES2EXT = (GrGLRenderbufferStorageMultisampleProc) eglGetProcAddress("glRenderbufferStorageMultisampleIMG");
-#endif
- }
-
- functions->fGenFramebuffers = glGenFramebuffers;
- functions->fGenRenderbuffers = glGenRenderbuffers;
- functions->fGetFramebufferAttachmentParameteriv = glGetFramebufferAttachmentParameteriv;
- functions->fGetRenderbufferParameteriv = glGetRenderbufferParameteriv;
- functions->fRenderbufferStorage = glRenderbufferStorage;
+#define GET_PROC(F) functions->f ## F = (GrGL ## F ## Proc) get(ctx, "gl" #F)
+#define GET_PROC_SUFFIX(F, S) functions->f ## F = (GrGL ## F ## Proc) get(ctx, "gl" #F #S)
+#define GET_PROC_LOCAL(F) GrGL ## F ## Proc F = (GrGL ## F ## Proc) get(ctx, "gl" #F)
-#if GL_OES_mapbuffer
- functions->fMapBuffer = glMapBufferOES;
- functions->fUnmapBuffer = glUnmapBufferOES;
-#else
- functions->fMapBuffer = (GrGLMapBufferProc) eglGetProcAddress("glMapBufferOES");
- functions->fUnmapBuffer = (GrGLUnmapBufferProc) eglGetProcAddress("glUnmapBufferOES");
+#define GET_LINKED(F) functions->f ## F = gl ## F
+#define GET_LINKED_SUFFIX(F, S) functions->f ## F = gl ## F ##S
-#endif
-
- if (version >= GR_GL_VER(3,0)) {
-#if GL_ES_VERSION_3_0
- functions->fMapBufferRange = glMapBufferRange;
- functions->fFlushMappedBufferRange = glFlushMappedBufferRange;
-#else
- functions->fMapBufferRange = (GrGLMapBufferRangeProc) eglGetProcAddress("glMapBufferRange");
- functions->fFlushMappedBufferRange = (GrGLFlushMappedBufferRangeProc) eglGetProcAddress("glFlushMappedBufferRange");
-#endif
- } else if (extensions->has("GL_EXT_map_buffer_range")) {
-#if GL_EXT_map_buffer_range
- functions->fMapBufferRange = glMapBufferRangeEXT;
- functions->fFlushMappedBufferRange = glFlushMappedBufferRangeEXT;
-#else
- functions->fMapBufferRange = (GrGLMapBufferRangeProc) eglGetProcAddress("glMapBufferRangeEXT");
- functions->fFlushMappedBufferRange = (GrGLFlushMappedBufferRangeProc) eglGetProcAddress("glFlushMappedBufferRangeEXT");
-#endif
- }
-
- if (extensions->has("GL_EXT_debug_marker")) {
- functions->fInsertEventMarker = (GrGLInsertEventMarkerProc) eglGetProcAddress("glInsertEventMarker");
- functions->fPushGroupMarker = (GrGLInsertEventMarkerProc) eglGetProcAddress("glPushGroupMarker");
- functions->fPopGroupMarker = (GrGLPopGroupMarkerProc) eglGetProcAddress("glPopGroupMarker");
- // The below check is here because a device has been found that has the extension string but
- // returns NULL from the eglGetProcAddress for the functions
- if (NULL == functions->fInsertEventMarker ||
- NULL == functions->fPushGroupMarker ||
- NULL == functions->fPopGroupMarker) {
- extensions->remove("GL_EXT_debug_marker");
- }
- }
-
-#if GL_ES_VERSION_3_0
- functions->fInvalidateFramebuffer = glInvalidateFramebuffer;
- functions->fInvalidateSubFramebuffer = glInvalidateSubFramebuffer;
-#else
- functions->fInvalidateFramebuffer = (GrGLInvalidateFramebufferProc) eglGetProcAddress("glInvalidateFramebuffer");
- functions->fInvalidateSubFramebuffer = (GrGLInvalidateSubFramebufferProc) eglGetProcAddress("glInvalidateSubFramebuffer");
-#endif
- functions->fInvalidateBufferData = (GrGLInvalidateBufferDataProc) eglGetProcAddress("glInvalidateBufferData");
- functions->fInvalidateBufferSubData = (GrGLInvalidateBufferSubDataProc) eglGetProcAddress("glInvalidateBufferSubData");
- functions->fInvalidateTexImage = (GrGLInvalidateTexImageProc) eglGetProcAddress("glInvalidateTexImage");
- functions->fInvalidateTexSubImage = (GrGLInvalidateTexSubImageProc) eglGetProcAddress("glInvalidateTexSubImage");
-
- return interface;
-}
+#include "gl/GrGLAssembleGLESInterface.h"
static GrGLFuncPtr android_get_gl_proc(void* ctx, const char name[]) {
SkASSERT(NULL == ctx);
return eglGetProcAddress(name);
}
-static const GrGLInterface* create_desktop_interface() {
- return GrGLAssembleGLInterface(NULL, android_get_gl_proc);
-}
-
const GrGLInterface* GrGLCreateNativeInterface() {
const char* verStr = reinterpret_cast<const char*>(glGetString(GR_GL_VERSION));
GrGLStandard standard = GrGLGetStandardInUseFromString(verStr);
if (kGLES_GrGLStandard == standard) {
- GrGLVersion version = GrGLGetVersionFromString(verStr);
- GrGLExtensions extensions;
- GrGLGetStringiProc getStringi = (GrGLGetStringiProc) eglGetProcAddress("glGetStringi");
- if (!extensions.init(standard, glGetString, getStringi, glGetIntegerv)) {
- return NULL;
- }
- GrGLInterface* interface = create_es_interface(version, &extensions);
-
- if (NULL != interface) {
- interface->fExtensions.swap(&extensions);
- }
-
- return interface;
+ return GrGLAssembleGLESInterface(NULL, android_get_gl_proc);
} else if (kGL_GrGLStandard == standard) {
- return create_desktop_interface();
+ return GrGLAssembleGLInterface(NULL, android_get_gl_proc);
}
return NULL;
diff --git a/src/gpu/gl/android/SkNativeGLContext_android.cpp b/src/gpu/gl/android/SkNativeGLContext_android.cpp
index 462109a6c4..705bd8f49c 100644
--- a/src/gpu/gl/android/SkNativeGLContext_android.cpp
+++ b/src/gpu/gl/android/SkNativeGLContext_android.cpp
@@ -51,7 +51,7 @@ void SkNativeGLContext::destroyGLContext() {
}
}
-const GrGLInterface* SkNativeGLContext::createGLContext() {
+const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedGpuAPI) {
static const EGLint kEGLContextAttribsForOpenGL[] = {
EGL_NONE
};
@@ -81,9 +81,18 @@ const GrGLInterface* SkNativeGLContext::createGLContext() {
},
};
+ size_t apiLimit = SK_ARRAY_COUNT(kAPIs);
+ size_t api = 0;
+ if (forcedGpuAPI == kGL_GrGLStandard) {
+ apiLimit = 1;
+ } else if (forcedGpuAPI == kGLES_GrGLStandard) {
+ api = 1;
+ }
+ SkASSERT(forcedGpuAPI == kNone_GrGLStandard || kAPIs[api].fStandard == forcedGpuAPI);
+
const GrGLInterface* interface = NULL;
- for (size_t api = 0; NULL == interface && api < SK_ARRAY_COUNT(kAPIs); ++api) {
+ for (size_t i = 0; NULL == interface && i < apiLimit; ++api) {
fDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
EGLint majorVersion;
diff --git a/src/gpu/gl/angle/SkANGLEGLContext.cpp b/src/gpu/gl/angle/SkANGLEGLContext.cpp
index 2600ec4634..884fe7ca11 100644
--- a/src/gpu/gl/angle/SkANGLEGLContext.cpp
+++ b/src/gpu/gl/angle/SkANGLEGLContext.cpp
@@ -52,7 +52,10 @@ void SkANGLEGLContext::destroyGLContext() {
}
}
-const GrGLInterface* SkANGLEGLContext::createGLContext() {
+const GrGLInterface* SkANGLEGLContext::createGLContext(GrGLStandard forcedGpuAPI) {
+ if (kGL_GrGLStandard == forcedGpuAPI) {
+ return NULL;
+ }
fDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
diff --git a/src/gpu/gl/debug/SkDebugGLContext.cpp b/src/gpu/gl/debug/SkDebugGLContext.cpp
index ae42227251..93c0b30b8b 100644
--- a/src/gpu/gl/debug/SkDebugGLContext.cpp
+++ b/src/gpu/gl/debug/SkDebugGLContext.cpp
@@ -8,6 +8,10 @@
#include "gl/SkDebugGLContext.h"
-const GrGLInterface* SkDebugGLContext::createGLContext() {
+const GrGLInterface* SkDebugGLContext::createGLContext(GrGLStandard forcedGpuAPI) {
+ if (kGLES_GrGLStandard == forcedGpuAPI) {
+ return NULL;
+ }
+
return GrGLCreateDebugInterface();
};
diff --git a/src/gpu/gl/iOS/SkNativeGLContext_iOS.mm b/src/gpu/gl/iOS/SkNativeGLContext_iOS.mm
index a276fd05da..1e11c0deb7 100644
--- a/src/gpu/gl/iOS/SkNativeGLContext_iOS.mm
+++ b/src/gpu/gl/iOS/SkNativeGLContext_iOS.mm
@@ -42,7 +42,11 @@ void SkNativeGLContext::destroyGLContext() {
[EAGLCTX release];
}
-const GrGLInterface* SkNativeGLContext::createGLContext() {
+const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedGpuAPI) {
+ if (kGL_GrGLStandard == forcedGpuAPI) {
+ return NULL;
+ }
+
fEAGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
[EAGLContext setCurrentContext:EAGLCTX];
@@ -61,4 +65,4 @@ void SkNativeGLContext::makeCurrent() const {
}
}
-void SkNativeGLContext::swapBuffers() const { } \ No newline at end of file
+void SkNativeGLContext::swapBuffers() const { }
diff --git a/src/gpu/gl/mac/SkNativeGLContext_mac.cpp b/src/gpu/gl/mac/SkNativeGLContext_mac.cpp
index df316d7ed1..fefbb4c12b 100644
--- a/src/gpu/gl/mac/SkNativeGLContext_mac.cpp
+++ b/src/gpu/gl/mac/SkNativeGLContext_mac.cpp
@@ -32,8 +32,11 @@ void SkNativeGLContext::destroyGLContext() {
}
}
-const GrGLInterface* SkNativeGLContext::createGLContext() {
+const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedGpuAPI) {
SkASSERT(NULL == fContext);
+ if (kGLES_GrGLStandard == forcedGpuAPI) {
+ return NULL;
+ }
CGLPixelFormatAttribute attributes[] = {
#if MAC_OS_X_VERSION_10_7
diff --git a/src/gpu/gl/mesa/SkMesaGLContext.cpp b/src/gpu/gl/mesa/SkMesaGLContext.cpp
index 0199d12c19..58e325dfeb 100644
--- a/src/gpu/gl/mesa/SkMesaGLContext.cpp
+++ b/src/gpu/gl/mesa/SkMesaGLContext.cpp
@@ -53,7 +53,11 @@ void SkMesaGLContext::destroyGLContext() {
static const GrGLint gBOGUS_SIZE = 16;
-const GrGLInterface* SkMesaGLContext::createGLContext() {
+const GrGLInterface* SkMesaGLContext::createGLContext(GrGLStandard forcedGpuAPI) {
+ if (kGLES_GrGLStandard == forcedGpuAPI) {
+ return NULL;
+ }
+
/* Create an RGBA-mode context */
#if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305
/* specify Z, stencil, accum sizes */
diff --git a/src/gpu/gl/nacl/SkNativeGLContext_nacl.cpp b/src/gpu/gl/nacl/SkNativeGLContext_nacl.cpp
index 69a74caf8a..334be1d954 100644
--- a/src/gpu/gl/nacl/SkNativeGLContext_nacl.cpp
+++ b/src/gpu/gl/nacl/SkNativeGLContext_nacl.cpp
@@ -26,7 +26,7 @@ SkNativeGLContext::~SkNativeGLContext() {
void SkNativeGLContext::destroyGLContext() {
}
-const GrGLInterface* SkNativeGLContext::createGLContext() {
+const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedGpuAPI) {
return NULL;
}
diff --git a/src/gpu/gl/unix/GrGLCreateNativeInterface_unix.cpp b/src/gpu/gl/unix/GrGLCreateNativeInterface_unix.cpp
index ddbfe5de29..b3c7a3c5a9 100644
--- a/src/gpu/gl/unix/GrGLCreateNativeInterface_unix.cpp
+++ b/src/gpu/gl/unix/GrGLCreateNativeInterface_unix.cpp
@@ -8,9 +8,19 @@
#include "gl/GrGLInterface.h"
#include "gl/GrGLAssembleInterface.h"
+#include "gl/GrGLUtil.h"
#include <GL/glx.h>
+#define GET_PROC(F) functions->f ## F = (GrGL ## F ## Proc) get(ctx, "gl" #F)
+#define GET_PROC_SUFFIX(F, S) functions->f ## F = (GrGL ## F ## Proc) get(ctx, "gl" #F #S)
+#define GET_PROC_LOCAL(F) GrGL ## F ## Proc F = (GrGL ## F ## Proc) get(ctx, "gl" #F)
+
+#define GET_LINKED GET_PROC
+#define GET_LINKED_SUFFIX GET_PROC_SUFFIX
+
+#include "gl/GrGLAssembleGLESInterface.h"
+
static GrGLFuncPtr glx_get(void* ctx, const char name[]) {
SkASSERT(NULL == ctx);
SkASSERT(NULL != glXGetCurrentContext());
@@ -21,5 +31,14 @@ const GrGLInterface* GrGLCreateNativeInterface() {
if (NULL == glXGetCurrentContext()) {
return NULL;
}
- return GrGLAssembleGLInterface(NULL, glx_get);
+
+ const char* verStr = reinterpret_cast<const char*>(glGetString(GR_GL_VERSION));
+ GrGLStandard standard = GrGLGetStandardInUseFromString(verStr);
+
+ if (kGLES_GrGLStandard == standard) {
+ return GrGLAssembleGLESInterface(NULL, glx_get);
+ } else if (kGL_GrGLStandard == standard) {
+ return GrGLAssembleGLInterface(NULL, glx_get);
+ }
+ return NULL;
}
diff --git a/src/gpu/gl/unix/SkNativeGLContext_unix.cpp b/src/gpu/gl/unix/SkNativeGLContext_unix.cpp
index c4bd6f937d..4da1eb2f4f 100644
--- a/src/gpu/gl/unix/SkNativeGLContext_unix.cpp
+++ b/src/gpu/gl/unix/SkNativeGLContext_unix.cpp
@@ -66,7 +66,7 @@ void SkNativeGLContext::destroyGLContext() {
}
}
-const GrGLInterface* SkNativeGLContext::createGLContext() {
+const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedGpuAPI) {
fDisplay = XOpenDisplay(0);
if (!fDisplay) {
@@ -187,60 +187,68 @@ const GrGLInterface* SkNativeGLContext::createGLContext() {
const char *glxExts = glXQueryExtensionsString(
fDisplay, DefaultScreen(fDisplay)
);
+
+
// Check for the GLX_ARB_create_context extension string and the function.
// If either is not present, use GLX 1.3 context creation method.
- if (!gluCheckExtension(
- reinterpret_cast<const GLubyte*>("GLX_ARB_create_context")
- , reinterpret_cast<const GLubyte*>(glxExts)))
- {
- //SkDebugf("GLX_ARB_create_context not found."
- // " Using old-style GLX context.\n");
+
+ if (!gluCheckExtension(reinterpret_cast<const GLubyte*>("GLX_ARB_create_context"),
+ reinterpret_cast<const GLubyte*>(glxExts))) {
+ if (kGLES_GrGLStandard != forcedGpuAPI) {
#ifdef GLX_1_3
- fContext = glXCreateNewContext(fDisplay, bestFbc, GLX_RGBA_TYPE, 0, True);
+ fContext = glXCreateNewContext(fDisplay, bestFbc, GLX_RGBA_TYPE, 0, True);
#else
- fContext = glXCreateContext(fDisplay, vi, 0, True);
+ fContext = glXCreateContext(fDisplay, vi, 0, True);
#endif
-
+ }
}
#ifdef GLX_1_3
else {
//SkDebugf("Creating context.\n");
-
PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB =
(PFNGLXCREATECONTEXTATTRIBSARBPROC) glXGetProcAddressARB((GrGLubyte*)"glXCreateContextAttribsARB");
- int context_attribs[] = {
+
+ static const int context_attribs_gl[] = {
GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
GLX_CONTEXT_MINOR_VERSION_ARB, 0,
- //GLX_CONTEXT_FLAGS_ARB , GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
None
};
- fContext = glXCreateContextAttribsARB(
- fDisplay, bestFbc, 0, True, context_attribs
- );
-
- // Sync to ensure any errors generated are processed.
- XSync(fDisplay, False);
- if (!ctxErrorOccurred && fContext) {
- //SkDebugf( "Created GL 3.0 context.\n" );
+ static const int context_attribs_gl_fallback[] = {
+ GLX_CONTEXT_MAJOR_VERSION_ARB, 1,
+ GLX_CONTEXT_MINOR_VERSION_ARB, 0,
+ None
+ };
+ static const int context_attribs_gles[] = {
+ GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
+ GLX_CONTEXT_MINOR_VERSION_ARB, 0,
+ GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_ES2_PROFILE_BIT_EXT,
+ None
+ };
+
+ if (kGLES_GrGLStandard == forcedGpuAPI) {
+ if (gluCheckExtension(
+ reinterpret_cast<const GLubyte*>("GLX_EXT_create_context_es2_profile"),
+ reinterpret_cast<const GLubyte*>(glxExts))) {
+ fContext = glXCreateContextAttribsARB(fDisplay, bestFbc, 0, True,
+ context_attribs_gles);
+ }
} else {
- // Couldn't create GL 3.0 context.
- // Fall back to old-style 2.x context.
- // When a context version below 3.0 is requested,
- // implementations will return the newest context version compatible
- // with OpenGL versions less than version 3.0.
-
- // GLX_CONTEXT_MAJOR_VERSION_ARB = 1
- context_attribs[1] = 1;
- // GLX_CONTEXT_MINOR_VERSION_ARB = 0
- context_attribs[3] = 0;
-
- ctxErrorOccurred = false;
-
- //SkDebugf("Failed to create GL 3.0 context."
- // " Using old-style GLX context.\n");
- fContext = glXCreateContextAttribsARB(
- fDisplay, bestFbc, 0, True, context_attribs
- );
+ fContext = glXCreateContextAttribsARB(fDisplay, bestFbc, 0, True, context_attribs_gl);
+
+ // Sync to ensure any errors generated are processed.
+ XSync(fDisplay, False);
+ if (ctxErrorOccurred || !fContext) {
+ // Couldn't create GL 3.0 context.
+ // Fall back to old-style 2.x context.
+ // When a context version below 3.0 is requested,
+ // implementations will return the newest context version
+ // compatible with OpenGL versions less than version 3.0.
+
+ ctxErrorOccurred = false;
+
+ fContext = glXCreateContextAttribsARB(fDisplay, bestFbc, 0, True,
+ context_attribs_gl_fallback);
+ }
}
}
#endif
diff --git a/src/gpu/gl/win/GrGLCreateNativeInterface_win.cpp b/src/gpu/gl/win/GrGLCreateNativeInterface_win.cpp
index 6adaf1964f..d63dfbbcd6 100644
--- a/src/gpu/gl/win/GrGLCreateNativeInterface_win.cpp
+++ b/src/gpu/gl/win/GrGLCreateNativeInterface_win.cpp
@@ -8,9 +8,21 @@
#include "gl/GrGLInterface.h"
#include "gl/GrGLAssembleInterface.h"
+#include "gl/GrGLUtil.h"
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
+#include <GL/gl.h>
+
+#define GET_PROC(F) functions->f ## F = (GrGL ## F ## Proc) get(ctx, "gl" #F)
+#define GET_PROC_SUFFIX(F, S) functions->f ## F = (GrGL ## F ## Proc) get(ctx, "gl" #F #S)
+#define GET_PROC_LOCAL(F) GrGL ## F ## Proc F = (GrGL ## F ## Proc) get(ctx, "gl" #F)
+
+#define GET_LINKED GET_PROC
+#define GET_LINKED_SUFFIX GET_PROC_SUFFIX
+
+#include "gl/GrGLAssembleGLESInterface.h"
+
class AutoLibraryUnload {
public:
AutoLibraryUnload(const char* moduleName) {
@@ -70,5 +82,13 @@ const GrGLInterface* GrGLCreateNativeInterface() {
return NULL;
}
- return GrGLAssembleGLInterface(&getter, win_get_gl_proc);
+ const char* verStr = reinterpret_cast<const char*>(glGetString(GR_GL_VERSION));
+ GrGLStandard standard = GrGLGetStandardInUseFromString(verStr);
+
+ if (kGLES_GrGLStandard == standard) {
+ return GrGLAssembleGLESInterface(&getter, win_get_gl_proc);
+ } else if (kGL_GrGLStandard == standard) {
+ return GrGLAssembleGLInterface(&getter, win_get_gl_proc);
+ }
+ return NULL;
}
diff --git a/src/gpu/gl/win/SkNativeGLContext_win.cpp b/src/gpu/gl/win/SkNativeGLContext_win.cpp
index bae97a780c..f085fdc6ee 100644
--- a/src/gpu/gl/win/SkNativeGLContext_win.cpp
+++ b/src/gpu/gl/win/SkNativeGLContext_win.cpp
@@ -47,7 +47,7 @@ void SkNativeGLContext::destroyGLContext() {
}
}
-const GrGLInterface* SkNativeGLContext::createGLContext() {
+const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedGpuAPI) {
HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL);
if (!gWC) {
@@ -85,9 +85,13 @@ const GrGLInterface* SkNativeGLContext::createGLContext() {
this->destroyGLContext();
return NULL;
}
+ // Requesting a Core profile would bar us from using NVPR. So we request
+ // compatibility profile or GL ES.
+ SkWGLContextRequest contextType =
+ kGLES_GrGLStandard == forcedGpuAPI ?
+ kGLES_SkWGLContextRequest : kGLPreferCompatibilityProfile_SkWGLContextRequest;
- // Requesting a Core profile would bar us from using NVPR. So we pass false.
- if (!(fGlRenderContext = SkCreateWGLContext(fDeviceContext, 0, false))) {
+ if (!(fGlRenderContext = SkCreateWGLContext(fDeviceContext, 0, contextType))) {
SkDebugf("Could not create rendering context.\n");
this->destroyGLContext();
return NULL;