diff options
author | fmalita <fmalita@chromium.org> | 2015-09-25 09:15:55 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-09-25 09:15:55 -0700 |
commit | 2f5891ea6460675b3c8d08684e1fa8b239bc0a14 (patch) | |
tree | b67a41b8f44935eb74ec797388e4021951b00bfc /gm/bigtileimagefilter.cpp | |
parent | d114645d931d4e95a938597a45a270f211273c17 (diff) |
Remove SkBitmapSource
To avoid breaking existing SKPs, add a deserialization stub which
unflattens SkBitmapSource records to SkImageSources.
R=reed@google.com,mtklein@google.com,robertphillips@google.com
Review URL: https://codereview.chromium.org/1363913002
Diffstat (limited to 'gm/bigtileimagefilter.cpp')
-rw-r--r-- | gm/bigtileimagefilter.cpp | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/gm/bigtileimagefilter.cpp b/gm/bigtileimagefilter.cpp index 3c55b71410..20c462b744 100644 --- a/gm/bigtileimagefilter.cpp +++ b/gm/bigtileimagefilter.cpp @@ -5,21 +5,24 @@ * found in the LICENSE file. */ -#include "SkBitmapSource.h" +#include "SkImageSource.h" +#include "SkSurface.h" #include "SkTileImageFilter.h" #include "gm.h" -static void create_circle_texture(SkBitmap* bm, SkColor color) { - SkCanvas canvas(*bm); - canvas.clear(0xFF000000); +static SkImage* create_circle_texture(int size, SkColor color) { + SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(size, size)); + SkCanvas* canvas = surface->getCanvas(); + canvas->clear(0xFF000000); SkPaint paint; paint.setColor(color); paint.setStrokeWidth(3); paint.setStyle(SkPaint::kStroke_Style); - canvas.drawCircle(SkScalarHalf(bm->width()), SkScalarHalf(bm->height()), - SkScalarHalf(bm->width()), paint); + canvas->drawCircle(SkScalarHalf(size), SkScalarHalf(size), SkScalarHalf(size), paint); + + return surface->newImageSnapshot(); } namespace skiagm { @@ -41,11 +44,8 @@ protected: } void onOnceBeforeDraw() override { - fRedBitmap.allocN32Pixels(kBitmapSize, kBitmapSize); - create_circle_texture(&fRedBitmap, SK_ColorRED); - - fGreenBitmap.allocN32Pixels(kBitmapSize, kBitmapSize); - create_circle_texture(&fGreenBitmap, SK_ColorGREEN); + fRedImage.reset(create_circle_texture(kBitmapSize, SK_ColorRED)); + fGreenImage.reset(create_circle_texture(kBitmapSize, SK_ColorGREEN)); } void onDraw(SkCanvas* canvas) override { @@ -55,11 +55,11 @@ protected: SkPaint p; SkRect bound = SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar(kHeight)); - SkAutoTUnref<SkBitmapSource> bms(SkBitmapSource::Create(fRedBitmap)); + SkAutoTUnref<SkImageFilter> imageSource(SkImageSource::Create(fRedImage)); SkAutoTUnref<SkTileImageFilter> tif(SkTileImageFilter::Create( SkRect::MakeWH(SkIntToScalar(kBitmapSize), SkIntToScalar(kBitmapSize)), SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar(kHeight)), - bms)); + imageSource)); p.setImageFilter(tif); canvas->saveLayer(&bound, &p); @@ -84,8 +84,8 @@ protected: SkRect bound3 = SkRect::MakeXYWH(320, 320, SkIntToScalar(kBitmapSize), SkIntToScalar(kBitmapSize)); - canvas->drawBitmapRect(fGreenBitmap, bound2, bound3, nullptr, - SkCanvas::kStrict_SrcRectConstraint); + canvas->drawImageRect(fGreenImage, bound2, bound3, nullptr, + SkCanvas::kStrict_SrcRectConstraint); canvas->restore(); } } @@ -95,8 +95,8 @@ private: static const int kHeight = 512; static const int kBitmapSize = 64; - SkBitmap fRedBitmap; - SkBitmap fGreenBitmap; + SkAutoTUnref<SkImage> fRedImage; + SkAutoTUnref<SkImage> fGreenImage; typedef GM INHERITED; }; |