*/
#include "Benchmark.h"
-#include "SkBitmapSource.h"
#include "SkCanvas.h"
#include "SkDisplacementMapEffect.h"
+#include "SkImageSource.h"
+#include "SkSurface.h"
#define FILTER_WIDTH_SMALL 32
#define FILTER_HEIGHT_SMALL 32
void makeCheckerboard() {
const int w = this->isSmall() ? FILTER_WIDTH_SMALL : FILTER_WIDTH_LARGE;
const int h = this->isSmall() ? FILTER_HEIGHT_LARGE : FILTER_HEIGHT_LARGE;
- fCheckerboard.allocN32Pixels(w, h);
- SkCanvas canvas(fCheckerboard);
- canvas.clear(0x00000000);
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(w, h));
+ SkCanvas* canvas = surface->getCanvas();
+ canvas->clear(0x00000000);
SkPaint darkPaint;
darkPaint.setColor(0xFF804020);
SkPaint lightPaint;
lightPaint.setColor(0xFF244484);
for (int y = 0; y < h; y += 16) {
for (int x = 0; x < w; x += 16) {
- canvas.save();
- canvas.translate(SkIntToScalar(x), SkIntToScalar(y));
- canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint);
- canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint);
- canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint);
- canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint);
- canvas.restore();
+ canvas->save();
+ canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
+ canvas->drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint);
+ canvas->drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint);
+ canvas->drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint);
+ canvas->drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint);
+ canvas->restore();
}
}
+
+ fCheckerboard.reset(surface->newImageSnapshot());
}
void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& paint) {
inline bool isSmall() const { return fIsSmall; }
- SkBitmap fBitmap, fCheckerboard;
+ SkBitmap fBitmap;
+ SkAutoTUnref<SkImage> fCheckerboard;
+
private:
bool fInitialized;
bool fIsSmall;
void onDraw(const int loops, SkCanvas* canvas) override {
SkPaint paint;
- SkAutoTUnref<SkImageFilter> displ(SkBitmapSource::Create(fCheckerboard));
+ SkAutoTUnref<SkImageFilter> displ(SkImageSource::Create(fCheckerboard));
// No displacement effect
paint.setImageFilter(SkDisplacementMapEffect::Create(
SkDisplacementMapEffect::kR_ChannelSelectorType,
void onDraw(const int loops, SkCanvas* canvas) override {
SkPaint paint;
- SkAutoTUnref<SkImageFilter> displ(SkBitmapSource::Create(fCheckerboard));
+ SkAutoTUnref<SkImageFilter> displ(SkImageSource::Create(fCheckerboard));
// Displacement, with 1 alpha component (which isn't pre-multiplied)
paint.setImageFilter(SkDisplacementMapEffect::Create(
SkDisplacementMapEffect::kB_ChannelSelectorType,
void onDraw(const int loops, SkCanvas* canvas) override {
SkPaint paint;
- SkAutoTUnref<SkImageFilter> displ(SkBitmapSource::Create(fCheckerboard));
+ SkAutoTUnref<SkImageFilter> displ(SkImageSource::Create(fCheckerboard));
// Displacement, with 2 non-alpha components
paint.setImageFilter(SkDisplacementMapEffect::Create(
SkDisplacementMapEffect::kR_ChannelSelectorType,
*/
#include "Benchmark.h"
-#include "SkBitmapSource.h"
#include "SkCanvas.h"
+#include "SkImageSource.h"
#include "SkMergeImageFilter.h"
+#include "SkSurface.h"
#define FILTER_WIDTH_SMALL SkIntToScalar(32)
#define FILTER_HEIGHT_SMALL SkIntToScalar(32)
private:
SkImageFilter* mergeBitmaps() {
- SkImageFilter* first = SkBitmapSource::Create(fCheckerboard);
- SkImageFilter* second = SkBitmapSource::Create(fBitmap);
- SkAutoUnref aur0(first);
- SkAutoUnref aur1(second);
+ SkAutoTUnref<SkImageFilter> first(SkImageSource::Create(fCheckerboard));
+ SkAutoTUnref<SkImageFilter> second(SkImageSource::Create(fImage));
return SkMergeImageFilter::Create(first, second);
}
void make_bitmap() {
- fBitmap.allocN32Pixels(80, 80);
- SkCanvas canvas(fBitmap);
- canvas.clear(0x00000000);
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(80, 80));
+ surface->getCanvas()->clear(0x00000000);
SkPaint paint;
paint.setAntiAlias(true);
paint.setColor(0xFF884422);
paint.setTextSize(SkIntToScalar(96));
const char* str = "g";
- canvas.drawText(str, strlen(str), SkIntToScalar(15), SkIntToScalar(55), paint);
+ surface->getCanvas()->drawText(str, strlen(str), 15, 55, paint);
+ fImage.reset(surface->newImageSnapshot());
}
void make_checkerboard() {
- fCheckerboard.allocN32Pixels(80, 80);
- SkCanvas canvas(fCheckerboard);
- canvas.clear(0x00000000);
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(80, 80));
+ SkCanvas* canvas = surface->getCanvas();
+ canvas->clear(0x00000000);
SkPaint darkPaint;
darkPaint.setColor(0xFF804020);
SkPaint lightPaint;
lightPaint.setColor(0xFF244484);
for (int y = 0; y < 80; y += 16) {
for (int x = 0; x < 80; x += 16) {
- canvas.save();
- canvas.translate(SkIntToScalar(x), SkIntToScalar(y));
- canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint);
- canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint);
- canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint);
- canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint);
- canvas.restore();
+ canvas->save();
+ canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
+ canvas->drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint);
+ canvas->drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint);
+ canvas->drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint);
+ canvas->drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint);
+ canvas->restore();
}
}
+
+ fCheckerboard.reset(surface->newImageSnapshot());
}
bool fIsSmall;
bool fInitialized;
- SkBitmap fBitmap, fCheckerboard;
+ SkAutoTUnref<SkImage> fImage, fCheckerboard;
typedef Benchmark INHERITED;
};
+++ /dev/null
-/*
- * Copyright 2015 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"
-
-namespace skiagm {
-
-// This GM reproduces the issue in crbug.com/472795. The SkBitmapSource image
-// is shifted for high quality mode between cpu and gpu.
-class BitmapSourceGM : public GM {
-public:
- BitmapSourceGM(const char* suffix, SkFilterQuality filter) : fSuffix(suffix), fFilter(filter) {
- this->setBGColor(0xFFFFFFFF);
- }
-
-protected:
- SkString onShortName() override {
- SkString name("bitmapsrc2_");
- name.append(fSuffix);
- return name;
- }
-
- SkISize onISize() override { return SkISize::Make(256, 256); }
-
- // Create a bitmap with high frequency vertical stripes
- void onOnceBeforeDraw() override {
- static const SkPMColor gColors[] = {
- SK_ColorRED, SK_ColorGRAY,
- SK_ColorGREEN, SK_ColorGRAY,
- SK_ColorBLUE, SK_ColorGRAY,
- SK_ColorCYAN, SK_ColorGRAY,
- SK_ColorMAGENTA, SK_ColorGRAY,
- SK_ColorYELLOW, SK_ColorGRAY,
- SK_ColorWHITE, SK_ColorGRAY,
- };
-
- fBM.allocN32Pixels(kImageSize, kImageSize, true);
-
- SkCanvas canvas(fBM);
-
- int curColor = 0;
-
- for (int x = 0; x < kImageSize; x += 3) {
- SkRect r = SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(0),
- SkIntToScalar(3), SkIntToScalar(kImageSize));
- SkPaint p;
- p.setColor(gColors[curColor]);
- canvas.drawRect(r, p);
-
- curColor = (curColor+1) % SK_ARRAY_COUNT(gColors);
- }
- }
-
- void onDraw(SkCanvas* canvas) override {
- SkRect srcRect = SkRect::MakeLTRB(0, 0,
- SkIntToScalar(kImageSize), SkIntToScalar(kImageSize));
- SkRect dstRect = SkRect::MakeLTRB(0.75f, 0.75f, 225.75f, 225.75f);
-
- SkAutoTUnref<SkImageFilter> filter(SkBitmapSource::Create(fBM, srcRect, dstRect, fFilter));
-
- SkPaint p;
- p.setImageFilter(filter);
-
- canvas->saveLayer(nullptr, &p);
- canvas->restore();
- }
-
-private:
- static const int kImageSize = 503;
-
- SkString fSuffix;
- SkFilterQuality fFilter;
- SkBitmap fBM;
-
- typedef GM INHERITED;
-};
-
-//////////////////////////////////////////////////////////////////////////////
-
-DEF_GM(return new BitmapSourceGM("none", kNone_SkFilterQuality);)
-DEF_GM(return new BitmapSourceGM("low", kLow_SkFilterQuality);)
-DEF_GM(return new BitmapSourceGM("med", kMedium_SkFilterQuality);)
-DEF_GM(return new BitmapSourceGM("high", kHigh_SkFilterQuality);)
-}
* found in the LICENSE file.
*/
-#include "SkBitmapSource.h"
#include "SkDisplacementMapEffect.h"
+#include "SkImage.h"
+#include "SkImageSource.h"
#include "gm.h"
#include "sk_tool_utils.h"
SkColor c1 = sk_tool_utils::color_to_565(0xFF244484);
SkColor c2 = sk_tool_utils::color_to_565(0xFF804020);
- fCheckerboard = sk_tool_utils::create_checkerboard_bitmap(80, 80, c1, c2, 8);
- fSmall = sk_tool_utils::create_checkerboard_bitmap(64, 64, c1, c2, 8);
- fLarge = sk_tool_utils::create_checkerboard_bitmap(96, 96, c1, c2, 8);
- fLargeW = sk_tool_utils::create_checkerboard_bitmap(96, 64, c1, c2, 8);
- fLargeH = sk_tool_utils::create_checkerboard_bitmap(64, 96, c1, c2, 8);
+ fCheckerboard.reset(SkImage::NewFromBitmap(
+ sk_tool_utils::create_checkerboard_bitmap(80, 80, c1, c2, 8)));
+ fSmall.reset(SkImage::NewFromBitmap(
+ sk_tool_utils::create_checkerboard_bitmap(64, 64, c1, c2, 8)));
+ fLarge.reset(SkImage::NewFromBitmap(
+ sk_tool_utils::create_checkerboard_bitmap(96, 96, c1, c2, 8)));
+ fLargeW.reset(
+ SkImage::NewFromBitmap(sk_tool_utils::create_checkerboard_bitmap(96, 64, c1, c2, 8)));
+ fLargeH.reset(SkImage::NewFromBitmap(
+ sk_tool_utils::create_checkerboard_bitmap(64, 96, c1, c2, 8)));
}
SkISize onISize() override {
void onDraw(SkCanvas* canvas) override {
canvas->clear(SK_ColorBLACK);
SkPaint paint;
- SkAutoTUnref<SkImageFilter> displ(SkBitmapSource::Create(fCheckerboard));
+ SkAutoTUnref<SkImageFilter> displ(SkImageSource::Create(fCheckerboard));
paint.setImageFilter(SkDisplacementMapEffect::Create(
SkDisplacementMapEffect::kR_ChannelSelectorType,
SkDisplacementMapEffect::kG_ChannelSelectorType, 0.0f, displ))->unref();
drawClippedBitmap(canvas, 400, 300, paint);
// Tests for images of different sizes
- displ.reset(SkBitmapSource::Create(fSmall));
+ displ.reset(SkImageSource::Create(fSmall));
paint.setImageFilter(SkDisplacementMapEffect::Create(
SkDisplacementMapEffect::kR_ChannelSelectorType,
SkDisplacementMapEffect::kG_ChannelSelectorType,
40.0f, displ))->unref();
drawClippedBitmap(canvas, 0, 400, paint);
- displ.reset(SkBitmapSource::Create(fLarge));
+ displ.reset(SkImageSource::Create(fLarge));
paint.setImageFilter(SkDisplacementMapEffect::Create(
SkDisplacementMapEffect::kB_ChannelSelectorType,
SkDisplacementMapEffect::kA_ChannelSelectorType,
40.0f, displ))->unref();
drawClippedBitmap(canvas, 100, 400, paint);
- displ.reset(SkBitmapSource::Create(fLargeW));
+ displ.reset(SkImageSource::Create(fLargeW));
paint.setImageFilter(SkDisplacementMapEffect::Create(
SkDisplacementMapEffect::kR_ChannelSelectorType,
SkDisplacementMapEffect::kB_ChannelSelectorType,
40.0f, displ))->unref();
drawClippedBitmap(canvas, 200, 400, paint);
- displ.reset(SkBitmapSource::Create(fLargeH));
+ displ.reset(SkImageSource::Create(fLargeH));
paint.setImageFilter(SkDisplacementMapEffect::Create(
SkDisplacementMapEffect::kG_ChannelSelectorType,
SkDisplacementMapEffect::kA_ChannelSelectorType,
}
private:
- SkBitmap fBitmap, fCheckerboard, fSmall, fLarge, fLargeW, fLargeH;
+ SkBitmap fBitmap;
+ SkAutoTUnref<SkImage> fCheckerboard, fSmall, fLarge, fLargeW, fLargeH;
typedef GM INHERITED;
};
*/
#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 "SkLightingImageFilter.h"
#include "SkMorphologyImageFilter.h"
#include "SkOffsetImageFilter.h"
#include "SkPoint3.h"
#include "SkRectShaderImageFilter.h"
#include "SkScalar.h"
+#include "SkSurface.h"
#include "gm.h"
#define RESIZE_FACTOR_X SkIntToScalar(2)
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);
+ 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;
);
SkPaint paint;
paint.setShader(shader);
- canvas.drawCircle(x, y, radius, paint);
+ canvas->drawCircle(x, y, radius, paint);
+ fGradientCircle.reset(surface->newImageSnapshot());
}
static void draw_clipped_filter(SkCanvas* canvas, SkImageFilter* filter, size_t i,
}
void onOnceBeforeDraw() override {
- fCheckerboard = sk_tool_utils::create_checkerboard_bitmap(64, 64,
- 0xFFA0A0A0, 0xFF404040, 8);
+ fCheckerboard.reset(SkImage::NewFromBitmap
+ (sk_tool_utils::create_checkerboard_bitmap(64, 64, 0xFFA0A0A0, 0xFF404040, 8)));
this->makeGradientCircle(64, 64);
}
void onDraw(SkCanvas* canvas) override {
canvas->clear(SK_ColorBLACK);
- SkAutoTUnref<SkImageFilter> gradient(SkBitmapSource::Create(fGradientCircle));
- SkAutoTUnref<SkImageFilter> checkerboard(SkBitmapSource::Create(fCheckerboard));
+ SkAutoTUnref<SkImageFilter> gradient(SkImageSource::Create(fGradientCircle));
+ SkAutoTUnref<SkImageFilter> checkerboard(SkImageSource::Create(fCheckerboard));
SkAutoTUnref<SkShader> noise(SkPerlinNoiseShader::CreateFractalNoise(
SkDoubleToScalar(0.1), SkDoubleToScalar(0.05), 1, 0));
SkMatrix resizeMatrix;
SkSafeUnref(filters[i]);
}
- SkImageFilter* rectFilter = SkRectShaderImageFilter::Create(noise);
+ SkAutoTUnref<SkImageFilter> rectFilter(SkRectShaderImageFilter::Create(noise));
canvas->translate(SK_ARRAY_COUNT(filters)*(r.width() + margin), 0);
for (int xOffset = 0; xOffset < 80; xOffset += 16) {
bounds.fLeft = SkIntToScalar(xOffset);
draw_clipped_filter(canvas, rectFilter, 0, r, bounds);
canvas->translate(0, r.height() + margin);
}
- SkSafeUnref(rectFilter);
}
private:
- SkBitmap fCheckerboard;
- SkBitmap fGradientCircle;
+ SkAutoTUnref<SkImage> fCheckerboard, fGradientCircle;
typedef GM INHERITED;
};
#include "SkColorPriv.h"
#include "SkShader.h"
-#include "SkBitmapSource.h"
#include "SkBlurImageFilter.h"
#include "SkColorMatrixFilter.h"
#include "SkDisplacementMapEffect.h"
#include "SkDropShadowImageFilter.h"
#include "SkGradientShader.h"
+#include "SkImageSource.h"
#include "SkMorphologyImageFilter.h"
#include "SkColorFilterImageFilter.h"
#include "SkMergeImageFilter.h"
#include "SkOffsetImageFilter.h"
+#include "SkSurface.h"
///////////////////////////////////////////////////////////////////////////////
protected:
- virtual SkString onShortName() {
+ SkString onShortName() override {
return SkString("imagefilterscropexpand");
}
- virtual SkISize onISize() { return SkISize::Make(570, 650); }
+ SkISize onISize() override { return SkISize::Make(570, 650); }
- void make_checkerboard(SkBitmap* bitmap) {
+ void onDraw(SkCanvas* canvas) override {
+ SkAutoTUnref<SkColorFilter> cf(
+ SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode));
+ SkImageFilter::CropRect cropRect(
+ SkRect::Make(SkIRect::MakeXYWH(10, 10, 44, 44)),
+ SkImageFilter::CropRect::kHasAll_CropEdge);
+
+ SkAutoTUnref<SkImage> gradientCircle(MakeGradientCircle(64, 64));
+ SkBitmap checkerboard;
+ MakeCheckerboard(&checkerboard);
+
+ SkAutoTUnref<SkImageFilter> gradientCircleSource(
+ SkImageSource::Create(gradientCircle));
+ SkAutoTUnref<SkImageFilter> noopCropped(
+ SkOffsetImageFilter::Create(0, 0, nullptr, &cropRect));
+ SkScalar sk255 = SkIntToScalar(255);
+ SkScalar matrix[20] = { 1, 0, 0, 0, 0,
+ 0, 1, 0, 0, sk255,
+ 0, 0, 1, 0, 0,
+ 0, 0, 0, 0, sk255 };
+ SkAutoTUnref<SkColorFilter> cfAlphaTrans(SkColorMatrixFilter::Create(matrix));
+
+ SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64));
+ SkScalar MARGIN = SkIntToScalar(12);
+
+ SkIRect bounds;
+ r.roundOut(&bounds);
+
+ SkPaint paint;
+ canvas->translate(MARGIN, MARGIN);
+ for (int outset = -15; outset <= 20; outset += 5) {
+ canvas->save();
+ SkRect rect = cropRect.rect();
+ rect.outset(SkIntToScalar(outset),
+ SkIntToScalar(outset));
+ SkImageFilter::CropRect big_rect(rect, SkImageFilter::CropRect::kHasAll_CropEdge);
+
+ Draw(canvas, checkerboard, rect, SkColorFilterImageFilter::Create(
+ cfAlphaTrans, noopCropped.get(), &big_rect));
+
+ Draw(canvas, checkerboard, rect, SkBlurImageFilter::Create(
+ 8.0f, 8.0f, noopCropped.get(), &big_rect));
+
+ Draw(canvas, checkerboard, rect, SkDilateImageFilter::Create(
+ 2, 2, noopCropped.get(), &big_rect));
+
+ Draw(canvas, checkerboard, rect, SkErodeImageFilter::Create(
+ 2, 2, noopCropped.get(), &big_rect));
+
+ Draw(canvas, checkerboard, rect, SkDropShadowImageFilter::Create(
+ SkIntToScalar(10), SkIntToScalar(10), SkIntToScalar(3), SkIntToScalar(3),
+ SK_ColorBLUE, SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode,
+ noopCropped.get(), &big_rect));
+
+ Draw(canvas, checkerboard, rect, SkDisplacementMapEffect::Create(
+ SkDisplacementMapEffect::kR_ChannelSelectorType,
+ SkDisplacementMapEffect::kR_ChannelSelectorType,
+ SkIntToScalar(12),
+ gradientCircleSource.get(),
+ noopCropped.get(),
+ &big_rect));
+
+ Draw(canvas, checkerboard, rect, SkOffsetImageFilter::Create(
+ SkIntToScalar(-8), SkIntToScalar(16), noopCropped.get(), &big_rect));
+
+ canvas->restore();
+ canvas->translate(0, SkIntToScalar(80));
+ }
+ }
+
+private:
+ static void MakeCheckerboard(SkBitmap* bitmap) {
bitmap->allocN32Pixels(64, 64);
SkCanvas canvas(*bitmap);
canvas.clear(0xFFFF0000);
}
}
- void make_gradient_circle(int width, int height, SkBitmap* bitmap) {
+ static SkImage* MakeGradientCircle(int width, int height) {
SkScalar x = SkIntToScalar(width / 2);
SkScalar y = SkIntToScalar(height / 2);
SkScalar radius = SkMinScalar(x, y) * 0.8f;
- bitmap->allocN32Pixels(width, height);
- SkCanvas canvas(*bitmap);
- canvas.clear(0x00000000);
+ 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;
);
SkPaint paint;
paint.setShader(shader);
- canvas.drawCircle(x, y, radius, paint);
+ canvas->drawCircle(x, y, radius, paint);
+
+ return surface->newImageSnapshot();
}
- static void draw(SkCanvas* canvas, const SkBitmap& bitmap, const SkRect& rect, SkImageFilter* filter) {
+ static void Draw(SkCanvas* canvas, const SkBitmap& bitmap, const SkRect& rect, SkImageFilter* filter) {
SkPaint paint;
paint.setImageFilter(filter)->unref();
canvas->saveLayer(&rect, &paint);
canvas->translate(SkIntToScalar(80), 0);
}
- virtual void onDraw(SkCanvas* canvas) {
- SkAutoTUnref<SkColorFilter> cf(
- SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode));
- SkImageFilter::CropRect crop_rect(
- SkRect::Make(SkIRect::MakeXYWH(10, 10, 44, 44)),
- SkImageFilter::CropRect::kHasAll_CropEdge);
-
- SkBitmap gradient_circle, checkerboard;
- make_gradient_circle(64, 64, &gradient_circle);
- make_checkerboard(&checkerboard);
-
- SkAutoTUnref<SkImageFilter> gradient_circle_source(
- SkBitmapSource::Create(gradient_circle));
- SkAutoTUnref<SkImageFilter> noop_cropped(
- SkOffsetImageFilter::Create(0, 0, nullptr, &crop_rect));
- SkScalar sk255 = SkIntToScalar(255);
- SkScalar matrix[20] = { 1, 0, 0, 0, 0,
- 0, 1, 0, 0, sk255,
- 0, 0, 1, 0, 0,
- 0, 0, 0, 0, sk255 };
- SkAutoTUnref<SkColorFilter> cf_alpha_trans(SkColorMatrixFilter::Create(matrix));
-
- SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64));
- SkScalar MARGIN = SkIntToScalar(12);
-
- SkIRect bounds;
- r.roundOut(&bounds);
-
- SkPaint paint;
- canvas->translate(MARGIN, MARGIN);
- for (int outset = -15; outset <= 20; outset += 5) {
- canvas->save();
- SkRect rect = crop_rect.rect();
- rect.outset(SkIntToScalar(outset),
- SkIntToScalar(outset));
- SkImageFilter::CropRect big_rect(rect, SkImageFilter::CropRect::kHasAll_CropEdge);
-
- draw(canvas, checkerboard, rect, SkColorFilterImageFilter::Create(
- cf_alpha_trans, noop_cropped.get(), &big_rect));
-
- draw(canvas, checkerboard, rect, SkBlurImageFilter::Create(
- 8.0f, 8.0f, noop_cropped.get(), &big_rect));
-
- draw(canvas, checkerboard, rect, SkDilateImageFilter::Create(
- 2, 2, noop_cropped.get(), &big_rect));
-
- draw(canvas, checkerboard, rect, SkErodeImageFilter::Create(
- 2, 2, noop_cropped.get(), &big_rect));
-
- draw(canvas, checkerboard, rect, SkDropShadowImageFilter::Create(
- SkIntToScalar(10), SkIntToScalar(10), SkIntToScalar(3), SkIntToScalar(3),
- SK_ColorBLUE, SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode,
- noop_cropped.get(), &big_rect));
-
- draw(canvas, checkerboard, rect, SkDisplacementMapEffect::Create(
- SkDisplacementMapEffect::kR_ChannelSelectorType,
- SkDisplacementMapEffect::kR_ChannelSelectorType,
- SkIntToScalar(12),
- gradient_circle_source.get(),
- noop_cropped.get(),
- &big_rect));
-
- draw(canvas, checkerboard, rect, SkOffsetImageFilter::Create(
- SkIntToScalar(-8), SkIntToScalar(16), noop_cropped.get(), &big_rect));
-
- canvas->restore();
- canvas->translate(0, SkIntToScalar(80));
- }
- }
-
-private:
typedef GM INHERITED;
};
#include "SkArithmeticMode.h"
#include "SkDevice.h"
-#include "SkBitmapSource.h"
#include "SkBlurImageFilter.h"
#include "SkColorFilter.h"
#include "SkColorFilterImageFilter.h"
#include "SkColorMatrixFilter.h"
+#include "SkImage.h"
+#include "SkImageSource.h"
#include "SkReadBuffer.h"
#include "SkWriteBuffer.h"
#include "SkMergeImageFilter.h"
return SkString("imagefiltersgraph");
}
- void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPaint& paint) {
- canvas->save();
- canvas->clipRect(SkRect::MakeXYWH(0, 0,
- SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height())));
- canvas->drawBitmap(bitmap, 0, 0, &paint);
- canvas->restore();
- }
-
SkISize onISize() override { return SkISize::Make(500, 150); }
void onOnceBeforeDraw() override {
- fBitmap = sk_tool_utils::create_string_bitmap(100, 100, SK_ColorWHITE, 20, 70, 96, "e");
+ fImage.reset(SkImage::NewFromBitmap(
+ sk_tool_utils::create_string_bitmap(100, 100, SK_ColorWHITE, 20, 70, 96, "e")));
}
void onDraw(SkCanvas* canvas) override {
canvas->clear(SK_ColorBLACK);
{
- SkAutoTUnref<SkImageFilter> bitmapSource(SkBitmapSource::Create(fBitmap));
+ SkAutoTUnref<SkImageFilter> bitmapSource(SkImageSource::Create(fImage));
SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorRED,
SkXfermode::kSrcIn_Mode));
SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(4.0f, 4.0f, bitmapSource));
SkPaint paint;
paint.setImageFilter(blendColor);
- drawClippedBitmap(canvas, fBitmap, paint);
+ DrawClippedImage(canvas, fImage, paint);
canvas->translate(SkIntToScalar(100), 0);
}
{
SkPaint paint;
paint.setImageFilter(arithFilter);
- drawClippedBitmap(canvas, fBitmap, paint);
+ DrawClippedImage(canvas, fImage, paint);
canvas->translate(SkIntToScalar(100), 0);
}
{
SkPaint paint;
paint.setImageFilter(blend);
- drawClippedBitmap(canvas, fBitmap, paint);
+ DrawClippedImage(canvas, fImage, paint);
canvas->translate(SkIntToScalar(100), 0);
}
{
}
private:
+ static void DrawClippedImage(SkCanvas* canvas, const SkImage* image, const SkPaint& paint) {
+ canvas->save();
+ canvas->clipRect(SkRect::MakeIWH(image->width(), image->height()));
+ canvas->drawImage(image, 0, 0, &paint);
+ canvas->restore();
+ }
+
+ SkAutoTUnref<SkImage> fImage;
+
typedef GM INHERITED;
- SkBitmap fBitmap;
};
///////////////////////////////////////////////////////////////////////////////
*/
#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 "SkLightingImageFilter.h"
#include "SkMorphologyImageFilter.h"
#include "SkOffsetImageFilter.h"
#include "SkPoint3.h"
#include "SkRectShaderImageFilter.h"
#include "SkScalar.h"
+#include "SkSurface.h"
#include "gm.h"
#define RESIZE_FACTOR SkIntToScalar(4)
return SkISize::Make(1428, 500);
}
- void makeGradientCircle(int width, int height) {
- SkScalar x = SkIntToScalar(width / 2);
- SkScalar y = SkIntToScalar(height / 2);
- SkScalar radius = SkScalarMul(SkMinScalar(x, y), SkIntToScalar(4) / SkIntToScalar(5));
- 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(MakeGradientCircle(64, 64));
}
void onDraw(SkCanvas* canvas) override {
canvas->clear(SK_ColorBLACK);
- SkAutoTUnref<SkImageFilter> gradient(SkBitmapSource::Create(fGradientCircle));
- SkAutoTUnref<SkImageFilter> checkerboard(SkBitmapSource::Create(fCheckerboard));
+ SkAutoTUnref<SkImageFilter> gradient(SkImageSource::Create(fGradientCircle));
+ SkAutoTUnref<SkImageFilter> checkerboard(SkImageSource::Create(fCheckerboard));
SkAutoTUnref<SkShader> noise(SkPerlinNoiseShader::CreateFractalNoise(
SkDoubleToScalar(0.1), SkDoubleToScalar(0.05), 1, 0));
}
private:
- SkBitmap fCheckerboard;
- SkBitmap fGradientCircle;
+ static SkImage* MakeGradientCircle(int width, int height) {
+ SkScalar x = SkIntToScalar(width / 2);
+ SkScalar y = SkIntToScalar(height / 2);
+ SkScalar radius = SkScalarMul(SkMinScalar(x, y), SkIntToScalar(4) / SkIntToScalar(5));
+ 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();
+ }
+
+ SkAutoTUnref<SkImage> fCheckerboard, fGradientCircle;
typedef GM INHERITED;
};
--- /dev/null
+/*
+ * Copyright 2015 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 "SkImage.h"
+#include "SkImageSource.h"
+#include "SkSurface.h"
+
+namespace skiagm {
+
+// This GM reproduces the issue in crbug.com/472795. The SkImageSource image
+// is shifted for high quality mode between cpu and gpu.
+class ImageSourceGM : public GM {
+public:
+ ImageSourceGM(const char* suffix, SkFilterQuality filter) : fSuffix(suffix), fFilter(filter) {
+ this->setBGColor(0xFFFFFFFF);
+ }
+
+protected:
+ SkString onShortName() override {
+ SkString name("imagesrc2_");
+ name.append(fSuffix);
+ return name;
+ }
+
+ SkISize onISize() override { return SkISize::Make(256, 256); }
+
+ // Create an image with high frequency vertical stripes
+ void onOnceBeforeDraw() override {
+ static const SkPMColor gColors[] = {
+ SK_ColorRED, SK_ColorGRAY,
+ SK_ColorGREEN, SK_ColorGRAY,
+ SK_ColorBLUE, SK_ColorGRAY,
+ SK_ColorCYAN, SK_ColorGRAY,
+ SK_ColorMAGENTA, SK_ColorGRAY,
+ SK_ColorYELLOW, SK_ColorGRAY,
+ SK_ColorWHITE, SK_ColorGRAY,
+ };
+
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(kImageSize, kImageSize));
+ SkCanvas* canvas = surface->getCanvas();
+
+ int curColor = 0;
+
+ for (int x = 0; x < kImageSize; x += 3) {
+ SkRect r = SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(0),
+ SkIntToScalar(3), SkIntToScalar(kImageSize));
+ SkPaint p;
+ p.setColor(gColors[curColor]);
+ canvas->drawRect(r, p);
+
+ curColor = (curColor+1) % SK_ARRAY_COUNT(gColors);
+ }
+
+ fImage.reset(surface->newImageSnapshot());
+ }
+
+ void onDraw(SkCanvas* canvas) override {
+ SkRect srcRect = SkRect::MakeLTRB(0, 0,
+ SkIntToScalar(kImageSize), SkIntToScalar(kImageSize));
+ SkRect dstRect = SkRect::MakeLTRB(0.75f, 0.75f, 225.75f, 225.75f);
+
+ SkAutoTUnref<SkImageFilter> filter(
+ SkImageSource::Create(fImage, srcRect, dstRect, fFilter));
+
+ SkPaint p;
+ p.setImageFilter(filter);
+
+ canvas->saveLayer(nullptr, &p);
+ canvas->restore();
+ }
+
+private:
+ static const int kImageSize = 503;
+
+ SkString fSuffix;
+ SkFilterQuality fFilter;
+ SkAutoTUnref<SkImage> fImage;
+
+ typedef GM INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+DEF_GM(return new ImageSourceGM("none", kNone_SkFilterQuality);)
+DEF_GM(return new ImageSourceGM("low", kLow_SkFilterQuality);)
+DEF_GM(return new ImageSourceGM("med", kMedium_SkFilterQuality);)
+DEF_GM(return new ImageSourceGM("high", kHigh_SkFilterQuality);)
+}
*/
#include "sk_tool_utils.h"
-#include "SkBitmapSource.h"
+#include "SkImage.h"
+#include "SkImageSource.h"
#include "SkOffsetImageFilter.h"
+#include "SkSurface.h"
#include "gm.h"
#define WIDTH 600
return SkISize::Make(WIDTH, HEIGHT);
}
- void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPaint& paint,
- SkScalar scale, const SkIRect& cropRect) {
- SkRect clipRect = SkRect::MakeIWH(bitmap.width(), bitmap.height());
-
- canvas->save();
- canvas->clipRect(clipRect);
- canvas->scale(scale, scale);
- canvas->drawBitmap(bitmap, 0, 0, &paint);
- canvas->restore();
-
- // Draw a boundary rect around the intersection of the clip rect and crop rect.
- SkRect cropRectFloat;
- SkMatrix::MakeScale(scale, scale).mapRect(&cropRectFloat, SkRect::Make(cropRect));
- if (clipRect.intersect(cropRectFloat)) {
- SkPaint strokePaint;
- strokePaint.setStyle(SkPaint::kStroke_Style);
- strokePaint.setStrokeWidth(2);
- strokePaint.setColor(SK_ColorRED);
- canvas->drawRect(clipRect, strokePaint);
- }
- }
-
void onOnceBeforeDraw() override {
- fBitmap = sk_tool_utils::create_string_bitmap(80, 80, 0xD000D000, 15, 65, 96, "e");
+ fBitmap.reset(SkImage::NewFromBitmap(
+ sk_tool_utils::create_string_bitmap(80, 80, 0xD000D000, 15, 65, 96, "e")));
- fCheckerboard = sk_tool_utils::create_checkerboard_bitmap(
- 80, 80,
- sk_tool_utils::color_to_565(0xFFA0A0A0),
- sk_tool_utils::color_to_565(0xFF404040),
- 8);
+ fCheckerboard.reset(SkImage::NewFromBitmap(
+ sk_tool_utils::create_checkerboard_bitmap(80, 80,
+ sk_tool_utils::color_to_565(0xFFA0A0A0),
+ sk_tool_utils::color_to_565(0xFF404040),
+ 8)));
}
void onDraw(SkCanvas* canvas) override {
SkPaint paint;
for (int i = 0; i < 4; i++) {
- const SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap;
+ const SkImage* image = (i & 0x01) ? fCheckerboard : fBitmap;
SkIRect cropRect = SkIRect::MakeXYWH(i * 12,
i * 8,
- bitmap->width() - i * 8,
- bitmap->height() - i * 12);
+ image->width() - i * 8,
+ image->height() - i * 12);
SkImageFilter::CropRect rect(SkRect::Make(cropRect));
- SkAutoTUnref<SkImageFilter> tileInput(SkBitmapSource::Create(*bitmap));
+ SkAutoTUnref<SkImageFilter> tileInput(SkImageSource::Create(image));
SkScalar dx = SkIntToScalar(i*5);
SkScalar dy = SkIntToScalar(i*10);
SkAutoTUnref<SkImageFilter> filter(SkOffsetImageFilter::Create(dx, dy, tileInput,
&rect));
paint.setImageFilter(filter);
- drawClippedBitmap(canvas, *bitmap, paint, 1, cropRect);
- canvas->translate(SkIntToScalar(bitmap->width() + MARGIN), 0);
+ DrawClippedImage(canvas, image, paint, 1, cropRect);
+ canvas->translate(SkIntToScalar(image->width() + MARGIN), 0);
}
SkIRect cropRect = SkIRect::MakeXYWH(0, 0, 100, 100);
SkImageFilter::CropRect rect(SkRect::Make(cropRect));
SkAutoTUnref<SkImageFilter> filter(SkOffsetImageFilter::Create(-5, -10, nullptr, &rect));
paint.setImageFilter(filter);
- drawClippedBitmap(canvas, fBitmap, paint, 2, cropRect);
+ DrawClippedImage(canvas, fBitmap, paint, 2, cropRect);
}
private:
- SkBitmap fBitmap, fCheckerboard;
+ static void DrawClippedImage(SkCanvas* canvas, const SkImage* image, const SkPaint& paint,
+ SkScalar scale, const SkIRect& cropRect) {
+ SkRect clipRect = SkRect::MakeIWH(image->width(), image->height());
+
+ canvas->save();
+ canvas->clipRect(clipRect);
+ canvas->scale(scale, scale);
+ canvas->drawImage(image, 0, 0, &paint);
+ canvas->restore();
+
+ // Draw a boundary rect around the intersection of the clip rect and crop rect.
+ SkRect cropRectFloat;
+ SkMatrix::MakeScale(scale, scale).mapRect(&cropRectFloat, SkRect::Make(cropRect));
+ if (clipRect.intersect(cropRectFloat)) {
+ SkPaint strokePaint;
+ strokePaint.setStyle(SkPaint::kStroke_Style);
+ strokePaint.setStrokeWidth(2);
+ strokePaint.setColor(SK_ColorRED);
+ canvas->drawRect(clipRect, strokePaint);
+ }
+ }
+
+ SkAutoTUnref<SkImage> fBitmap, fCheckerboard;
typedef skiagm::GM INHERITED;
};
*/
#include "gm.h"
-#include "SkBitmapSource.h"
#include "SkColor.h"
+#include "SkImageSource.h"
#include "SkRefCnt.h"
+#include "SkSurface.h"
namespace skiagm {
deviceSize,
kHigh_SkFilterQuality);
- SkBitmap bitmap;
- bitmap.allocN32Pixels(16, 16);
- bitmap.eraseARGB(0x00, 0x00, 0x00, 0x00);
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(16, 16));
+ SkCanvas* surfaceCanvas = surface->getCanvas();
+ surfaceCanvas->clear(0x000000);
{
- SkCanvas bitmapCanvas(bitmap);
SkPaint paint;
paint.setColor(0xFF00FF00);
SkRect ovalRect = SkRect::MakeWH(16, 16);
ovalRect.inset(SkIntToScalar(2)/3, SkIntToScalar(2)/3);
- bitmapCanvas.drawOval(ovalRect, paint);
+ surfaceCanvas->drawOval(ovalRect, paint);
}
+ SkAutoTUnref<SkImage> image(surface->newImageSnapshot());
SkRect inRect = SkRect::MakeXYWH(-4, -4, 20, 20);
SkRect outRect = SkRect::MakeXYWH(-24, -24, 120, 120);
- SkAutoTUnref<SkBitmapSource> source(SkBitmapSource::Create(bitmap, inRect, outRect));
+ SkAutoTUnref<SkImageFilter> source(
+ SkImageSource::Create(image, inRect, outRect, kHigh_SkFilterQuality));
canvas->translate(srcRect.width() + SkIntToScalar(10), 0);
draw(canvas,
srcRect,
*/
#include "sk_tool_utils.h"
-#include "SkBitmapSource.h"
#include "SkColorFilterImageFilter.h"
#include "SkColorMatrixFilter.h"
+#include "SkImage.h"
+#include "SkImageSource.h"
#include "SkTileImageFilter.h"
#include "gm.h"
}
void onOnceBeforeDraw() override {
- fBitmap = sk_tool_utils::create_string_bitmap(50, 50, 0xD000D000, 10, 45, 50, "e");
-
- fCheckerboard = sk_tool_utils::create_checkerboard_bitmap(
- 80, 80,
- sk_tool_utils::color_to_565(0xFFA0A0A0),
- sk_tool_utils::color_to_565(0xFF404040),
- 8);
+ fBitmap.reset(SkImage::NewFromBitmap(
+ sk_tool_utils::create_string_bitmap(50, 50, 0xD000D000, 10, 45, 50, "e")));
+
+ fCheckerboard.reset(SkImage::NewFromBitmap(
+ sk_tool_utils::create_checkerboard_bitmap(80, 80,
+ sk_tool_utils::color_to_565(0xFFA0A0A0),
+ sk_tool_utils::color_to_565(0xFF404040),
+ 8)));
}
void onDraw(SkCanvas* canvas) override {
int x = 0, y = 0;
for (size_t i = 0; i < 4; i++) {
- SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap;
- SkRect srcRect = SkRect::MakeXYWH(SkIntToScalar(bitmap->width()/4),
- SkIntToScalar(bitmap->height()/4),
- SkIntToScalar(bitmap->width()/(i+1)),
- SkIntToScalar(bitmap->height()/(i+1)));
+ const SkImage* image = (i & 0x01) ? fCheckerboard : fBitmap;
+ SkRect srcRect = SkRect::MakeXYWH(SkIntToScalar(image->width()/4),
+ SkIntToScalar(image->height()/4),
+ SkIntToScalar(image->width()/(i+1)),
+ SkIntToScalar(image->height()/(i+1)));
SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(i * 8),
SkIntToScalar(i * 4),
- SkIntToScalar(bitmap->width() - i * 12),
- SkIntToScalar(bitmap->height()) - i * 12);
- SkAutoTUnref<SkImageFilter> tileInput(SkBitmapSource::Create(*bitmap));
+ SkIntToScalar(image->width() - i * 12),
+ SkIntToScalar(image->height()) - i * 12);
+ SkAutoTUnref<SkImageFilter> tileInput(SkImageSource::Create(image));
SkAutoTUnref<SkImageFilter> filter(
SkTileImageFilter::Create(srcRect, dstRect, tileInput));
canvas->save();
canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
SkPaint paint;
paint.setImageFilter(filter);
- canvas->drawBitmap(fBitmap, 0, 0, &paint);
+ canvas->drawImage(fBitmap, 0, 0, &paint);
canvas->restore();
- x += bitmap->width() + MARGIN;
- if (x + bitmap->width() > WIDTH) {
+ x += image->width() + MARGIN;
+ if (x + image->width() > WIDTH) {
x = 0;
- y += bitmap->height() + MARGIN;
+ y += image->height() + MARGIN;
}
}
0, 0, SK_Scalar1, 0, 0,
0, 0, 0, SK_Scalar1, 0 };
- SkRect srcRect = SkRect::MakeWH(SkIntToScalar(fBitmap.width()),
- SkIntToScalar(fBitmap.height()));
- SkRect dstRect = SkRect::MakeWH(SkIntToScalar(fBitmap.width() * 2),
- SkIntToScalar(fBitmap.height() * 2));
+ SkRect srcRect = SkRect::MakeWH(SkIntToScalar(fBitmap->width()),
+ SkIntToScalar(fBitmap->height()));
+ SkRect dstRect = SkRect::MakeWH(SkIntToScalar(fBitmap->width() * 2),
+ SkIntToScalar(fBitmap->height() * 2));
SkAutoTUnref<SkImageFilter> tile(SkTileImageFilter::Create(srcRect, dstRect, nullptr));
SkAutoTUnref<SkColorFilter> cf(SkColorMatrixFilter::Create(matrix));
canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
canvas->clipRect(dstRect);
canvas->saveLayer(&dstRect, &paint);
- canvas->drawBitmap(fBitmap, 0, 0);
+ canvas->drawImage(fBitmap, 0, 0);
canvas->restore();
canvas->restore();
}
private:
- SkBitmap fBitmap;
- SkBitmap fCheckerboard;
+ SkAutoTUnref<SkImage> fBitmap, fCheckerboard;
typedef GM INHERITED;
};
#include "gm.h"
#include "sk_tool_utils.h"
#include "SkArithmeticMode.h"
+#include "SkImage.h"
+#include "SkImageSource.h"
#include "SkOffsetImageFilter.h"
#include "SkXfermodeImageFilter.h"
-#include "SkBitmapSource.h"
#define WIDTH 600
#define HEIGHT 600
return SkISize::Make(WIDTH, HEIGHT);
}
- static void drawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPaint& paint,
- int x, int y) {
- canvas->save();
- canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
- canvas->clipRect(SkRect::MakeWH(
- SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height())));
- canvas->drawBitmap(bitmap, 0, 0, &paint);
- canvas->restore();
- }
-
- static void drawClippedPaint(SkCanvas* canvas, const SkRect& rect, const SkPaint& paint,
- int x, int y) {
- canvas->save();
- canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
- canvas->clipRect(rect);
- canvas->drawPaint(paint);
- canvas->restore();
- }
-
void onOnceBeforeDraw() override {
fBitmap = sk_tool_utils::create_string_bitmap(80, 80, 0xD000D000, 15, 65, 96, "e");
- fCheckerboard = sk_tool_utils::create_checkerboard_bitmap(
- 80, 80,
- sk_tool_utils::color_to_565(0xFFA0A0A0),
- sk_tool_utils::color_to_565(0xFF404040),
- 8);
+ fCheckerboard.reset(SkImage::NewFromBitmap(
+ sk_tool_utils::create_checkerboard_bitmap(80, 80,
+ sk_tool_utils::color_to_565(0xFFA0A0A0),
+ sk_tool_utils::color_to_565(0xFF404040),
+ 8)));
}
void onDraw(SkCanvas* canvas) override {
};
int x = 0, y = 0;
- SkAutoTUnref<SkImageFilter> background(SkBitmapSource::Create(fCheckerboard));
+ SkAutoTUnref<SkImageFilter> background(SkImageSource::Create(fCheckerboard));
for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) {
SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(gModes[i].fMode));
SkAutoTUnref<SkImageFilter> filter(SkXfermodeImageFilter::Create(mode, background));
paint.setImageFilter(filter);
- drawClippedBitmap(canvas, fBitmap, paint, x, y);
+ DrawClippedBitmap(canvas, fBitmap, paint, x, y);
x += fBitmap.width() + MARGIN;
if (x + fBitmap.width() > WIDTH) {
x = 0;
SkAutoTUnref<SkXfermode> mode(SkArithmeticMode::Create(0, SK_Scalar1, SK_Scalar1, 0));
SkAutoTUnref<SkImageFilter> filter(SkXfermodeImageFilter::Create(mode, background));
paint.setImageFilter(filter);
- drawClippedBitmap(canvas, fBitmap, paint, x, y);
+ DrawClippedBitmap(canvas, fBitmap, paint, x, y);
x += fBitmap.width() + MARGIN;
if (x + fBitmap.width() > WIDTH) {
x = 0;
// Test nullptr mode
filter.reset(SkXfermodeImageFilter::Create(nullptr, background));
paint.setImageFilter(filter);
- drawClippedBitmap(canvas, fBitmap, paint, x, y);
+ DrawClippedBitmap(canvas, fBitmap, paint, x, y);
x += fBitmap.width() + MARGIN;
if (x + fBitmap.width() > WIDTH) {
x = 0;
SkRect clipRect = SkRect::MakeWH(SkIntToScalar(fBitmap.width() + 4),
SkIntToScalar(fBitmap.height() + 4));
// Test offsets on SrcMode (uses fixed-function blend)
- SkAutoTUnref<SkImageFilter> foreground(SkBitmapSource::Create(fBitmap));
+ SkAutoTUnref<SkImage> bitmapImage(SkImage::NewFromBitmap(fBitmap));
+ SkAutoTUnref<SkImageFilter> foreground(SkImageSource::Create(bitmapImage));
SkAutoTUnref<SkImageFilter> offsetForeground(SkOffsetImageFilter::Create(
SkIntToScalar(4), SkIntToScalar(-4), foreground));
SkAutoTUnref<SkImageFilter> offsetBackground(SkOffsetImageFilter::Create(
mode.reset(SkXfermode::Create(SkXfermode::kSrcOver_Mode));
filter.reset(SkXfermodeImageFilter::Create(mode, offsetBackground, offsetForeground));
paint.setImageFilter(filter);
- drawClippedPaint(canvas, clipRect, paint, x, y);
+ DrawClippedPaint(canvas, clipRect, paint, x, y);
x += fBitmap.width() + MARGIN;
if (x + fBitmap.width() > WIDTH) {
x = 0;
mode.reset(SkXfermode::Create(SkXfermode::kDarken_Mode));
filter.reset(SkXfermodeImageFilter::Create(mode, offsetBackground, offsetForeground));
paint.setImageFilter(filter);
- drawClippedPaint(canvas, clipRect, paint, x, y);
+ DrawClippedPaint(canvas, clipRect, paint, x, y);
x += fBitmap.width() + MARGIN;
if (x + fBitmap.width() > WIDTH) {
x = 0;
filter.reset(SkXfermodeImageFilter::Create(
mode, offsetBackground, offsetForeground, &rect));
paint.setImageFilter(filter);
- drawClippedPaint(canvas, clipRect, paint, x, y);
+ DrawClippedPaint(canvas, clipRect, paint, x, y);
x += fBitmap.width() + MARGIN;
if (x + fBitmap.width() > WIDTH) {
x = 0;
}
}
}
+
private:
- SkBitmap fBitmap, fCheckerboard;
+ static void DrawClippedBitmap(SkCanvas* canvas, const SkBitmap& bitmap, const SkPaint& paint,
+ int x, int y) {
+ canvas->save();
+ canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
+ canvas->clipRect(SkRect::MakeWH(
+ SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height())));
+ canvas->drawBitmap(bitmap, 0, 0, &paint);
+ canvas->restore();
+ }
+
+ static void DrawClippedPaint(SkCanvas* canvas, const SkRect& rect, const SkPaint& paint,
+ int x, int y) {
+ canvas->save();
+ canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
+ canvas->clipRect(rect);
+ canvas->drawPaint(paint);
+ canvas->restore();
+ }
+
+ SkBitmap fBitmap;
+ SkAutoTUnref<SkImage> fCheckerboard;
+
typedef GM INHERITED;
};
*/
#include "SampleCode.h"
#include "SkAlphaThresholdFilter.h"
-#include "SkBitmapSource.h"
#include "SkBlurImageFilter.h"
#include "SkCanvas.h"
#include "SkColorCubeFilter.h"
#include "SkDisplacementMapEffect.h"
#include "SkDropShadowImageFilter.h"
#include "SkFlattenableSerialization.h"
+#include "SkImageSource.h"
#include "SkLightingImageFilter.h"
#include "SkMagnifierImageFilter.h"
#include "SkMatrixConvolutionImageFilter.h"
}
break;
case BITMAP:
+ {
+ SkAutoTUnref<SkImage> image(SkImage::NewFromBitmap(make_bitmap()));
if (R(2) == 1) {
- filter = SkBitmapSource::Create(make_bitmap(), make_rect(), make_rect());
+ filter = SkImageSource::Create(image, make_rect(), make_rect(), kHigh_SkFilterQuality);
} else {
- filter = SkBitmapSource::Create(make_bitmap());
+ filter = SkImageSource::Create(image);
}
+ }
break;
case DISPLACE:
filter = SkDisplacementMapEffect::Create(make_channel_selector_type(),
#include "SkBitmap.h"
#include "SkBitmapDevice.h"
-#include "SkBitmapSource.h"
#include "SkBlurImageFilter.h"
#include "SkCanvas.h"
#include "SkColorFilterImageFilter.h"
#include "SkDropShadowImageFilter.h"
#include "SkFlattenableSerialization.h"
#include "SkGradientShader.h"
+#include "SkImage.h"
#include "SkImageSource.h"
#include "SkLightingImageFilter.h"
#include "SkMatrixConvolutionImageFilter.h"
}
#endif
-static void make_small_bitmap(SkBitmap& bitmap) {
- bitmap.allocN32Pixels(kBitmapSize, kBitmapSize);
- SkCanvas canvas(bitmap);
- canvas.clear(0x00000000);
+static SkImage* make_small_image() {
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(kBitmapSize, kBitmapSize));
+ SkCanvas* canvas = surface->getCanvas();
+ canvas->clear(0x00000000);
SkPaint darkPaint;
darkPaint.setColor(0xFF804020);
SkPaint lightPaint;
const int i = kBitmapSize / 4;
for (int y = 0; y < kBitmapSize; y += i) {
for (int x = 0; x < kBitmapSize; x += i) {
- canvas.save();
- canvas.translate(SkIntToScalar(x), SkIntToScalar(y));
- canvas.drawRect(SkRect::MakeXYWH(0, 0,
+ canvas->save();
+ canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
+ canvas->drawRect(SkRect::MakeXYWH(0, 0,
SkIntToScalar(i),
SkIntToScalar(i)), darkPaint);
- canvas.drawRect(SkRect::MakeXYWH(SkIntToScalar(i),
+ canvas->drawRect(SkRect::MakeXYWH(SkIntToScalar(i),
0,
SkIntToScalar(i),
SkIntToScalar(i)), lightPaint);
- canvas.drawRect(SkRect::MakeXYWH(0,
+ canvas->drawRect(SkRect::MakeXYWH(0,
SkIntToScalar(i),
SkIntToScalar(i),
SkIntToScalar(i)), lightPaint);
- canvas.drawRect(SkRect::MakeXYWH(SkIntToScalar(i),
+ canvas->drawRect(SkRect::MakeXYWH(SkIntToScalar(i),
SkIntToScalar(i),
SkIntToScalar(i),
SkIntToScalar(i)), darkPaint);
- canvas.restore();
+ canvas->restore();
}
}
+
+ return surface->newImageSnapshot();
}
static SkImageFilter* make_scale(float amount, SkImageFilter* input = nullptr) {
{
// Tests pass by not asserting
- SkBitmap bitmap, result;
- make_small_bitmap(bitmap);
+ SkAutoTUnref<SkImage> image(make_small_image());
+ SkBitmap result;
result.allocN32Pixels(kBitmapSize, kBitmapSize);
{
// 3 ) large negative specular exponent value
SkScalar specularExponent = -1000;
- SkAutoTUnref<SkImageFilter> bmSrc(SkBitmapSource::Create(bitmap));
+ SkAutoTUnref<SkImageFilter> bmSrc(SkImageSource::Create(image));
SkPaint paint;
paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular(
location, target, specularExponent, 180,
SkScalar gain = SK_Scalar1, bias = 0;
SkScalar five = SkIntToScalar(5);
- SkAutoTUnref<SkImageFilter> gradient_source(SkBitmapSource::Create(make_gradient_circle(64, 64)));
+ SkAutoTUnref<SkImage> gradientImage(SkImage::NewFromBitmap(make_gradient_circle(64, 64)));
+ SkAutoTUnref<SkImageFilter> gradientSource(SkImageSource::Create(gradientImage));
SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(five, five));
SkMatrix matrix;
{ "displacement map", SkDisplacementMapEffect::Create(
SkDisplacementMapEffect::kR_ChannelSelectorType,
SkDisplacementMapEffect::kB_ChannelSelectorType,
- 20.0f, gradient_source.get()) },
+ 20.0f, gradientSource.get()) },
{ "blur", SkBlurImageFilter::Create(SK_Scalar1, SK_Scalar1) },
{ "drop shadow", SkDropShadowImageFilter::Create(
SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_ColorGREEN,
*/
#include "Resources.h"
-#include "SkBitmapSource.h"
#include "SkCanvas.h"
#include "SkFixed.h"
#include "SkFontDescriptor.h"
+#include "SkImage.h"
+#include "SkImageSource.h"
#include "SkMallocPixelRef.h"
#include "SkOSFile.h"
#include "SkPictureRecorder.h"
const SkBitmap& invalidBitmap,
bool shouldSucceed,
skiatest::Reporter* reporter) {
- SkAutoTUnref<SkBitmapSource> validBitmapSource(SkBitmapSource::Create(validBitmap));
- SkAutoTUnref<SkBitmapSource> invalidBitmapSource(SkBitmapSource::Create(invalidBitmap));
+ SkAutoTUnref<SkImage> validImage(SkImage::NewFromBitmap(validBitmap));
+ SkAutoTUnref<SkImageFilter> validBitmapSource(SkImageSource::Create(validImage));
+ SkAutoTUnref<SkImage> invalidImage(SkImage::NewFromBitmap(invalidBitmap));
+ SkAutoTUnref<SkImageFilter> invalidBitmapSource(SkImageSource::Create(invalidImage));
SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kSrcOver_Mode));
SkAutoTUnref<SkXfermodeImageFilter> xfermodeImageFilter(
SkXfermodeImageFilter::Create(mode, invalidBitmapSource, validBitmapSource));