| Index: runtime/embedders/openglui/common/graphics_handler.cc
|
| ===================================================================
|
| --- runtime/embedders/openglui/common/graphics_handler.cc (revision 17604)
|
| +++ runtime/embedders/openglui/common/graphics_handler.cc (working copy)
|
| @@ -2,63 +2,80 @@
|
| // for details. All rights reserved. Use of this source code is governed by a
|
| // BSD-style license that can be found in the LICENSE file.
|
|
|
| -#include "embedders/openglui/common/gl_graphics_handler.h"
|
| +#include "embedders/openglui/common/graphics_handler.h"
|
| +#include "embedders/openglui/common/canvas_context.h"
|
| #include "embedders/openglui/common/log.h"
|
|
|
| extern void CheckGLError(const char *function);
|
|
|
| -void GLGraphicsHandler::SetViewport(int left, int top, int width, int height) {
|
| - glViewport(left, top, width, height);
|
| - CheckGLError("glViewPort");
|
| +GraphicsHandler* graphics;
|
| +
|
| +GraphicsHandler::GraphicsHandler()
|
| + : ag(),
|
| + grcontext(NULL),
|
| + width_(0),
|
| + height_(0) {
|
| + graphics = this;
|
| }
|
|
|
| -int GLGraphicsHandler::BuildProgram(const char* vertexShaderSource,
|
| - const char* fragmentShaderSource) const {
|
| - int vertexShader = BuildShader(vertexShaderSource, GL_VERTEX_SHADER);
|
| - int fragmentShader = BuildShader(fragmentShaderSource, GL_FRAGMENT_SHADER);
|
| - if (vertexShader < 0 || fragmentShader < 0) {
|
| - return -1;
|
| +// Kludge to get around an issue with Android emulator, which returns
|
| +// NULL for the shader language version, causing Skia to blow up.
|
| +const GrGLubyte* myGLGetString(GLenum name) {
|
| + const GrGLubyte* str = glGetString(name);
|
| + if (NULL == str && GL_SHADING_LANGUAGE_VERSION == name) {
|
| + return reinterpret_cast<GrGLubyte*>(
|
| + const_cast<char*>("OpenGL ES GLSL ES 1.0"));
|
| + } else {
|
| + return str;
|
| }
|
| +}
|
|
|
| - GLuint programHandle = glCreateProgram();
|
| - glAttachShader(programHandle, static_cast<GLuint>(vertexShader));
|
| - glAttachShader(programHandle, static_cast<GLuint>(fragmentShader));
|
| - glLinkProgram(programHandle);
|
| +int32_t GraphicsHandler::Start() {
|
| + SkGraphics::Init();
|
| + GrGLInterface* fGL = const_cast<GrGLInterface*>(GrGLCreateNativeInterface());
|
| + LOGI("Created native interface %s\n", fGL ? "succeeded" : "failed");
|
| + fGL->fGetString = myGLGetString;
|
| + grcontext = GrContext::Create(kOpenGL_Shaders_GrEngine,
|
| + (GrPlatform3DContext)fGL);
|
| + LOGI("Created GrContext %s\n", grcontext ? "succeeded" : "failed");
|
| + return 0;
|
| +}
|
|
|
| - GLint linkSuccess;
|
| - glGetProgramiv(programHandle, GL_LINK_STATUS, &linkSuccess);
|
| - if (linkSuccess == GL_FALSE) {
|
| - GLint infoLogLength;
|
| - glGetProgramiv(programHandle, GL_INFO_LOG_LENGTH, &infoLogLength);
|
| - GLchar* strInfoLog = new GLchar[infoLogLength + 1];
|
| - glGetProgramInfoLog(programHandle, infoLogLength, NULL, strInfoLog);
|
| - strInfoLog[infoLogLength] = 0;
|
| - LOGE("Link failed: %s", strInfoLog);
|
| - delete[] strInfoLog;
|
| - return -1;
|
| - }
|
| - return static_cast<int>(programHandle);
|
| +void GraphicsHandler::Stop() {
|
| + SkGraphics::Term();
|
| }
|
|
|
| -int GLGraphicsHandler::BuildShader(const char* source,
|
| - GLenum shaderType) const {
|
| - GLuint shaderHandle = glCreateShader(shaderType);
|
| - glShaderSource(shaderHandle, 1, &source, NULL);
|
| - glCompileShader(shaderHandle);
|
| +SkCanvas* GraphicsHandler::CreateCanvas() {
|
| + GrPlatformRenderTargetDesc desc;
|
| + desc.fWidth = width_;
|
| + desc.fHeight = height_;
|
| + desc.fConfig = kSkia8888_PM_GrPixelConfig;
|
| + glGetIntegerv(GL_SAMPLES, &desc.fSampleCnt);
|
| + glGetIntegerv(GL_STENCIL_BITS, &desc.fStencilBits);
|
| + GrGLint buffer;
|
| + glGetIntegerv(GL_FRAMEBUFFER_BINDING, &buffer);
|
| + desc.fRenderTargetHandle = buffer;
|
| + GrRenderTarget* fGrRenderTarget = grcontext->createPlatformRenderTarget(desc);
|
| + return new SkCanvas(new SkGpuDevice(grcontext, fGrRenderTarget));
|
| +}
|
|
|
| - GLint compileSuccess;
|
| - glGetShaderiv(shaderHandle, GL_COMPILE_STATUS, &compileSuccess);
|
| +void GraphicsHandler::SetViewport(int left, int top, int width, int height) {
|
| + width_ = width;
|
| + height_ = height;
|
| + glViewport(left, top, width, height);
|
| + CheckGLError("glViewPort");
|
| +}
|
|
|
| - if (compileSuccess == GL_FALSE) {
|
| - GLint infoLogLength = 0;
|
| - glGetShaderiv(shaderHandle, GL_INFO_LOG_LENGTH, &infoLogLength);
|
| - GLchar* strInfoLog = new GLchar[infoLogLength + 1];
|
| - glGetShaderInfoLog(shaderHandle, infoLogLength, NULL, strInfoLog);
|
| - strInfoLog[infoLogLength] = 0;
|
| - LOGE("Shader compile failed: %s", strInfoLog);
|
| - delete [] strInfoLog;
|
| - return -1;
|
| +int32_t GraphicsHandler::Update() {
|
| + extern CanvasContext* display_context;
|
| + if (display_context != NULL) {
|
| + LOGI("Flushing display context\n");
|
| + display_context->Flush();
|
| }
|
| - return static_cast<int>(shaderHandle);
|
| + SwapBuffers();
|
| + return 0;
|
| }
|
|
|
| +
|
| +
|
| +
|
|
|