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" |
robertphillips
2014/02/26 23:51:08
Is this #include for the kBGRA_8888_SkColorType de
jcgregorio
2014/02/27 14:23:16
I added it for that reason, looks like it isn't ne
| |
29 #include "SkImageInfo.h" | |
29 #include "SkScalar.h" | 30 #include "SkScalar.h" |
31 #include "SkSurface.h" | |
30 | 32 |
31 | 33 |
32 DEFINE_string2(infile, i, NULL, "Name of file to load JS from.\n"); | 34 DEFINE_string2(infile, i, NULL, "Name of file to load JS from.\n"); |
33 DEFINE_bool(gpu, true, "Use the GPU for rendering."); | 35 DEFINE_bool(gpu, true, "Use the GPU for rendering."); |
34 | 36 |
35 void application_init() { | 37 void application_init() { |
36 SkGraphics::Init(); | 38 SkGraphics::Init(); |
37 SkEvent::Init(); | 39 SkEvent::Init(); |
38 } | 40 } |
39 | 41 |
40 void application_term() { | 42 void application_term() { |
41 SkEvent::Term(); | 43 SkEvent::Term(); |
42 SkGraphics::Term(); | 44 SkGraphics::Term(); |
43 } | 45 } |
44 | 46 |
45 SkV8ExampleWindow::SkV8ExampleWindow(void* hwnd, JsContext* context) | 47 SkV8ExampleWindow::SkV8ExampleWindow(void* hwnd, JsContext* context) |
46 : INHERITED(hwnd) | 48 : INHERITED(hwnd) |
47 , fJsContext(context) | 49 , fJsContext(context) |
48 #if SK_SUPPORT_GPU | 50 #if SK_SUPPORT_GPU |
49 , fCurContext(NULL) | 51 , fCurContext(NULL) |
50 , fCurIntf(NULL) | 52 , fCurIntf(NULL) |
51 , fCurRenderTarget(NULL) | 53 , fCurRenderTarget(NULL) |
54 , fCurSurface(NULL) | |
52 #endif | 55 #endif |
53 { | 56 { |
54 this->setConfig(SkBitmap::kARGB_8888_Config); | 57 this->setColorType(kBGRA_8888_SkColorType); |
55 this->setVisibleP(true); | 58 this->setVisibleP(true); |
56 this->setClipToBounds(false); | 59 this->setClipToBounds(false); |
57 | 60 |
58 #if SK_SUPPORT_GPU | 61 #if SK_SUPPORT_GPU |
59 this->windowSizeChanged(); | 62 this->windowSizeChanged(); |
60 #endif | 63 #endif |
61 } | 64 } |
62 | 65 |
63 #if SK_SUPPORT_GPU | 66 #if SK_SUPPORT_GPU |
64 void SkV8ExampleWindow::windowSizeChanged() { | 67 void SkV8ExampleWindow::windowSizeChanged() { |
(...skipping 20 matching lines...) Expand all Loading... | |
85 desc.fConfig = kSkia8888_GrPixelConfig; | 88 desc.fConfig = kSkia8888_GrPixelConfig; |
86 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; | 89 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
87 desc.fSampleCnt = attachmentInfo.fSampleCount; | 90 desc.fSampleCnt = attachmentInfo.fSampleCount; |
88 desc.fStencilBits = attachmentInfo.fStencilBits; | 91 desc.fStencilBits = attachmentInfo.fStencilBits; |
89 GrGLint buffer; | 92 GrGLint buffer; |
90 GR_GL_GetIntegerv(fCurIntf, GR_GL_FRAMEBUFFER_BINDING, &buffer); | 93 GR_GL_GetIntegerv(fCurIntf, GR_GL_FRAMEBUFFER_BINDING, &buffer); |
91 desc.fRenderTargetHandle = buffer; | 94 desc.fRenderTargetHandle = buffer; |
92 | 95 |
93 SkSafeUnref(fCurRenderTarget); | 96 SkSafeUnref(fCurRenderTarget); |
94 fCurRenderTarget = fCurContext->wrapBackendRenderTarget(desc); | 97 fCurRenderTarget = fCurContext->wrapBackendRenderTarget(desc); |
98 SkSafeUnref(fCurSurface); | |
robertphillips
2014/02/26 23:51:08
Doesn't this need to get cleaned up in the destruc
jcgregorio
2014/02/27 14:23:16
Added SkSafeUnref's for all the GPU related object
| |
99 fCurSurface = SkSurface::NewRenderTargetDirect(fCurRenderTarget); | |
95 } | 100 } |
96 } | 101 } |
97 #endif | 102 #endif |
98 | 103 |
99 #if SK_SUPPORT_GPU | 104 #if SK_SUPPORT_GPU |
robertphillips
2014/02/26 23:51:08
So does the base class not support creating a GPU
jcgregorio
2014/02/27 14:23:16
No, the base class impl is merely new SkCanvas(thi
| |
100 SkCanvas* SkV8ExampleWindow::createCanvas() { | 105 SkCanvas* SkV8ExampleWindow::createCanvas() { |
101 if (FLAGS_gpu) { | 106 if (FLAGS_gpu) { |
102 SkAutoTUnref<SkBaseDevice> device( | 107 SkCanvas* c = fCurSurface->getCanvas(); |
robertphillips
2014/02/26 23:51:08
How isn't there an unbalanced ref problem here? Is
jcgregorio
2014/02/27 14:23:16
Yeah, I would expect that fCurSurface->getCanvas()
| |
103 new SkGpuDevice(fCurContext, fCurRenderTarget)); | 108 // Increase the ref count since the surface keeps a reference |
104 return new SkCanvas(device); | 109 // to the canvas, but callers of createCanvas put the results |
110 // in a SkAutoTUnref. | |
111 c->ref(); | |
112 return c; | |
105 } else { | 113 } else { |
106 return this->INHERITED::createCanvas(); | 114 return this->INHERITED::createCanvas(); |
107 } | 115 } |
108 } | 116 } |
109 #endif | 117 #endif |
110 | 118 |
111 void SkV8ExampleWindow::onSizeChange() { | 119 void SkV8ExampleWindow::onSizeChange() { |
112 this->INHERITED::onSizeChange(); | 120 this->INHERITED::onSizeChange(); |
113 | 121 |
114 #if SK_SUPPORT_GPU | 122 #if SK_SUPPORT_GPU |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
200 | 208 |
201 if (!jsContext->initialize()) { | 209 if (!jsContext->initialize()) { |
202 printf("Failed to initialize.\n"); | 210 printf("Failed to initialize.\n"); |
203 exit(1); | 211 exit(1); |
204 } | 212 } |
205 SkV8ExampleWindow* win = new SkV8ExampleWindow(hwnd, jsContext); | 213 SkV8ExampleWindow* win = new SkV8ExampleWindow(hwnd, jsContext); |
206 global->setWindow(win); | 214 global->setWindow(win); |
207 | 215 |
208 return win; | 216 return win; |
209 } | 217 } |
OLD | NEW |