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

Side by Side Diff: tools/skiaserve/Request.cpp

Issue 1811703002: return pictures as sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rely on RVO in picturerecorder Created 4 years, 9 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 | « tools/skiaserve/Request.h ('k') | tools/skpmaker.cpp » ('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 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Request.h" 8 #include "Request.h"
9 9
10 #include "png.h" 10 #include "png.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 } 124 }
125 125
126 SkData* Request::writeOutSkp() { 126 SkData* Request::writeOutSkp() {
127 // Playback into picture recorder 127 // Playback into picture recorder
128 SkIRect bounds = this->getBounds(); 128 SkIRect bounds = this->getBounds();
129 SkPictureRecorder recorder; 129 SkPictureRecorder recorder;
130 SkCanvas* canvas = recorder.beginRecording(bounds.width(), bounds.height()); 130 SkCanvas* canvas = recorder.beginRecording(bounds.width(), bounds.height());
131 131
132 fDebugCanvas->draw(canvas); 132 fDebugCanvas->draw(canvas);
133 133
134 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 134 sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
135 135
136 SkDynamicMemoryWStream outStream; 136 SkDynamicMemoryWStream outStream;
137 137
138 SkAutoTUnref<SkPixelSerializer> serializer(SkImageEncoder::CreatePixelSerial izer()); 138 SkAutoTUnref<SkPixelSerializer> serializer(SkImageEncoder::CreatePixelSerial izer());
139 picture->serialize(&outStream, serializer); 139 picture->serialize(&outStream, serializer);
140 140
141 return outStream.copyToData(); 141 return outStream.copyToData();
142 } 142 }
143 143
144 GrContext* Request::getContext() { 144 GrContext* Request::getContext() {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 } 208 }
209 return false; 209 return false;
210 } 210 }
211 fSurface.reset(this->createCPUSurface()); 211 fSurface.reset(this->createCPUSurface());
212 fGPUEnabled = false; 212 fGPUEnabled = false;
213 return true; 213 return true;
214 } 214 }
215 215
216 bool Request::initPictureFromStream(SkStream* stream) { 216 bool Request::initPictureFromStream(SkStream* stream) {
217 // parse picture from stream 217 // parse picture from stream
218 fPicture.reset(SkPicture::CreateFromStream(stream)); 218 fPicture = SkPicture::MakeFromStream(stream);
219 if (!fPicture.get()) { 219 if (!fPicture) {
220 fprintf(stderr, "Could not create picture from stream.\n"); 220 fprintf(stderr, "Could not create picture from stream.\n");
221 return false; 221 return false;
222 } 222 }
223 223
224 // reinitialize canvas with the new picture dimensions 224 // reinitialize canvas with the new picture dimensions
225 this->enableGPU(fGPUEnabled); 225 this->enableGPU(fGPUEnabled);
226 226
227 // pour picture into debug canvas 227 // pour picture into debug canvas
228 SkIRect bounds = this->getBounds(); 228 SkIRect bounds = this->getBounds();
229 fDebugCanvas.reset(new SkDebugCanvas(bounds.width(), bounds.height())); 229 fDebugCanvas.reset(new SkDebugCanvas(bounds.width(), bounds.height()));
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 canvas->flush(); 284 canvas->flush();
285 SkAutoTDelete<SkBitmap> bitmap(this->getBitmapFromCanvas(canvas)); 285 SkAutoTDelete<SkBitmap> bitmap(this->getBitmapFromCanvas(canvas));
286 SkASSERT(bitmap); 286 SkASSERT(bitmap);
287 bitmap->lockPixels(); 287 bitmap->lockPixels();
288 uint8_t* start = ((uint8_t*) bitmap->getPixels()) + (y * bitmap->width() + x ) * 4; 288 uint8_t* start = ((uint8_t*) bitmap->getPixels()) + (y * bitmap->width() + x ) * 4;
289 SkColor result = SkColorSetARGB(start[3], start[0], start[1], start[2]); 289 SkColor result = SkColorSetARGB(start[3], start[0], start[1], start[2]);
290 bitmap->unlockPixels(); 290 bitmap->unlockPixels();
291 return result; 291 return result;
292 } 292 }
293 293
OLDNEW
« no previous file with comments | « tools/skiaserve/Request.h ('k') | tools/skpmaker.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698