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

Side by Side Diff: example/HelloWorld.cpp

Issue 2178353005: Remove use of MakeRenderTargetDirect from view system (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix Mac Created 4 years, 4 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
« no previous file with comments | « example/HelloWorld.h ('k') | include/views/SkWindow.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 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 9
10 #include "HelloWorld.h" 10 #include "HelloWorld.h"
(...skipping 11 matching lines...) Expand all
22 SkEvent::Init(); 22 SkEvent::Init();
23 } 23 }
24 24
25 void application_term() { 25 void application_term() {
26 SkEvent::Term(); 26 SkEvent::Term();
27 } 27 }
28 28
29 HelloWorldWindow::HelloWorldWindow(void* hwnd) 29 HelloWorldWindow::HelloWorldWindow(void* hwnd)
30 : INHERITED(hwnd) { 30 : INHERITED(hwnd) {
31 fType = kGPU_DeviceType; 31 fType = kGPU_DeviceType;
32 fRenderTarget = NULL;
33 fRotationAngle = 0; 32 fRotationAngle = 0;
34 this->setTitle(); 33 this->setTitle();
35 this->setUpBackend(); 34 this->setUpBackend();
36 } 35 }
37 36
38 HelloWorldWindow::~HelloWorldWindow() { 37 HelloWorldWindow::~HelloWorldWindow() {
39 tearDownBackend(); 38 tearDownBackend();
40 } 39 }
41 40
42 void HelloWorldWindow::tearDownBackend() { 41 void HelloWorldWindow::tearDownBackend() {
43 SkSafeUnref(fContext); 42 SkSafeUnref(fContext);
44 fContext = NULL; 43 fContext = NULL;
45 44
46 SkSafeUnref(fInterface); 45 SkSafeUnref(fInterface);
47 fInterface = NULL; 46 fInterface = NULL;
48 47
49 SkSafeUnref(fRenderTarget); 48 fGpuSurface = nullptr;
50 fRenderTarget = NULL;
51 49
52 INHERITED::release(); 50 INHERITED::release();
53 } 51 }
54 52
55 void HelloWorldWindow::setTitle() { 53 void HelloWorldWindow::setTitle() {
56 SkString title("Hello World "); 54 SkString title("Hello World ");
57 title.appendf(fType == kRaster_DeviceType ? "raster" : "opengl"); 55 title.appendf(fType == kRaster_DeviceType ? "raster" : "opengl");
58 INHERITED::setTitle(title.c_str()); 56 INHERITED::setTitle(title.c_str());
59 } 57 }
60 58
61 bool HelloWorldWindow::setUpBackend() { 59 bool HelloWorldWindow::setUpBackend() {
62 this->setVisibleP(true); 60 this->setVisibleP(true);
63 this->setClipToBounds(false); 61 this->setClipToBounds(false);
64 62
65 bool result = attach(kNativeGL_BackEndType, 0 /*msaa*/, false, &fAttachmentI nfo); 63 bool result = attach(kNativeGL_BackEndType, 0 /*msaa*/, false, &fAttachmentI nfo);
66 if (false == result) { 64 if (false == result) {
67 SkDebugf("Not possible to create backend.\n"); 65 SkDebugf("Not possible to create backend.\n");
68 release(); 66 release();
69 return false; 67 return false;
70 } 68 }
71 69
72 fInterface = GrGLCreateNativeInterface(); 70 fInterface = GrGLCreateNativeInterface();
73
74 SkASSERT(NULL != fInterface); 71 SkASSERT(NULL != fInterface);
75 72
76 fContext = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)fInterface ); 73 fContext = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)fInterface );
77 SkASSERT(NULL != fContext); 74 SkASSERT(NULL != fContext);
78 75
79 this->setUpRenderTarget(); 76 this->setUpGpuBackedSurface();
80 return true; 77 return true;
81 } 78 }
82 79
83 void HelloWorldWindow::setUpRenderTarget() { 80 void HelloWorldWindow::setUpGpuBackedSurface() {
84 SkSafeUnref(fRenderTarget); 81 fGpuSurface = this->makeGpuBackedSurface(fAttachmentInfo, fInterface, fConte xt);
85 fRenderTarget = this->renderTarget(fAttachmentInfo, fInterface, fContext);
86 } 82 }
87 83
88 void HelloWorldWindow::drawContents(SkCanvas* canvas) { 84 void HelloWorldWindow::drawContents(SkCanvas* canvas) {
89 // Clear background 85 // Clear background
90 canvas->drawColor(SK_ColorWHITE); 86 canvas->drawColor(SK_ColorWHITE);
91 87
92 SkPaint paint; 88 SkPaint paint;
93 paint.setColor(SK_ColorRED); 89 paint.setColor(SK_ColorRED);
94 90
95 // Draw a rectangle with red paint 91 // Draw a rectangle with red paint
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 } 131 }
136 canvas->rotate(fRotationAngle); 132 canvas->rotate(fRotationAngle);
137 133
138 // Draw the text: 134 // Draw the text:
139 canvas->drawText(message, strlen(message), 0, 0, paint); 135 canvas->drawText(message, strlen(message), 0, 0, paint);
140 136
141 canvas->restore(); 137 canvas->restore();
142 } 138 }
143 139
144 void HelloWorldWindow::draw(SkCanvas* canvas) { 140 void HelloWorldWindow::draw(SkCanvas* canvas) {
145 drawContents(canvas); 141 this->drawContents(canvas);
146 // in case we have queued drawing calls 142 // in case we have queued drawing calls
147 fContext->flush(); 143 fContext->flush();
148 // Invalidate the window to force a redraw. Poor man's animation mechanism. 144 // Invalidate the window to force a redraw. Poor man's animation mechanism.
149 this->inval(NULL); 145 this->inval(NULL);
150 146
151 if (kRaster_DeviceType == fType) { 147 if (kRaster_DeviceType == fType) {
152 // need to send the raster bits to the (gpu) window 148 // need to send the raster bits to the (gpu) window
153 sk_sp<SkImage> snap = fSurface->makeImageSnapshot(); 149 sk_sp<SkImage> snap = fRasterSurface->makeImageSnapshot();
154 SkPixmap pmap; 150 SkPixmap pmap;
155 if (snap->peekPixels(&pmap)) { 151 if (snap->peekPixels(&pmap)) {
156 const SkImageInfo& info = pmap.info(); 152 const SkImageInfo& info = pmap.info();
157 fRenderTarget->writePixels(0, 0, snap->width(), snap->height(), 153
158 SkImageInfo2GrPixelConfig(info, *fContext ->caps()), 154 SkCanvas* canvas = fGpuSurface->getCanvas();
159 pmap.addr(), pmap.rowBytes(), 155
160 GrContext::kFlushWrites_PixelOp); 156 canvas->writePixels(info, pmap.addr(), pmap.rowBytes(), 0, 0);
157 canvas->flush();
161 } 158 }
162 } 159 }
163 INHERITED::present(); 160 INHERITED::present();
164 } 161 }
165 162
166 void HelloWorldWindow::onSizeChange() { 163 void HelloWorldWindow::onSizeChange() {
167 setUpRenderTarget(); 164 this->setUpGpuBackedSurface();
168 } 165 }
169 166
170 bool HelloWorldWindow::onHandleChar(SkUnichar unichar) { 167 bool HelloWorldWindow::onHandleChar(SkUnichar unichar) {
171 if (' ' == unichar) { 168 if (' ' == unichar) {
172 fType = fType == kRaster_DeviceType ? kGPU_DeviceType: kRaster_DeviceTyp e; 169 fType = fType == kRaster_DeviceType ? kGPU_DeviceType: kRaster_DeviceTyp e;
173 tearDownBackend(); 170 tearDownBackend();
174 setUpBackend(); 171 setUpBackend();
175 this->setTitle(); 172 this->setTitle();
176 this->inval(NULL); 173 this->inval(NULL);
177 } 174 }
178 return true; 175 return true;
179 } 176 }
180 177
181 SkOSWindow* create_sk_window(void* hwnd, int , char** ) { 178 SkOSWindow* create_sk_window(void* hwnd, int , char** ) {
182 return new HelloWorldWindow(hwnd); 179 return new HelloWorldWindow(hwnd);
183 } 180 }
OLDNEW
« no previous file with comments | « example/HelloWorld.h ('k') | include/views/SkWindow.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698