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 "SkData.h" | 10 #include "SkData.h" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 // since we draw into this directly, we need to start fresh | 170 // since we draw into this directly, we need to start fresh |
171 sk_bzero(fBuffer, fBufferSize); | 171 sk_bzero(fBuffer, fBufferSize); |
172 | 172 |
173 SkImageInfo info = SkImageInfo::MakeN32Premul(W, H); | 173 SkImageInfo info = SkImageInfo::MakeN32Premul(W, H); |
174 SkAutoTUnref<SkSurface> surf0(SkSurface::NewRasterDirect(info, fBuffer,
RB)); | 174 SkAutoTUnref<SkSurface> surf0(SkSurface::NewRasterDirect(info, fBuffer,
RB)); |
175 SkAutoTUnref<SkSurface> surf1(SkSurface::NewRaster(info)); | 175 SkAutoTUnref<SkSurface> surf1(SkSurface::NewRaster(info)); |
176 SkAutoTUnref<SkSurface> surf2; // gpu | 176 SkAutoTUnref<SkSurface> surf2; // gpu |
177 | 177 |
178 #if SK_SUPPORT_GPU | 178 #if SK_SUPPORT_GPU |
179 surf2.reset(SkSurface::NewRenderTarget(canvas->getGrContext(), | 179 surf2.reset(SkSurface::NewRenderTarget(canvas->getGrContext(), |
180 SkBudgeted::kNo, info)); | 180 SkSurface::kNo_Budgeted, info)); |
181 #endif | 181 #endif |
182 | 182 |
183 test_surface(canvas, surf0, true); | 183 test_surface(canvas, surf0, true); |
184 canvas->translate(80, 0); | 184 canvas->translate(80, 0); |
185 test_surface(canvas, surf1, true); | 185 test_surface(canvas, surf1, true); |
186 if (surf2) { | 186 if (surf2) { |
187 canvas->translate(80, 0); | 187 canvas->translate(80, 0); |
188 test_surface(canvas, surf2, true); | 188 test_surface(canvas, surf2, true); |
189 } | 189 } |
190 } | 190 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 } | 255 } |
256 | 256 |
257 static SkImage* make_codec(const SkImageInfo& info, GrContext*, void (*draw)(SkC
anvas*)) { | 257 static SkImage* make_codec(const SkImageInfo& info, GrContext*, void (*draw)(SkC
anvas*)) { |
258 SkAutoTUnref<SkImage> image(make_raster(info, nullptr, draw)); | 258 SkAutoTUnref<SkImage> image(make_raster(info, nullptr, draw)); |
259 SkAutoTUnref<SkData> data(image->encode()); | 259 SkAutoTUnref<SkData> data(image->encode()); |
260 return SkImage::NewFromEncoded(data); | 260 return SkImage::NewFromEncoded(data); |
261 } | 261 } |
262 | 262 |
263 static SkImage* make_gpu(const SkImageInfo& info, GrContext* ctx, void (*draw)(S
kCanvas*)) { | 263 static SkImage* make_gpu(const SkImageInfo& info, GrContext* ctx, void (*draw)(S
kCanvas*)) { |
264 if (!ctx) { return nullptr; } | 264 if (!ctx) { return nullptr; } |
265 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, SkBudgeted::
kNo, info)); | 265 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, SkSurface::k
No_Budgeted, info)); |
266 draw(surface->getCanvas()); | 266 draw(surface->getCanvas()); |
267 return surface->newImageSnapshot(); | 267 return surface->newImageSnapshot(); |
268 } | 268 } |
269 | 269 |
270 typedef SkImage* (*ImageMakerProc)(const SkImageInfo&, GrContext*, void (*)(SkCa
nvas*)); | 270 typedef SkImage* (*ImageMakerProc)(const SkImageInfo&, GrContext*, void (*)(SkCa
nvas*)); |
271 | 271 |
272 class ScalePixelsGM : public skiagm::GM { | 272 class ScalePixelsGM : public skiagm::GM { |
273 public: | 273 public: |
274 ScalePixelsGM() {} | 274 ScalePixelsGM() {} |
275 | 275 |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 [render_image] { | 480 [render_image] { |
481 SkPictureRecorder recorder; | 481 SkPictureRecorder recorder; |
482 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kSize), SkI
ntToScalar(kSize)); | 482 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kSize), SkI
ntToScalar(kSize)); |
483 render_image(canvas); | 483 render_image(canvas); |
484 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | 484 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |
485 return SkImage::NewFromPicture(picture, SkISize::Make(kSize, kSize),
nullptr, nullptr); | 485 return SkImage::NewFromPicture(picture, SkISize::Make(kSize, kSize),
nullptr, nullptr); |
486 }, | 486 }, |
487 // Create a texture image | 487 // Create a texture image |
488 [context, render_image]() -> SkImage* { | 488 [context, render_image]() -> SkImage* { |
489 SkAutoTUnref<SkSurface> surface( | 489 SkAutoTUnref<SkSurface> surface( |
490 SkSurface::NewRenderTarget(context, SkBudgeted::kYes, | 490 SkSurface::NewRenderTarget(context, SkSurface::kYes_Budgeted, |
491 SkImageInfo::MakeN32Premul(kSize, kSi
ze))); | 491 SkImageInfo::MakeN32Premul(kSize, kSi
ze))); |
492 if (!surface) { | 492 if (!surface) { |
493 return nullptr; | 493 return nullptr; |
494 } | 494 } |
495 render_image(surface->getCanvas()); | 495 render_image(surface->getCanvas()); |
496 return surface->newImageSnapshot(); | 496 return surface->newImageSnapshot(); |
497 } | 497 } |
498 }; | 498 }; |
499 | 499 |
500 static const SkScalar kPad = 5.f; | 500 static const SkScalar kPad = 5.f; |
501 canvas->translate(kPad, kPad); | 501 canvas->translate(kPad, kPad); |
502 for (auto factory : imageFactories) { | 502 for (auto factory : imageFactories) { |
503 SkAutoTUnref<SkImage> image(factory()); | 503 SkAutoTUnref<SkImage> image(factory()); |
504 if (!image) { | 504 if (!image) { |
505 continue; | 505 continue; |
506 } | 506 } |
507 if (context) { | 507 if (context) { |
508 SkAutoTUnref<SkImage> texImage(image->newTextureImage(context)); | 508 SkAutoTUnref<SkImage> texImage(image->newTextureImage(context)); |
509 if (texImage) { | 509 if (texImage) { |
510 canvas->drawImage(texImage, 0, 0); | 510 canvas->drawImage(texImage, 0, 0); |
511 } | 511 } |
512 } | 512 } |
513 canvas->translate(image->width() + kPad, 0); | 513 canvas->translate(image->width() + kPad, 0); |
514 } | 514 } |
515 } | 515 } |
OLD | NEW |