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

Side by Side Diff: runtime/embedders/openglui/common/graphics_handler.cc

Issue 12340036: Android improvements: (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "embedders/openglui/common/graphics_handler.h" 5 #include "embedders/openglui/common/graphics_handler.h"
6 #include "embedders/openglui/common/canvas_context.h" 6 #include "embedders/openglui/common/canvas_context.h"
7 #include "embedders/openglui/common/log.h" 7 #include "embedders/openglui/common/log.h"
8 8
9 extern void CheckGLError(const char *function); 9 extern void CheckGLError(const char *function);
10 10
11 GraphicsHandler* graphics; 11 GraphicsHandler* graphics;
12 extern CanvasContext* display_context;
12 13
13 GraphicsHandler::GraphicsHandler() 14 GraphicsHandler::GraphicsHandler(const char* resource_path)
14 : ag(), 15 : resource_path_(resource_path),
16 ag(),
15 grcontext(NULL), 17 grcontext(NULL),
16 width_(0), 18 width_(0),
17 height_(0) { 19 height_(0) {
18 graphics = this; 20 graphics = this;
21 DecoderHack(0, NULL);
22 }
23
24 void GraphicsHandler::DecoderHack(int x, SkStream* s) {
25 if (x) { // hack to keep the linker from throwing these out
26 extern SkImageDecoder* sk_libpng_dfactory(SkStream* s);
27 sk_libpng_dfactory(s);
28
29 // TODO(gram): For some reason I get linker errors on these, even though
30 // they are defined in libskia_images. Figure out why...
31 /*
32 extern SkImageDecoder* sk_libjpeg_dfactory(SkStream* s);
33 extern SkImageDecoder* sk_libbmp_dfactory(SkStream* s);
34 extern SkImageDecoder* sk_libgif_dfactory(SkStream* s);
35 extern SkImageDecoder* sk_libico_dfactory(SkStream* s);
36 extern SkImageDecoder* sk_libwbmp_dfactory(SkStream* s);
37 sk_libjpeg_dfactory(s);
38 sk_libbmp_dfactory(s);
39 sk_libgif_dfactory(s);
40 sk_libico_dfactory(s);
41 sk_libwbmp_dfactory(s);
42 */
43 }
19 } 44 }
20 45
21 // Kludge to get around an issue with Android emulator, which returns 46 // Kludge to get around an issue with Android emulator, which returns
22 // NULL for the shader language version, causing Skia to blow up. 47 // NULL for the shader language version, causing Skia to blow up.
23 const GrGLubyte* myGLGetString(GLenum name) { 48 const GrGLubyte* myGLGetString(GLenum name) {
24 const GrGLubyte* str = glGetString(name); 49 const GrGLubyte* str = glGetString(name);
25 if (NULL == str && GL_SHADING_LANGUAGE_VERSION == name) { 50 if (NULL == str && GL_SHADING_LANGUAGE_VERSION == name) {
26 return reinterpret_cast<GrGLubyte*>( 51 return reinterpret_cast<GrGLubyte*>(
27 const_cast<char*>("OpenGL ES GLSL ES 1.0")); 52 const_cast<char*>("OpenGL ES GLSL ES 1.0"));
28 } else { 53 } else {
29 return str; 54 return str;
30 } 55 }
31 } 56 }
32 57
33 int32_t GraphicsHandler::Start() { 58 int32_t GraphicsHandler::Start() {
34 SkGraphics::Init();
35 GrGLInterface* fGL = const_cast<GrGLInterface*>(GrGLCreateNativeInterface()); 59 GrGLInterface* fGL = const_cast<GrGLInterface*>(GrGLCreateNativeInterface());
36 LOGI("Created native interface %s\n", fGL ? "succeeded" : "failed"); 60 LOGI("Created native interface %s\n", fGL ? "succeeded" : "failed");
37 fGL->fGetString = myGLGetString; 61 fGL->fGetString = myGLGetString;
38 grcontext = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)fGL); 62 grcontext = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)fGL);
39 LOGI("Created GrContext %s\n", grcontext ? "succeeded" : "failed"); 63 LOGI("Created GrContext %s\n", grcontext ? "succeeded" : "failed");
40 return 0; 64 return 0;
41 } 65 }
42 66
43 void GraphicsHandler::Stop() { 67 void GraphicsHandler::Stop() {
44 SkGraphics::Term(); 68 LOGI("Releasing display context");
69 FreeContexts();
70 grcontext->unref();
71 grcontext = NULL;
45 } 72 }
46 73
47 SkCanvas* GraphicsHandler::CreateDisplayCanvas() { 74 SkCanvas* GraphicsHandler::CreateDisplayCanvas() {
48 GrBackendRenderTargetDesc desc; 75 GrBackendRenderTargetDesc desc;
49 desc.fWidth = width_; 76 desc.fWidth = width_;
50 desc.fHeight = height_; 77 desc.fHeight = height_;
51 desc.fConfig = kSkia8888_GrPixelConfig; 78 desc.fConfig = kSkia8888_GrPixelConfig;
52 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; 79 desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
53 glGetIntegerv(GL_SAMPLES, &desc.fSampleCnt); 80 glGetIntegerv(GL_SAMPLES, &desc.fSampleCnt);
54 glGetIntegerv(GL_STENCIL_BITS, &desc.fStencilBits); 81 glGetIntegerv(GL_STENCIL_BITS, &desc.fStencilBits);
(...skipping 20 matching lines...) Expand all
75 } 102 }
76 103
77 void GraphicsHandler::SetViewport(int left, int top, int width, int height) { 104 void GraphicsHandler::SetViewport(int left, int top, int width, int height) {
78 width_ = width; 105 width_ = width;
79 height_ = height; 106 height_ = height;
80 glViewport(left, top, width, height); 107 glViewport(left, top, width, height);
81 CheckGLError("glViewPort"); 108 CheckGLError("glViewPort");
82 } 109 }
83 110
84 int32_t GraphicsHandler::Update() { 111 int32_t GraphicsHandler::Update() {
85 extern CanvasContext* display_context; 112 if (display_context != NULL && display_context->isDirty()) {
86 if (display_context != NULL) {
87 LOGI("Flushing display context\n"); 113 LOGI("Flushing display context\n");
88 display_context->Flush(); 114 display_context->Flush();
115 SwapBuffers();
116 display_context->clearDirty();
89 } 117 }
90 SwapBuffers();
91 return 0; 118 return 0;
92 } 119 }
93 120
94
95
96
OLDNEW
« no previous file with comments | « runtime/embedders/openglui/common/graphics_handler.h ('k') | runtime/embedders/openglui/common/lifecycle_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698