Index: gm/imagefiltersscaled.cpp |
diff --git a/gm/imagefiltersscaled.cpp b/gm/imagefiltersscaled.cpp |
index e98749ebac3bd18ac561b4823e1b8fe252e4f8f9..3221c88cae87a194dfbcc617c5f74f5540a40081 100644 |
--- a/gm/imagefiltersscaled.cpp |
+++ b/gm/imagefiltersscaled.cpp |
@@ -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; |
}; |