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 | |
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')
-rw-r--r-- | gm/bigtileimagefilter.cpp | 34 | ||||
-rw-r--r-- | gm/bitmapsource.cpp | 77 | ||||
-rw-r--r-- | gm/colorcube.cpp | 1 | ||||
-rw-r--r-- | gm/filterfastbounds.cpp | 21 | ||||
-rw-r--r-- | gm/imagefilterscropped.cpp | 1 | ||||
-rw-r--r-- | gm/imagefilterstransformed.cpp | 60 |
6 files changed, 61 insertions, 133 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; }; diff --git a/gm/bitmapsource.cpp b/gm/bitmapsource.cpp deleted file mode 100644 index 155785b200..0000000000 --- a/gm/bitmapsource.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2013 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "gm.h" - -#include "SkBitmapSource.h" - -// This GM exercises the SkBitmapSource ImageFilter class. - -class BitmapSourceGM : public skiagm::GM { -public: - BitmapSourceGM() { - } - -protected: - SkString onShortName() override { - return SkString("bitmapsource"); - } - - SkISize onISize() override { return SkISize::Make(500, 150); } - - void onOnceBeforeDraw() override { - fBitmap = sk_tool_utils::create_string_bitmap(100, 100, 0xFFFFFFFF, 20, 70, 96, "e"); - } - - static void FillRectFiltered(SkCanvas* canvas, const SkRect& clipRect, SkImageFilter* filter) { - SkPaint paint; - paint.setImageFilter(filter); - canvas->save(); - canvas->clipRect(clipRect); - canvas->drawPaint(paint); - canvas->restore(); - } - - void onDraw(SkCanvas* canvas) override { - canvas->clear(SK_ColorBLACK); - { - SkRect srcRect = SkRect::MakeXYWH(20, 20, 30, 30); - SkRect dstRect = SkRect::MakeXYWH(0, 10, 60, 60); - SkRect clipRect = SkRect::MakeXYWH(0, 0, 100, 100); - SkRect bounds; - fBitmap.getBounds(&bounds); - SkAutoTUnref<SkImageFilter> bitmapSource(SkBitmapSource::Create(fBitmap)); - SkAutoTUnref<SkImageFilter> bitmapSourceSrcRect(SkBitmapSource::Create(fBitmap, srcRect, srcRect)); - SkAutoTUnref<SkImageFilter> bitmapSourceSrcRectDstRect(SkBitmapSource::Create(fBitmap, srcRect, dstRect)); - SkAutoTUnref<SkImageFilter> bitmapSourceDstRectOnly(SkBitmapSource::Create(fBitmap, bounds, dstRect)); - - // Draw an unscaled bitmap. - FillRectFiltered(canvas, clipRect, bitmapSource); - canvas->translate(SkIntToScalar(100), 0); - - // Draw an unscaled subset of the source bitmap (srcRect -> srcRect). - FillRectFiltered(canvas, clipRect, bitmapSourceSrcRect); - canvas->translate(SkIntToScalar(100), 0); - - // Draw a subset of the bitmap scaled to a destination rect (srcRect -> dstRect). - FillRectFiltered(canvas, clipRect, bitmapSourceSrcRectDstRect); - canvas->translate(SkIntToScalar(100), 0); - - // Draw the entire bitmap scaled to a destination rect (bounds -> dstRect). - FillRectFiltered(canvas, clipRect, bitmapSourceDstRectOnly); - canvas->translate(SkIntToScalar(100), 0); - } - } - -private: - SkBitmap fBitmap; - typedef GM INHERITED; -}; - -/////////////////////////////////////////////////////////////////////////////// - -DEF_GM( return new BitmapSourceGM; ) diff --git a/gm/colorcube.cpp b/gm/colorcube.cpp index 18de813134..519f88a6a5 100644 --- a/gm/colorcube.cpp +++ b/gm/colorcube.cpp @@ -7,7 +7,6 @@ #include "gm.h" #include "SkColorCubeFilter.h" -#include "SkBitmapSource.h" #include "SkData.h" #include "SkGradientShader.h" diff --git a/gm/filterfastbounds.cpp b/gm/filterfastbounds.cpp index fe06ff1049..dcff05bfcc 100644 --- a/gm/filterfastbounds.cpp +++ b/gm/filterfastbounds.cpp @@ -6,13 +6,14 @@ */ #include "gm.h" -#include "SkBitmapSource.h" #include "SkBlurImageFilter.h" #include "SkDropShadowImageFilter.h" +#include "SkImageSource.h" #include "SkOffsetImageFilter.h" #include "SkPictureImageFilter.h" #include "SkPictureRecorder.h" #include "SkRandom.h" +#include "SkSurface.h" namespace skiagm { @@ -251,24 +252,24 @@ protected: create_paints(pif, &pifPaints); //----------- - // Paints with a BitmapSource as a source - SkBitmap bm; + // Paints with a SkImageSource as a source + SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(10, 10)); { SkPaint p; - bm.allocN32Pixels(10, 10); - SkCanvas temp(bm); - temp.clear(SK_ColorYELLOW); + SkCanvas* temp = surface->getCanvas(); + temp->clear(SK_ColorYELLOW); p.setColor(SK_ColorBLUE); - temp.drawRect(SkRect::MakeLTRB(5, 5, 10, 10), p); + temp->drawRect(SkRect::MakeLTRB(5, 5, 10, 10), p); p.setColor(SK_ColorGREEN); - temp.drawRect(SkRect::MakeLTRB(5, 0, 10, 5), p); + temp->drawRect(SkRect::MakeLTRB(5, 0, 10, 5), p); } - SkAutoTUnref<SkBitmapSource> bms(SkBitmapSource::Create(bm)); + SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); + SkAutoTUnref<SkImageFilter> imageSource(SkImageSource::Create(image)); SkTArray<SkPaint> bmsPaints; - create_paints(bms, &bmsPaints); + create_paints(imageSource, &bmsPaints); //----------- SkASSERT(paints.count() == kNumVertTiles); diff --git a/gm/imagefilterscropped.cpp b/gm/imagefilterscropped.cpp index 92e45ea499..82d538999f 100644 --- a/gm/imagefilterscropped.cpp +++ b/gm/imagefilterscropped.cpp @@ -14,7 +14,6 @@ #include "SkBlurImageFilter.h" #include "SkMorphologyImageFilter.h" #include "SkColorFilterImageFilter.h" -#include "SkBitmapSource.h" #include "SkMergeImageFilter.h" #include "SkOffsetImageFilter.h" #include "SkTestImageFilters.h" diff --git a/gm/imagefilterstransformed.cpp b/gm/imagefilterstransformed.cpp index c6ff5a7931..8e59b9242c 100644 --- a/gm/imagefilterstransformed.cpp +++ b/gm/imagefilterstransformed.cpp @@ -6,14 +6,16 @@ */ #include "sk_tool_utils.h" -#include "SkBitmapSource.h" #include "SkBlurImageFilter.h" #include "SkColor.h" #include "SkDisplacementMapEffect.h" #include "SkDropShadowImageFilter.h" #include "SkGradientShader.h" +#include "SkImage.h" +#include "SkImageSource.h" #include "SkMorphologyImageFilter.h" #include "SkScalar.h" +#include "SkSurface.h" #include "gm.h" namespace skiagm { @@ -22,6 +24,29 @@ namespace skiagm { // It checks that the scale portion of the CTM is correctly extracted // and applied to the image inputs separately from the non-scale portion. +static SkImage* make_gradient_circle(int width, int height) { + SkScalar x = SkIntToScalar(width / 2); + SkScalar y = SkIntToScalar(height / 2); + SkScalar radius = SkMinScalar(x, y) * 0.8f; + + SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(width, height)); + SkCanvas* canvas = surface->getCanvas(); + + canvas->clear(0x00000000); + SkColor colors[2]; + colors[0] = SK_ColorWHITE; + colors[1] = SK_ColorBLACK; + SkAutoTUnref<SkShader> shader( + SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors, nullptr, 2, + SkShader::kClamp_TileMode) + ); + SkPaint paint; + paint.setShader(shader); + canvas->drawCircle(x, y, radius, paint); + + return surface->newImageSnapshot(); +} + class ImageFiltersTransformedGM : public GM { public: ImageFiltersTransformedGM() { @@ -34,34 +59,15 @@ protected: SkISize onISize() override { return SkISize::Make(420, 240); } - void makeGradientCircle(int width, int height) { - SkScalar x = SkIntToScalar(width / 2); - SkScalar y = SkIntToScalar(height / 2); - SkScalar radius = SkMinScalar(x, y) * 0.8f; - fGradientCircle.allocN32Pixels(width, height); - SkCanvas canvas(fGradientCircle); - canvas.clear(0x00000000); - SkColor colors[2]; - colors[0] = SK_ColorWHITE; - colors[1] = SK_ColorBLACK; - SkAutoTUnref<SkShader> shader( - SkGradientShader::CreateRadial(SkPoint::Make(x, y), radius, colors, nullptr, 2, - SkShader::kClamp_TileMode) - ); - SkPaint paint; - paint.setShader(shader); - canvas.drawCircle(x, y, radius, paint); - } - void onOnceBeforeDraw() override { - fCheckerboard = sk_tool_utils::create_checkerboard_bitmap(64, 64, - 0xFFA0A0A0, 0xFF404040, 8); - this->makeGradientCircle(64, 64); + fCheckerboard.reset(SkImage::NewFromBitmap( + sk_tool_utils::create_checkerboard_bitmap(64, 64, 0xFFA0A0A0, 0xFF404040, 8))); + fGradientCircle.reset(make_gradient_circle(64, 64)); } void onDraw(SkCanvas* canvas) override { - SkAutoTUnref<SkImageFilter> gradient(SkBitmapSource::Create(fGradientCircle)); - SkAutoTUnref<SkImageFilter> checkerboard(SkBitmapSource::Create(fCheckerboard)); + SkAutoTUnref<SkImageFilter> gradient(SkImageSource::Create(fGradientCircle)); + SkAutoTUnref<SkImageFilter> checkerboard(SkImageSource::Create(fCheckerboard)); SkImageFilter* filters[] = { SkBlurImageFilter::Create(12, 0), SkDropShadowImageFilter::Create(0, 15, 8, 0, SK_ColorGREEN, @@ -110,8 +116,8 @@ protected: } private: - SkBitmap fCheckerboard; - SkBitmap fGradientCircle; + SkAutoTUnref<SkImage> fCheckerboard; + SkAutoTUnref<SkImage> fGradientCircle; typedef GM INHERITED; }; |