Convert unit tests, GMs from SkBitmapSource to SkImagesource
This removes SkBitmapSource clients within Skia. http://crrev.com/1334173004 does the same for Blink, so we should be able to remove SkBitmapSource in a follow-up. R=reed@google.com,robertphillips@google.com,mtklein@google.com Review URL: https://codereview.chromium.org/1343123002
This commit is contained in:
parent
30c4cae7d3
commit
5598b63cd2
@ -6,9 +6,10 @@
|
||||
*/
|
||||
|
||||
#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
|
||||
@ -47,24 +48,26 @@ protected:
|
||||
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) {
|
||||
@ -78,7 +81,9 @@ protected:
|
||||
|
||||
inline bool isSmall() const { return fIsSmall; }
|
||||
|
||||
SkBitmap fBitmap, fCheckerboard;
|
||||
SkBitmap fBitmap;
|
||||
SkAutoTUnref<SkImage> fCheckerboard;
|
||||
|
||||
private:
|
||||
bool fInitialized;
|
||||
bool fIsSmall;
|
||||
@ -97,7 +102,7 @@ protected:
|
||||
|
||||
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,
|
||||
@ -124,7 +129,7 @@ protected:
|
||||
|
||||
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,
|
||||
@ -150,7 +155,7 @@ protected:
|
||||
|
||||
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,
|
||||
|
@ -6,9 +6,10 @@
|
||||
*/
|
||||
|
||||
#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)
|
||||
@ -44,49 +45,49 @@ protected:
|
||||
|
||||
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;
|
||||
};
|
||||
|
@ -5,8 +5,9 @@
|
||||
* 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"
|
||||
|
||||
@ -29,11 +30,16 @@ protected:
|
||||
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 {
|
||||
@ -51,7 +57,7 @@ protected:
|
||||
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();
|
||||
@ -148,25 +154,25 @@ protected:
|
||||
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,
|
||||
@ -184,7 +190,8 @@ protected:
|
||||
}
|
||||
|
||||
private:
|
||||
SkBitmap fBitmap, fCheckerboard, fSmall, fLarge, fLargeW, fLargeH;
|
||||
SkBitmap fBitmap;
|
||||
SkAutoTUnref<SkImage> fCheckerboard, fSmall, fLarge, fLargeW, fLargeH;
|
||||
|
||||
typedef GM INHERITED;
|
||||
};
|
||||
|
@ -6,12 +6,13 @@
|
||||
*/
|
||||
|
||||
#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"
|
||||
@ -19,6 +20,7 @@
|
||||
#include "SkPoint3.h"
|
||||
#include "SkRectShaderImageFilter.h"
|
||||
#include "SkScalar.h"
|
||||
#include "SkSurface.h"
|
||||
#include "gm.h"
|
||||
|
||||
#define RESIZE_FACTOR_X SkIntToScalar(2)
|
||||
@ -45,9 +47,9 @@ protected:
|
||||
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;
|
||||
@ -57,7 +59,8 @@ protected:
|
||||
);
|
||||
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,
|
||||
@ -80,16 +83,16 @@ protected:
|
||||
}
|
||||
|
||||
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;
|
||||
@ -136,19 +139,17 @@ protected:
|
||||
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;
|
||||
};
|
||||
|
@ -11,16 +11,17 @@
|
||||
#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"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -30,13 +31,84 @@ public:
|
||||
|
||||
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);
|
||||
@ -57,13 +129,13 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
@ -73,10 +145,12 @@ protected:
|
||||
);
|
||||
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);
|
||||
@ -91,77 +165,6 @@ protected:
|
||||
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;
|
||||
};
|
||||
|
||||
|
@ -9,11 +9,12 @@
|
||||
|
||||
#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"
|
||||
@ -107,24 +108,17 @@ protected:
|
||||
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));
|
||||
@ -152,7 +146,7 @@ protected:
|
||||
|
||||
SkPaint paint;
|
||||
paint.setImageFilter(blendColor);
|
||||
drawClippedBitmap(canvas, fBitmap, paint);
|
||||
DrawClippedImage(canvas, fImage, paint);
|
||||
canvas->translate(SkIntToScalar(100), 0);
|
||||
}
|
||||
{
|
||||
@ -171,7 +165,7 @@ protected:
|
||||
|
||||
SkPaint paint;
|
||||
paint.setImageFilter(arithFilter);
|
||||
drawClippedBitmap(canvas, fBitmap, paint);
|
||||
DrawClippedImage(canvas, fImage, paint);
|
||||
canvas->translate(SkIntToScalar(100), 0);
|
||||
}
|
||||
{
|
||||
@ -185,7 +179,7 @@ protected:
|
||||
|
||||
SkPaint paint;
|
||||
paint.setImageFilter(blend);
|
||||
drawClippedBitmap(canvas, fBitmap, paint);
|
||||
DrawClippedImage(canvas, fImage, paint);
|
||||
canvas->translate(SkIntToScalar(100), 0);
|
||||
}
|
||||
{
|
||||
@ -210,8 +204,16 @@ protected:
|
||||
}
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -6,12 +6,13 @@
|
||||
*/
|
||||
|
||||
#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"
|
||||
@ -19,6 +20,7 @@
|
||||
#include "SkPoint3.h"
|
||||
#include "SkRectShaderImageFilter.h"
|
||||
#include "SkScalar.h"
|
||||
#include "SkSurface.h"
|
||||
#include "gm.h"
|
||||
|
||||
#define RESIZE_FACTOR SkIntToScalar(4)
|
||||
@ -41,36 +43,17 @@ protected:
|
||||
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));
|
||||
|
||||
@ -150,8 +133,28 @@ protected:
|
||||
}
|
||||
|
||||
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;
|
||||
};
|
||||
|
@ -6,28 +6,30 @@
|
||||
*/
|
||||
|
||||
#include "gm.h"
|
||||
#include "SkBitmapSource.h"
|
||||
#include "SkImage.h"
|
||||
#include "SkImageSource.h"
|
||||
#include "SkSurface.h"
|
||||
|
||||
namespace skiagm {
|
||||
|
||||
// This GM reproduces the issue in crbug.com/472795. The SkBitmapSource image
|
||||
// This GM reproduces the issue in crbug.com/472795. The SkImageSource image
|
||||
// is shifted for high quality mode between cpu and gpu.
|
||||
class BitmapSourceGM : public GM {
|
||||
class ImageSourceGM : public GM {
|
||||
public:
|
||||
BitmapSourceGM(const char* suffix, SkFilterQuality filter) : fSuffix(suffix), fFilter(filter) {
|
||||
ImageSourceGM(const char* suffix, SkFilterQuality filter) : fSuffix(suffix), fFilter(filter) {
|
||||
this->setBGColor(0xFFFFFFFF);
|
||||
}
|
||||
|
||||
protected:
|
||||
SkString onShortName() override {
|
||||
SkString name("bitmapsrc2_");
|
||||
SkString name("imagesrc2_");
|
||||
name.append(fSuffix);
|
||||
return name;
|
||||
}
|
||||
|
||||
SkISize onISize() override { return SkISize::Make(256, 256); }
|
||||
|
||||
// Create a bitmap with high frequency vertical stripes
|
||||
// Create an image with high frequency vertical stripes
|
||||
void onOnceBeforeDraw() override {
|
||||
static const SkPMColor gColors[] = {
|
||||
SK_ColorRED, SK_ColorGRAY,
|
||||
@ -39,9 +41,8 @@ protected:
|
||||
SK_ColorWHITE, SK_ColorGRAY,
|
||||
};
|
||||
|
||||
fBM.allocN32Pixels(kImageSize, kImageSize, true);
|
||||
|
||||
SkCanvas canvas(fBM);
|
||||
SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(kImageSize, kImageSize));
|
||||
SkCanvas* canvas = surface->getCanvas();
|
||||
|
||||
int curColor = 0;
|
||||
|
||||
@ -50,10 +51,12 @@ protected:
|
||||
SkIntToScalar(3), SkIntToScalar(kImageSize));
|
||||
SkPaint p;
|
||||
p.setColor(gColors[curColor]);
|
||||
canvas.drawRect(r, p);
|
||||
canvas->drawRect(r, p);
|
||||
|
||||
curColor = (curColor+1) % SK_ARRAY_COUNT(gColors);
|
||||
}
|
||||
|
||||
fImage.reset(surface->newImageSnapshot());
|
||||
}
|
||||
|
||||
void onDraw(SkCanvas* canvas) override {
|
||||
@ -61,7 +64,8 @@ protected:
|
||||
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));
|
||||
SkAutoTUnref<SkImageFilter> filter(
|
||||
SkImageSource::Create(fImage, srcRect, dstRect, fFilter));
|
||||
|
||||
SkPaint p;
|
||||
p.setImageFilter(filter);
|
||||
@ -75,15 +79,15 @@ private:
|
||||
|
||||
SkString fSuffix;
|
||||
SkFilterQuality fFilter;
|
||||
SkBitmap fBM;
|
||||
SkAutoTUnref<SkImage> fImage;
|
||||
|
||||
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);)
|
||||
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);)
|
||||
}
|
@ -6,8 +6,10 @@
|
||||
*/
|
||||
|
||||
#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
|
||||
@ -29,14 +31,53 @@ protected:
|
||||
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());
|
||||
void onOnceBeforeDraw() override {
|
||||
fBitmap.reset(SkImage::NewFromBitmap(
|
||||
sk_tool_utils::create_string_bitmap(80, 80, 0xD000D000, 15, 65, 96, "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 {
|
||||
canvas->clear(SK_ColorBLACK);
|
||||
SkPaint paint;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
const SkImage* image = (i & 0x01) ? fCheckerboard : fBitmap;
|
||||
SkIRect cropRect = SkIRect::MakeXYWH(i * 12,
|
||||
i * 8,
|
||||
image->width() - i * 8,
|
||||
image->height() - i * 12);
|
||||
SkImageFilter::CropRect rect(SkRect::Make(cropRect));
|
||||
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);
|
||||
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);
|
||||
DrawClippedImage(canvas, fBitmap, paint, 2, cropRect);
|
||||
}
|
||||
private:
|
||||
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->drawBitmap(bitmap, 0, 0, &paint);
|
||||
canvas->drawImage(image, 0, 0, &paint);
|
||||
canvas->restore();
|
||||
|
||||
// Draw a boundary rect around the intersection of the clip rect and crop rect.
|
||||
@ -51,45 +92,7 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void onDraw(SkCanvas* canvas) override {
|
||||
canvas->clear(SK_ColorBLACK);
|
||||
SkPaint paint;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
const SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap;
|
||||
SkIRect cropRect = SkIRect::MakeXYWH(i * 12,
|
||||
i * 8,
|
||||
bitmap->width() - i * 8,
|
||||
bitmap->height() - i * 12);
|
||||
SkImageFilter::CropRect rect(SkRect::Make(cropRect));
|
||||
SkAutoTUnref<SkImageFilter> tileInput(SkBitmapSource::Create(*bitmap));
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
private:
|
||||
SkBitmap fBitmap, fCheckerboard;
|
||||
SkAutoTUnref<SkImage> fBitmap, fCheckerboard;
|
||||
|
||||
typedef skiagm::GM INHERITED;
|
||||
};
|
||||
|
@ -6,9 +6,10 @@
|
||||
*/
|
||||
|
||||
#include "gm.h"
|
||||
#include "SkBitmapSource.h"
|
||||
#include "SkColor.h"
|
||||
#include "SkImageSource.h"
|
||||
#include "SkRefCnt.h"
|
||||
#include "SkSurface.h"
|
||||
|
||||
namespace skiagm {
|
||||
|
||||
@ -86,20 +87,21 @@ protected:
|
||||
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,
|
||||
|
@ -6,9 +6,10 @@
|
||||
*/
|
||||
|
||||
#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"
|
||||
|
||||
@ -34,13 +35,14 @@ protected:
|
||||
}
|
||||
|
||||
void onOnceBeforeDraw() override {
|
||||
fBitmap = sk_tool_utils::create_string_bitmap(50, 50, 0xD000D000, 10, 45, 50, "e");
|
||||
fBitmap.reset(SkImage::NewFromBitmap(
|
||||
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);
|
||||
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 {
|
||||
@ -48,28 +50,28 @@ protected:
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,10 +80,10 @@ protected:
|
||||
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));
|
||||
|
||||
@ -92,13 +94,12 @@ protected:
|
||||
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;
|
||||
};
|
||||
|
@ -8,9 +8,10 @@
|
||||
#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
|
||||
@ -33,33 +34,14 @@ protected:
|
||||
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 {
|
||||
@ -103,12 +85,12 @@ protected:
|
||||
};
|
||||
|
||||
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;
|
||||
@ -119,7 +101,7 @@ protected:
|
||||
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;
|
||||
@ -128,7 +110,7 @@ protected:
|
||||
// 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;
|
||||
@ -137,7 +119,8 @@ protected:
|
||||
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(
|
||||
@ -145,7 +128,7 @@ protected:
|
||||
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;
|
||||
@ -155,7 +138,7 @@ protected:
|
||||
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;
|
||||
@ -179,7 +162,7 @@ protected:
|
||||
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;
|
||||
@ -187,8 +170,30 @@ protected:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
@ -6,7 +6,6 @@
|
||||
*/
|
||||
#include "SampleCode.h"
|
||||
#include "SkAlphaThresholdFilter.h"
|
||||
#include "SkBitmapSource.h"
|
||||
#include "SkBlurImageFilter.h"
|
||||
#include "SkCanvas.h"
|
||||
#include "SkColorCubeFilter.h"
|
||||
@ -17,6 +16,7 @@
|
||||
#include "SkDisplacementMapEffect.h"
|
||||
#include "SkDropShadowImageFilter.h"
|
||||
#include "SkFlattenableSerialization.h"
|
||||
#include "SkImageSource.h"
|
||||
#include "SkLightingImageFilter.h"
|
||||
#include "SkMagnifierImageFilter.h"
|
||||
#include "SkMatrixConvolutionImageFilter.h"
|
||||
@ -392,11 +392,14 @@ static SkImageFilter* make_image_filter(bool canBeNull = true) {
|
||||
}
|
||||
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(),
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
#include "SkBitmap.h"
|
||||
#include "SkBitmapDevice.h"
|
||||
#include "SkBitmapSource.h"
|
||||
#include "SkBlurImageFilter.h"
|
||||
#include "SkCanvas.h"
|
||||
#include "SkColorFilterImageFilter.h"
|
||||
@ -17,6 +16,7 @@
|
||||
#include "SkDropShadowImageFilter.h"
|
||||
#include "SkFlattenableSerialization.h"
|
||||
#include "SkGradientShader.h"
|
||||
#include "SkImage.h"
|
||||
#include "SkImageSource.h"
|
||||
#include "SkLightingImageFilter.h"
|
||||
#include "SkMatrixConvolutionImageFilter.h"
|
||||
@ -92,10 +92,10 @@ void MatrixTestImageFilter::toString(SkString* str) const {
|
||||
}
|
||||
#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;
|
||||
@ -103,26 +103,28 @@ static void make_small_bitmap(SkBitmap& bitmap) {
|
||||
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) {
|
||||
@ -241,8 +243,8 @@ DEF_TEST(ImageFilter, reporter) {
|
||||
|
||||
{
|
||||
// Tests pass by not asserting
|
||||
SkBitmap bitmap, result;
|
||||
make_small_bitmap(bitmap);
|
||||
SkAutoTUnref<SkImage> image(make_small_image());
|
||||
SkBitmap result;
|
||||
result.allocN32Pixels(kBitmapSize, kBitmapSize);
|
||||
|
||||
{
|
||||
@ -254,7 +256,7 @@ DEF_TEST(ImageFilter, reporter) {
|
||||
// 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,
|
||||
@ -424,7 +426,8 @@ DEF_TEST(ImageFilterDrawTiled, reporter) {
|
||||
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;
|
||||
|
||||
@ -458,7 +461,7 @@ DEF_TEST(ImageFilterDrawTiled, reporter) {
|
||||
{ "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,
|
||||
|
@ -6,10 +6,11 @@
|
||||
*/
|
||||
|
||||
#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"
|
||||
@ -240,8 +241,10 @@ static void TestBitmapSerialization(const SkBitmap& validBitmap,
|
||||
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));
|
||||
|
Loading…
Reference in New Issue
Block a user