| OLD | NEW |
| 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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 | 149 |
| 150 void HelloWorldWindow::draw(SkCanvas* canvas) { | 150 void HelloWorldWindow::draw(SkCanvas* canvas) { |
| 151 drawContents(canvas); | 151 drawContents(canvas); |
| 152 // in case we have queued drawing calls | 152 // in case we have queued drawing calls |
| 153 fContext->flush(); | 153 fContext->flush(); |
| 154 // Invalidate the window to force a redraw. Poor man's animation mechanism. | 154 // Invalidate the window to force a redraw. Poor man's animation mechanism. |
| 155 this->inval(NULL); | 155 this->inval(NULL); |
| 156 | 156 |
| 157 if (kRaster_DeviceType == fType) { | 157 if (kRaster_DeviceType == fType) { |
| 158 // need to send the raster bits to the (gpu) window | 158 // need to send the raster bits to the (gpu) window |
| 159 SkImage* snap = fSurface->newImageSnapshot(); | 159 sk_sp<SkImage> snap = sk_sp<SkImage>(fSurface->newImageSnapshot()); |
| 160 size_t rowBytes = 0; | 160 SkPixmap pmap; |
| 161 SkImageInfo info; | 161 if (snap->peekPixels(&pmap)) { |
| 162 const void* pixels = snap->peekPixels(&info, &rowBytes); | 162 const SkImageInfo& info = pmap.info(); |
| 163 fRenderTarget->writePixels(0, 0, snap->width(), snap->height(), | 163 fRenderTarget->writePixels(0, 0, snap->width(), snap->height(), |
| 164 SkImageInfo2GrPixelConfig(info.colorType
(), | 164 SkImageInfo2GrPixelConfig(info.color
Type(), |
| 165 info.alphaType()
, | 165 info.alphaTy
pe(), |
| 166 info.profileType
()), | 166 info.profile
Type()), |
| 167 pixels, | 167 pmap.addr(), |
| 168 rowBytes, | 168 pmap.rowBytes(), |
| 169 GrContext::kFlushWrites_PixelOp); | 169 GrContext::kFlushWrites_PixelOp); |
| 170 SkSafeUnref(snap); | 170 } |
| 171 } | 171 } |
| 172 INHERITED::present(); | 172 INHERITED::present(); |
| 173 } | 173 } |
| 174 | 174 |
| 175 void HelloWorldWindow::onSizeChange() { | 175 void HelloWorldWindow::onSizeChange() { |
| 176 setUpRenderTarget(); | 176 setUpRenderTarget(); |
| 177 } | 177 } |
| 178 | 178 |
| 179 bool HelloWorldWindow::onHandleChar(SkUnichar unichar) { | 179 bool HelloWorldWindow::onHandleChar(SkUnichar unichar) { |
| 180 if (' ' == unichar) { | 180 if (' ' == unichar) { |
| 181 fType = fType == kRaster_DeviceType ? kGPU_DeviceType: kRaster_DeviceTyp
e; | 181 fType = fType == kRaster_DeviceType ? kGPU_DeviceType: kRaster_DeviceTyp
e; |
| 182 tearDownBackend(); | 182 tearDownBackend(); |
| 183 setUpBackend(); | 183 setUpBackend(); |
| 184 this->setTitle(); | 184 this->setTitle(); |
| 185 this->inval(NULL); | 185 this->inval(NULL); |
| 186 } | 186 } |
| 187 return true; | 187 return true; |
| 188 } | 188 } |
| 189 | 189 |
| 190 SkOSWindow* create_sk_window(void* hwnd, int , char** ) { | 190 SkOSWindow* create_sk_window(void* hwnd, int , char** ) { |
| 191 return new HelloWorldWindow(hwnd); | 191 return new HelloWorldWindow(hwnd); |
| 192 } | 192 } |
| OLD | NEW |