OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 <functional> | 8 #include <functional> |
9 #include "gm.h" | 9 #include "gm.h" |
10 #include "SkAutoPixmapStorage.h" | 10 #include "SkAutoPixmapStorage.h" |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 canvas->drawText(kLabel8, strlen(kLabel8), 80, 10, textPaint); | 160 canvas->drawText(kLabel8, strlen(kLabel8), 80, 10, textPaint); |
161 canvas->drawText(kLabel9, strlen(kLabel9), 160, 10, textPaint); | 161 canvas->drawText(kLabel9, strlen(kLabel9), 160, 10, textPaint); |
162 canvas->drawText(kLabel10, strlen(kLabel10), 265, 10, textPaint); | 162 canvas->drawText(kLabel10, strlen(kLabel10), 265, 10, textPaint); |
163 | 163 |
164 canvas->translate(80, 20); | 164 canvas->translate(80, 20); |
165 | 165 |
166 // since we draw into this directly, we need to start fresh | 166 // since we draw into this directly, we need to start fresh |
167 sk_bzero(fBuffer, fBufferSize); | 167 sk_bzero(fBuffer, fBufferSize); |
168 | 168 |
169 SkImageInfo info = SkImageInfo::MakeN32Premul(W, H); | 169 SkImageInfo info = SkImageInfo::MakeN32Premul(W, H); |
170 SkAutoTUnref<SkSurface> surf0(SkSurface::NewRasterDirect(info, fBuffer,
RB)); | 170 sk_sp<SkSurface> surf0(SkSurface::MakeRasterDirect(info, fBuffer, RB)); |
171 SkAutoTUnref<SkSurface> surf1(SkSurface::NewRaster(info)); | 171 sk_sp<SkSurface> surf1(SkSurface::MakeRaster(info)); |
172 SkAutoTUnref<SkSurface> surf2; // gpu | 172 sk_sp<SkSurface> surf2; // gpu |
173 | 173 |
174 #if SK_SUPPORT_GPU | 174 #if SK_SUPPORT_GPU |
175 surf2.reset(SkSurface::NewRenderTarget(canvas->getGrContext(), | 175 surf2 = SkSurface::MakeRenderTarget(canvas->getGrContext(), SkBudgeted::
kNo, info); |
176 SkBudgeted::kNo, info)); | |
177 #endif | 176 #endif |
178 | 177 |
179 test_surface(canvas, surf0, true); | 178 test_surface(canvas, surf0.get(), true); |
180 canvas->translate(80, 0); | 179 canvas->translate(80, 0); |
181 test_surface(canvas, surf1, true); | 180 test_surface(canvas, surf1.get(), true); |
182 if (surf2) { | 181 if (surf2) { |
183 canvas->translate(80, 0); | 182 canvas->translate(80, 0); |
184 test_surface(canvas, surf2, true); | 183 test_surface(canvas, surf2.get(), true); |
185 } | 184 } |
186 } | 185 } |
187 | 186 |
188 private: | 187 private: |
189 typedef skiagm::GM INHERITED; | 188 typedef skiagm::GM INHERITED; |
190 }; | 189 }; |
191 DEF_GM( return new ImageGM; ) | 190 DEF_GM( return new ImageGM; ) |
192 | 191 |
193 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 192 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
194 | 193 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 } | 230 } |
232 | 231 |
233 static void draw_contents(SkCanvas* canvas) { | 232 static void draw_contents(SkCanvas* canvas) { |
234 SkPaint paint; | 233 SkPaint paint; |
235 paint.setStyle(SkPaint::kStroke_Style); | 234 paint.setStyle(SkPaint::kStroke_Style); |
236 paint.setStrokeWidth(20); | 235 paint.setStrokeWidth(20); |
237 canvas->drawCircle(50, 50, 35, paint); | 236 canvas->drawCircle(50, 50, 35, paint); |
238 } | 237 } |
239 | 238 |
240 static sk_sp<SkImage> make_raster(const SkImageInfo& info, GrContext*, void (*dr
aw)(SkCanvas*)) { | 239 static sk_sp<SkImage> make_raster(const SkImageInfo& info, GrContext*, void (*dr
aw)(SkCanvas*)) { |
241 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); | 240 auto surface(SkSurface::MakeRaster(info)); |
242 draw(surface->getCanvas()); | 241 draw(surface->getCanvas()); |
243 return surface->makeImageSnapshot(); | 242 return surface->makeImageSnapshot(); |
244 } | 243 } |
245 | 244 |
246 static sk_sp<SkImage> make_picture(const SkImageInfo& info, GrContext*, void (*d
raw)(SkCanvas*)) { | 245 static sk_sp<SkImage> make_picture(const SkImageInfo& info, GrContext*, void (*d
raw)(SkCanvas*)) { |
247 SkPictureRecorder recorder; | 246 SkPictureRecorder recorder; |
248 draw(recorder.beginRecording(SkRect::MakeIWH(info.width(), info.height()))); | 247 draw(recorder.beginRecording(SkRect::MakeIWH(info.width(), info.height()))); |
249 return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(), | 248 return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(), |
250 info.dimensions(), nullptr, nullptr); | 249 info.dimensions(), nullptr, nullptr); |
251 } | 250 } |
252 | 251 |
253 static sk_sp<SkImage> make_codec(const SkImageInfo& info, GrContext*, void (*dra
w)(SkCanvas*)) { | 252 static sk_sp<SkImage> make_codec(const SkImageInfo& info, GrContext*, void (*dra
w)(SkCanvas*)) { |
254 sk_sp<SkImage> image(make_raster(info, nullptr, draw)); | 253 sk_sp<SkImage> image(make_raster(info, nullptr, draw)); |
255 sk_sp<SkData> data(image->encode()); | 254 sk_sp<SkData> data(image->encode()); |
256 return SkImage::MakeFromEncoded(data); | 255 return SkImage::MakeFromEncoded(data); |
257 } | 256 } |
258 | 257 |
259 static sk_sp<SkImage> make_gpu(const SkImageInfo& info, GrContext* ctx, void (*d
raw)(SkCanvas*)) { | 258 static sk_sp<SkImage> make_gpu(const SkImageInfo& info, GrContext* ctx, void (*d
raw)(SkCanvas*)) { |
260 if (!ctx) { return nullptr; } | 259 if (!ctx) { return nullptr; } |
261 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, SkBudgeted::
kNo, info)); | 260 auto surface(SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info)); |
262 draw(surface->getCanvas()); | 261 draw(surface->getCanvas()); |
263 return surface->makeImageSnapshot(); | 262 return surface->makeImageSnapshot(); |
264 } | 263 } |
265 | 264 |
266 typedef sk_sp<SkImage> (*ImageMakerProc)(const SkImageInfo&, GrContext*, void (*
)(SkCanvas*)); | 265 typedef sk_sp<SkImage> (*ImageMakerProc)(const SkImageInfo&, GrContext*, void (*
)(SkCanvas*)); |
267 | 266 |
268 class ScalePixelsGM : public skiagm::GM { | 267 class ScalePixelsGM : public skiagm::GM { |
269 public: | 268 public: |
270 ScalePixelsGM() {} | 269 ScalePixelsGM() {} |
271 | 270 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 static void draw_opaque_contents(SkCanvas* canvas) { | 327 static void draw_opaque_contents(SkCanvas* canvas) { |
329 canvas->drawColor(0xFFFF8844); | 328 canvas->drawColor(0xFFFF8844); |
330 | 329 |
331 SkPaint paint; | 330 SkPaint paint; |
332 paint.setStyle(SkPaint::kStroke_Style); | 331 paint.setStyle(SkPaint::kStroke_Style); |
333 paint.setStrokeWidth(20); | 332 paint.setStrokeWidth(20); |
334 canvas->drawCircle(50, 50, 35, paint); | 333 canvas->drawCircle(50, 50, 35, paint); |
335 } | 334 } |
336 | 335 |
337 static SkImageGenerator* gen_raster(const SkImageInfo& info) { | 336 static SkImageGenerator* gen_raster(const SkImageInfo& info) { |
338 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); | 337 auto surface(SkSurface::MakeRaster(info)); |
339 draw_opaque_contents(surface->getCanvas()); | 338 draw_opaque_contents(surface->getCanvas()); |
340 return new ImageGeneratorFromImage(surface->makeImageSnapshot().get()); | 339 return new ImageGeneratorFromImage(surface->makeImageSnapshot().get()); |
341 } | 340 } |
342 | 341 |
343 static SkImageGenerator* gen_picture(const SkImageInfo& info) { | 342 static SkImageGenerator* gen_picture(const SkImageInfo& info) { |
344 SkPictureRecorder recorder; | 343 SkPictureRecorder recorder; |
345 draw_opaque_contents(recorder.beginRecording(SkRect::MakeIWH(info.width(), i
nfo.height()))); | 344 draw_opaque_contents(recorder.beginRecording(SkRect::MakeIWH(info.width(), i
nfo.height()))); |
346 sk_sp<SkPicture> pict(recorder.finishRecordingAsPicture()); | 345 sk_sp<SkPicture> pict(recorder.finishRecordingAsPicture()); |
347 return SkImageGenerator::NewFromPicture(info.dimensions(), pict.get(), nullp
tr, nullptr); | 346 return SkImageGenerator::NewFromPicture(info.dimensions(), pict.get(), nullp
tr, nullptr); |
348 } | 347 } |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 // Create a picture image. | 473 // Create a picture image. |
475 [render_image] { | 474 [render_image] { |
476 SkPictureRecorder recorder; | 475 SkPictureRecorder recorder; |
477 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kSize), SkI
ntToScalar(kSize)); | 476 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kSize), SkI
ntToScalar(kSize)); |
478 render_image(canvas); | 477 render_image(canvas); |
479 return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(), | 478 return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(), |
480 SkISize::Make(kSize, kSize), nullptr,
nullptr); | 479 SkISize::Make(kSize, kSize), nullptr,
nullptr); |
481 }, | 480 }, |
482 // Create a texture image | 481 // Create a texture image |
483 [context, render_image]() -> sk_sp<SkImage> { | 482 [context, render_image]() -> sk_sp<SkImage> { |
484 SkAutoTUnref<SkSurface> surface( | 483 auto surface( |
485 SkSurface::NewRenderTarget(context, SkBudgeted::kYes, | 484 SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, |
486 SkImageInfo::MakeN32Premul(kSize, kSi
ze))); | 485 SkImageInfo::MakeN32Premul(kSize, kS
ize))); |
487 if (!surface) { | 486 if (!surface) { |
488 return nullptr; | 487 return nullptr; |
489 } | 488 } |
490 render_image(surface->getCanvas()); | 489 render_image(surface->getCanvas()); |
491 return surface->makeImageSnapshot(); | 490 return surface->makeImageSnapshot(); |
492 } | 491 } |
493 }; | 492 }; |
494 | 493 |
495 static const SkScalar kPad = 5.f; | 494 static const SkScalar kPad = 5.f; |
496 canvas->translate(kPad, kPad); | 495 canvas->translate(kPad, kPad); |
497 for (auto factory : imageFactories) { | 496 for (auto factory : imageFactories) { |
498 auto image(factory()); | 497 auto image(factory()); |
499 if (!image) { | 498 if (!image) { |
500 continue; | 499 continue; |
501 } | 500 } |
502 if (context) { | 501 if (context) { |
503 sk_sp<SkImage> texImage(image->makeTextureImage(context)); | 502 sk_sp<SkImage> texImage(image->makeTextureImage(context)); |
504 if (texImage) { | 503 if (texImage) { |
505 canvas->drawImage(texImage, 0, 0); | 504 canvas->drawImage(texImage, 0, 0); |
506 } | 505 } |
507 } | 506 } |
508 canvas->translate(image->width() + kPad, 0); | 507 canvas->translate(image->width() + kPad, 0); |
509 } | 508 } |
510 } | 509 } |
OLD | NEW |