aboutsummaryrefslogtreecommitdiffhomepage
path: root/samplecode
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2016-03-17 10:51:11 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-03-17 10:51:11 -0700
commit9ce9d6772df650ceb0511f275e1a83dffa78ff72 (patch)
tree1c0d54a75945863947490ec45cccf7c30eaa2ca4 /samplecode
parent42d95a0afb26560586232961445ba36de387ca37 (diff)
update callsites for Make image factories
not forced yet, as we still have the build-guard. waiting on chrome CL BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1810813003 TBR= Review URL: https://codereview.chromium.org/1810813003
Diffstat (limited to 'samplecode')
-rw-r--r--samplecode/SampleAtlas.cpp10
-rw-r--r--samplecode/SampleFilterFuzz.cpp6
-rw-r--r--samplecode/SampleFilterQuality.cpp46
-rw-r--r--samplecode/SampleLayers.cpp6
-rw-r--r--samplecode/SampleShip.cpp8
-rw-r--r--samplecode/SampleTextureDomain.cpp2
6 files changed, 32 insertions, 46 deletions
diff --git a/samplecode/SampleAtlas.cpp b/samplecode/SampleAtlas.cpp
index a7d5cbe9fd..1075f4d12e 100644
--- a/samplecode/SampleAtlas.cpp
+++ b/samplecode/SampleAtlas.cpp
@@ -39,7 +39,7 @@ static void draw_atlas_sim(SkCanvas* canvas, SkImage* atlas, const SkRSXform xfo
}
}
-static SkImage* make_atlas(int atlasSize, int cellSize) {
+static sk_sp<SkImage> make_atlas(int atlasSize, int cellSize) {
SkImageInfo info = SkImageInfo::MakeN32Premul(atlasSize, atlasSize);
SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info));
SkCanvas* canvas = surface->getCanvas();
@@ -62,7 +62,7 @@ static SkImage* make_atlas(int atlasSize, int cellSize) {
i += 1;
}
}
- return surface->newImageSnapshot();
+ return surface->makeImageSnapshot();
}
class DrawAtlasDrawable : public SkDrawable {
@@ -131,7 +131,7 @@ class DrawAtlasDrawable : public SkDrawable {
N = 256,
};
- SkAutoTUnref<SkImage> fAtlas;
+ sk_sp<SkImage> fAtlas;
Rec fRec[N];
SkRect fTex[N];
SkRect fBounds;
@@ -142,7 +142,7 @@ public:
: fProc(proc), fBounds(r), fUseColors(false)
{
SkRandom rand;
- fAtlas.reset(make_atlas(kAtlasSize, kCellSize));
+ fAtlas = make_atlas(kAtlasSize, kCellSize);
const SkScalar kMaxSpeed = 5;
const SkScalar cell = SkIntToScalar(kCellSize);
int i = 0;
@@ -187,7 +187,7 @@ protected:
const SkRect cull = this->getBounds();
const SkColor* colorsPtr = fUseColors ? colors : nullptr;
- fProc(canvas, fAtlas, xform, fTex, colorsPtr, N, &cull, &paint);
+ fProc(canvas, fAtlas.get(), xform, fTex, colorsPtr, N, &cull, &paint);
}
SkRect onGetBounds() override {
diff --git a/samplecode/SampleFilterFuzz.cpp b/samplecode/SampleFilterFuzz.cpp
index 28155f14fd..81ea2eaed4 100644
--- a/samplecode/SampleFilterFuzz.cpp
+++ b/samplecode/SampleFilterFuzz.cpp
@@ -688,11 +688,11 @@ static SkImageFilter* make_image_filter(bool canBeNull) {
break;
case BITMAP:
{
- SkAutoTUnref<SkImage> image(SkImage::NewFromBitmap(make_bitmap()));
+ sk_sp<SkImage> image(SkImage::MakeFromBitmap(make_bitmap()));
if (R(2) == 1) {
- filter = SkImageSource::Create(image, make_rect(), make_rect(), kHigh_SkFilterQuality);
+ filter = SkImageSource::Create(image.get(), make_rect(), make_rect(), kHigh_SkFilterQuality);
} else {
- filter = SkImageSource::Create(image);
+ filter = SkImageSource::Create(image.get());
}
}
break;
diff --git a/samplecode/SampleFilterQuality.cpp b/samplecode/SampleFilterQuality.cpp
index 27c092fc47..9098901959 100644
--- a/samplecode/SampleFilterQuality.cpp
+++ b/samplecode/SampleFilterQuality.cpp
@@ -28,32 +28,18 @@ static SkSurface* make_surface(SkCanvas* canvas, const SkImageInfo& info) {
}
static sk_sp<SkShader> make_shader(const SkRect& bounds) {
-#if 0
- const SkPoint pts[] = {
- { bounds.left(), bounds.top() },
- { bounds.right(), bounds.bottom() },
- };
- const SkColor colors[] = {
- SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorBLACK,
- SK_ColorCYAN, SK_ColorMAGENTA, SK_ColorYELLOW,
- };
- return SkGradientShader::CreateLinear(pts,
- colors, nullptr, SK_ARRAY_COUNT(colors),
- SkShader::kClamp_TileMode);
-#else
- SkAutoTUnref<SkImage> image(GetResourceAsImage("mandrill_128.png"));
- if (nullptr == image) {
+ sk_sp<SkImage> image(GetResourceAsImage("mandrill_128.png"));
+ if (!image) {
return nullptr;
}
return image->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
-#endif
}
#define N 128
#define ANGLE_DELTA 3
#define SCALE_DELTA (SK_Scalar1 / 32)
-static SkImage* make_image() {
+static sk_sp<SkImage> make_image() {
SkImageInfo info = SkImageInfo::MakeN32(N, N, kOpaque_SkAlphaType);
SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info));
SkCanvas* canvas = surface->getCanvas();
@@ -70,10 +56,10 @@ static SkImage* make_image() {
paint.setShader(make_shader(SkRect::MakeWH(N, N)));
canvas->drawPath(path, paint);
- return surface->newImageSnapshot();
+ return surface->makeImageSnapshot();
}
-static SkImage* zoom_up(SkSurface* origSurf, SkImage* orig) {
+static sk_sp<SkImage> zoom_up(SkSurface* origSurf, SkImage* orig) {
const SkScalar S = 16; // amount to scale up
const int D = 2; // dimension scaling for the offscreen
// since we only view the center, don't need to produce the entire thing
@@ -100,7 +86,7 @@ static SkImage* zoom_up(SkSurface* origSurf, SkImage* orig) {
canvas->drawLine(x, 0, x, SkIntToScalar(orig->height()), paint);
}
}
- return surface->newImageSnapshot();
+ return surface->makeImageSnapshot();
}
struct AnimValue {
@@ -156,12 +142,12 @@ static void draw_box_frame(SkCanvas* canvas, int width, int height) {
}
class FilterQualityView : public SampleView {
- SkAutoTUnref<SkImage> fImage;
- AnimValue fScale, fAngle;
- SkSize fCell;
- SkInterpolator fTrans;
- SkMSec fCurrTime;
- bool fShowFatBits;
+ sk_sp<SkImage> fImage;
+ AnimValue fScale, fAngle;
+ SkSize fCell;
+ SkInterpolator fTrans;
+ SkMSec fCurrTime;
+ bool fShowFatBits;
public:
FilterQualityView() : fImage(make_image()), fTrans(2, 2), fShowFatBits(true) {
@@ -216,7 +202,7 @@ protected:
canvas->translate(SkScalarHalf(size.width()), SkScalarHalf(size.height()));
canvas->scale(fScale, fScale);
canvas->rotate(fAngle);
- canvas->drawImage(fImage, -SkScalarHalf(fImage->width()), -SkScalarHalf(fImage->height()),
+ canvas->drawImage(fImage.get(), -SkScalarHalf(fImage->width()), -SkScalarHalf(fImage->height()),
&paint);
if (false) {
@@ -247,9 +233,9 @@ protected:
this->drawTheImage(canvas, size, filter, dx, dy);
if (surface) {
- SkAutoTUnref<SkImage> orig(surface->newImageSnapshot());
- SkAutoTUnref<SkImage> zoomed(zoom_up(surface, orig));
- origCanvas->drawImage(zoomed,
+ sk_sp<SkImage> orig(surface->makeImageSnapshot());
+ sk_sp<SkImage> zoomed(zoom_up(surface, orig.get()));
+ origCanvas->drawImage(zoomed.get(),
SkScalarHalf(fCell.width() - zoomed->width()),
SkScalarHalf(fCell.height() - zoomed->height()));
}
diff --git a/samplecode/SampleLayers.cpp b/samplecode/SampleLayers.cpp
index beb7e4ae1a..118356872a 100644
--- a/samplecode/SampleLayers.cpp
+++ b/samplecode/SampleLayers.cpp
@@ -244,13 +244,13 @@ DEF_SAMPLE( return new LayersView; )
class BackdropView : public SampleView {
SkPoint fCenter;
SkScalar fAngle;
- SkAutoTUnref<SkImage> fImage;
+ sk_sp<SkImage> fImage;
SkAutoTUnref<SkImageFilter> fFilter;
public:
BackdropView() {
fCenter.set(200, 150);
fAngle = 0;
- fImage.reset(GetResourceAsImage("mandrill_512.png"));
+ fImage = GetResourceAsImage("mandrill_512.png");
fFilter.reset(SkDilateImageFilter::Create(8, 8));
}
@@ -265,7 +265,7 @@ protected:
}
void onDrawContent(SkCanvas* canvas) override {
- canvas->drawImage(fImage, 0, 0, nullptr);
+ canvas->drawImage(fImage.get(), 0, 0, nullptr);
const SkScalar w = 250;
const SkScalar h = 150;
diff --git a/samplecode/SampleShip.cpp b/samplecode/SampleShip.cpp
index fddf0235ba..daaf5e3551 100644
--- a/samplecode/SampleShip.cpp
+++ b/samplecode/SampleShip.cpp
@@ -48,10 +48,10 @@ static void draw_atlas_sim(SkCanvas* canvas, SkImage* atlas, const SkRSXform xfo
class DrawShipView : public SampleView {
public:
DrawShipView(const char name[], DrawAtlasProc proc) : fName(name), fProc(proc) {
- fAtlas.reset(GetResourceAsImage("ship.png"));
+ fAtlas = GetResourceAsImage("ship.png");
if (!fAtlas) {
SkDebugf("\nCould not decode file ship.png. Falling back to penguin mode.\n");
- fAtlas.reset(GetResourceAsImage("baby_tux.png"));
+ fAtlas = GetResourceAsImage("baby_tux.png");
if (!fAtlas) {
SkDebugf("\nCould not decode file baby_tux.png. Did you forget"
" to set the resourcePath?\n");
@@ -146,7 +146,7 @@ protected:
fXform[i].fTy += dy;
}
- fProc(canvas, fAtlas, fXform, fTex, nullptr, kGrid*kGrid+1, nullptr, &paint);
+ fProc(canvas, fAtlas.get(), fXform, fTex, nullptr, kGrid*kGrid+1, nullptr, &paint);
paint.setColor(SK_ColorBLACK);
canvas->drawRect(SkRect::MakeXYWH(0, 0, 200, 24), paint);
paint.setColor(SK_ColorWHITE);
@@ -168,7 +168,7 @@ private:
const char* fName;
DrawAtlasProc fProc;
- SkAutoTUnref<SkImage> fAtlas;
+ sk_sp<SkImage> fAtlas;
SkRSXform fXform[kGrid*kGrid+1];
SkRect fTex[kGrid*kGrid+1];
WallTimer fTimer;
diff --git a/samplecode/SampleTextureDomain.cpp b/samplecode/SampleTextureDomain.cpp
index 65575338c9..2c6dd64301 100644
--- a/samplecode/SampleTextureDomain.cpp
+++ b/samplecode/SampleTextureDomain.cpp
@@ -67,7 +67,7 @@ protected:
surface->getCanvas()->drawBitmapRect(fBM, srcRect, dstRect, &paint,
SkCanvas::kStrict_SrcRectConstraint);
- SkAutoTUnref<SkImage> image(surface->newImageSnapshot());
+ sk_sp<SkImage> image(surface->makeImageSnapshot());
srcRect.setXYWH(1, 1, 3, 3);
dstRect.setXYWH(405, 5, 305, 305);