| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 * | 7 * |
| 8 */ | 8 */ |
| 9 #include <v8.h> | 9 #include <v8.h> |
| 10 | 10 |
| 11 using namespace v8; | 11 using namespace v8; |
| 12 | 12 |
| 13 #include "SkV8Example.h" | 13 #include "SkV8Example.h" |
| 14 #include "Global.h" | 14 #include "Global.h" |
| 15 #include "JsContext.h" | 15 #include "JsContext.h" |
| 16 #include "Path.h" | 16 #include "Path.h" |
| 17 | 17 |
| 18 #include "gl/GrGLUtil.h" | 18 #include "gl/GrGLUtil.h" |
| 19 #include "gl/GrGLDefines.h" | 19 #include "gl/GrGLDefines.h" |
| 20 #include "gl/GrGLInterface.h" | 20 #include "gl/GrGLInterface.h" |
| 21 #include "GrRenderTarget.h" | 21 #include "GrRenderTarget.h" |
| 22 #include "GrContext.h" | 22 #include "GrContext.h" |
| 23 #include "SkApplication.h" | 23 #include "SkApplication.h" |
| 24 #include "SkCommandLineFlags.h" | 24 #include "SkCommandLineFlags.h" |
| 25 #include "SkData.h" | 25 #include "SkData.h" |
| 26 #include "SkDraw.h" | 26 #include "SkDraw.h" |
| 27 #include "SkGpuDevice.h" | 27 #include "SkGpuDevice.h" |
| 28 #include "SkGraphics.h" | 28 #include "SkGraphics.h" |
| 29 #include "SkScalar.h" | 29 #include "SkScalar.h" |
| 30 #include "SkSurface.h" |
| 30 | 31 |
| 31 | 32 |
| 32 DEFINE_string2(infile, i, NULL, "Name of file to load JS from.\n"); | 33 DEFINE_string2(infile, i, NULL, "Name of file to load JS from.\n"); |
| 33 DEFINE_bool(gpu, true, "Use the GPU for rendering."); | 34 DEFINE_bool(gpu, true, "Use the GPU for rendering."); |
| 34 | 35 |
| 35 void application_init() { | 36 void application_init() { |
| 36 SkGraphics::Init(); | 37 SkGraphics::Init(); |
| 37 SkEvent::Init(); | 38 SkEvent::Init(); |
| 38 } | 39 } |
| 39 | 40 |
| 40 void application_term() { | 41 void application_term() { |
| 41 SkEvent::Term(); | 42 SkEvent::Term(); |
| 42 SkGraphics::Term(); | 43 SkGraphics::Term(); |
| 43 } | 44 } |
| 44 | 45 |
| 45 SkV8ExampleWindow::SkV8ExampleWindow(void* hwnd, JsContext* context) | 46 SkV8ExampleWindow::SkV8ExampleWindow(void* hwnd, JsContext* context) |
| 46 : INHERITED(hwnd) | 47 : INHERITED(hwnd) |
| 47 , fJsContext(context) | 48 , fJsContext(context) |
| 48 #if SK_SUPPORT_GPU | 49 #if SK_SUPPORT_GPU |
| 49 , fCurContext(NULL) | 50 , fCurContext(NULL) |
| 50 , fCurIntf(NULL) | 51 , fCurIntf(NULL) |
| 51 , fCurRenderTarget(NULL) | 52 , fCurRenderTarget(NULL) |
| 53 , fCurSurface(NULL) |
| 52 #endif | 54 #endif |
| 53 { | 55 { |
| 54 this->setConfig(SkBitmap::kARGB_8888_Config); | 56 this->setColorType(kBGRA_8888_SkColorType); |
| 55 this->setVisibleP(true); | 57 this->setVisibleP(true); |
| 56 this->setClipToBounds(false); | 58 this->setClipToBounds(false); |
| 57 | 59 |
| 58 #if SK_SUPPORT_GPU | 60 #if SK_SUPPORT_GPU |
| 59 this->windowSizeChanged(); | 61 this->windowSizeChanged(); |
| 60 #endif | 62 #endif |
| 61 } | 63 } |
| 62 | 64 |
| 65 SkV8ExampleWindow::~SkV8ExampleWindow() { |
| 66 #if SK_SUPPORT_GPU |
| 67 SkSafeUnref(fCurContext); |
| 68 SkSafeUnref(fCurIntf); |
| 69 SkSafeUnref(fCurRenderTarget); |
| 70 SkSafeUnref(fCurSurface); |
| 71 #endif |
| 72 } |
| 73 |
| 63 #if SK_SUPPORT_GPU | 74 #if SK_SUPPORT_GPU |
| 64 void SkV8ExampleWindow::windowSizeChanged() { | 75 void SkV8ExampleWindow::windowSizeChanged() { |
| 65 if (FLAGS_gpu) { | 76 if (FLAGS_gpu) { |
| 66 SkOSWindow::AttachmentInfo attachmentInfo; | 77 SkOSWindow::AttachmentInfo attachmentInfo; |
| 67 bool result = this->attach( | 78 bool result = this->attach( |
| 68 SkOSWindow::kNativeGL_BackEndType, 0, &attachmentInfo); | 79 SkOSWindow::kNativeGL_BackEndType, 0, &attachmentInfo); |
| 69 if (!result) { | 80 if (!result) { |
| 70 printf("Failed to attach."); | 81 printf("Failed to attach."); |
| 71 exit(1); | 82 exit(1); |
| 72 } | 83 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 85 desc.fConfig = kSkia8888_GrPixelConfig; | 96 desc.fConfig = kSkia8888_GrPixelConfig; |
| 86 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; | 97 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
| 87 desc.fSampleCnt = attachmentInfo.fSampleCount; | 98 desc.fSampleCnt = attachmentInfo.fSampleCount; |
| 88 desc.fStencilBits = attachmentInfo.fStencilBits; | 99 desc.fStencilBits = attachmentInfo.fStencilBits; |
| 89 GrGLint buffer; | 100 GrGLint buffer; |
| 90 GR_GL_GetIntegerv(fCurIntf, GR_GL_FRAMEBUFFER_BINDING, &buffer); | 101 GR_GL_GetIntegerv(fCurIntf, GR_GL_FRAMEBUFFER_BINDING, &buffer); |
| 91 desc.fRenderTargetHandle = buffer; | 102 desc.fRenderTargetHandle = buffer; |
| 92 | 103 |
| 93 SkSafeUnref(fCurRenderTarget); | 104 SkSafeUnref(fCurRenderTarget); |
| 94 fCurRenderTarget = fCurContext->wrapBackendRenderTarget(desc); | 105 fCurRenderTarget = fCurContext->wrapBackendRenderTarget(desc); |
| 106 SkSafeUnref(fCurSurface); |
| 107 fCurSurface = SkSurface::NewRenderTargetDirect(fCurRenderTarget); |
| 95 } | 108 } |
| 96 } | 109 } |
| 97 #endif | 110 #endif |
| 98 | 111 |
| 99 #if SK_SUPPORT_GPU | 112 #if SK_SUPPORT_GPU |
| 100 SkCanvas* SkV8ExampleWindow::createCanvas() { | 113 SkCanvas* SkV8ExampleWindow::createCanvas() { |
| 101 if (FLAGS_gpu) { | 114 if (FLAGS_gpu) { |
| 102 SkAutoTUnref<SkBaseDevice> device( | 115 SkCanvas* c = fCurSurface->getCanvas(); |
| 103 new SkGpuDevice(fCurContext, fCurRenderTarget)); | 116 // Increase the ref count since the surface keeps a reference |
| 104 return new SkCanvas(device); | 117 // to the canvas, but callers of createCanvas put the results |
| 118 // in a SkAutoTUnref. |
| 119 c->ref(); |
| 120 return c; |
| 105 } else { | 121 } else { |
| 106 return this->INHERITED::createCanvas(); | 122 return this->INHERITED::createCanvas(); |
| 107 } | 123 } |
| 108 } | 124 } |
| 109 #endif | 125 #endif |
| 110 | 126 |
| 111 void SkV8ExampleWindow::onSizeChange() { | 127 void SkV8ExampleWindow::onSizeChange() { |
| 112 this->INHERITED::onSizeChange(); | 128 this->INHERITED::onSizeChange(); |
| 113 | 129 |
| 114 #if SK_SUPPORT_GPU | 130 #if SK_SUPPORT_GPU |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 | 216 |
| 201 if (!jsContext->initialize()) { | 217 if (!jsContext->initialize()) { |
| 202 printf("Failed to initialize.\n"); | 218 printf("Failed to initialize.\n"); |
| 203 exit(1); | 219 exit(1); |
| 204 } | 220 } |
| 205 SkV8ExampleWindow* win = new SkV8ExampleWindow(hwnd, jsContext); | 221 SkV8ExampleWindow* win = new SkV8ExampleWindow(hwnd, jsContext); |
| 206 global->setWindow(win); | 222 global->setWindow(win); |
| 207 | 223 |
| 208 return win; | 224 return win; |
| 209 } | 225 } |
| OLD | NEW |