Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(609)

Unified Diff: samplecode/SampleFilterQuality.cpp

Issue 1810813003: update callsites for Make image factories (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: start to take advantage of sk_sp drawImage Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « samplecode/SampleFilterFuzz.cpp ('k') | samplecode/SampleLayers.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samplecode/SampleFilterQuality.cpp
diff --git a/samplecode/SampleFilterQuality.cpp b/samplecode/SampleFilterQuality.cpp
index 27c092fc476f2e8249fdb16c8641197e6c4909fc..9098901959e64490499e60df8cdc896690416fb6 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()));
}
« no previous file with comments | « samplecode/SampleFilterFuzz.cpp ('k') | samplecode/SampleLayers.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698