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

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

Issue 12212074: Support for non-DOM canvases/contexts (backed by bitaps). (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
(...skipping 17 matching lines...) Expand all
28 } else { 28 } else {
29 return str; 29 return str;
30 } 30 }
31 } 31 }
32 32
33 int32_t GraphicsHandler::Start() { 33 int32_t GraphicsHandler::Start() {
34 SkGraphics::Init(); 34 SkGraphics::Init();
35 GrGLInterface* fGL = const_cast<GrGLInterface*>(GrGLCreateNativeInterface()); 35 GrGLInterface* fGL = const_cast<GrGLInterface*>(GrGLCreateNativeInterface());
36 LOGI("Created native interface %s\n", fGL ? "succeeded" : "failed"); 36 LOGI("Created native interface %s\n", fGL ? "succeeded" : "failed");
37 fGL->fGetString = myGLGetString; 37 fGL->fGetString = myGLGetString;
38 grcontext = GrContext::Create(kOpenGL_Shaders_GrEngine, 38 grcontext = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)fGL);
39 (GrPlatform3DContext)fGL);
40 LOGI("Created GrContext %s\n", grcontext ? "succeeded" : "failed"); 39 LOGI("Created GrContext %s\n", grcontext ? "succeeded" : "failed");
41 return 0; 40 return 0;
42 } 41 }
43 42
44 void GraphicsHandler::Stop() { 43 void GraphicsHandler::Stop() {
45 SkGraphics::Term(); 44 SkGraphics::Term();
46 } 45 }
47 46
48 SkCanvas* GraphicsHandler::CreateCanvas() { 47 SkCanvas* GraphicsHandler::CreateDisplayCanvas() {
49 GrPlatformRenderTargetDesc desc; 48 GrBackendRenderTargetDesc desc;
50 desc.fWidth = width_; 49 desc.fWidth = width_;
51 desc.fHeight = height_; 50 desc.fHeight = height_;
52 desc.fConfig = kSkia8888_PM_GrPixelConfig; 51 desc.fConfig = kSkia8888_GrPixelConfig;
52 desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
53 glGetIntegerv(GL_SAMPLES, &desc.fSampleCnt); 53 glGetIntegerv(GL_SAMPLES, &desc.fSampleCnt);
54 glGetIntegerv(GL_STENCIL_BITS, &desc.fStencilBits); 54 glGetIntegerv(GL_STENCIL_BITS, &desc.fStencilBits);
55 LOGI("Creating %dx%d display canvas, samples %d, stencil bits %d",
56 width_, height_, desc.fSampleCnt, desc.fStencilBits);
55 GrGLint buffer; 57 GrGLint buffer;
56 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &buffer); 58 glGetIntegerv(GL_FRAMEBUFFER_BINDING, &buffer);
57 desc.fRenderTargetHandle = buffer; 59 desc.fRenderTargetHandle = buffer;
58 GrRenderTarget* fGrRenderTarget = grcontext->createPlatformRenderTarget(desc); 60 GrRenderTarget* fGrRenderTarget = grcontext->wrapBackendRenderTarget(desc);
59 return new SkCanvas(new SkGpuDevice(grcontext, fGrRenderTarget)); 61 SkGpuDevice* device = new SkGpuDevice(grcontext, fGrRenderTarget);
62 // fGrRenderTarget->unref(); // TODO(gram): determine if we need this.
63 SkCanvas* canvas = new SkCanvas(device);
64 device->unref();
65 return canvas;
66 }
67
68 SkCanvas* GraphicsHandler::CreateBitmapCanvas(int width, int height) {
69 LOGI("Creating %dx%d bitmap canvas", width, height);
70 SkDevice* rasterDevice =
71 new SkDevice(SkBitmap::kARGB_8888_Config, width, height);
72 SkCanvas* canvas = new SkCanvas(rasterDevice);
73 rasterDevice->unref();
74 return canvas;
60 } 75 }
61 76
62 void GraphicsHandler::SetViewport(int left, int top, int width, int height) { 77 void GraphicsHandler::SetViewport(int left, int top, int width, int height) {
63 width_ = width; 78 width_ = width;
64 height_ = height; 79 height_ = height;
65 glViewport(left, top, width, height); 80 glViewport(left, top, width, height);
66 CheckGLError("glViewPort"); 81 CheckGLError("glViewPort");
67 } 82 }
68 83
69 int32_t GraphicsHandler::Update() { 84 int32_t GraphicsHandler::Update() {
70 extern CanvasContext* display_context; 85 extern CanvasContext* display_context;
71 if (display_context != NULL) { 86 if (display_context != NULL) {
72 LOGI("Flushing display context\n"); 87 LOGI("Flushing display context\n");
73 display_context->Flush(); 88 display_context->Flush();
74 } 89 }
75 SwapBuffers(); 90 SwapBuffers();
76 return 0; 91 return 0;
77 } 92 }
78 93
79 94
80 95
81 96
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698