Index: gm/colormatrix.cpp |
diff --git a/gm/colormatrix.cpp b/gm/colormatrix.cpp |
index 8dcdf15e50167e2a1d85fb6a1f52b94f8429a5ed..5ae2b05bdf20f82b929e3119a7457bdb04cba97a 100644 |
--- a/gm/colormatrix.cpp |
+++ b/gm/colormatrix.cpp |
@@ -8,6 +8,7 @@ |
#include "gm.h" |
#include "SkColorMatrixFilter.h" |
#include "SkGradientShader.h" |
+#include "SkImage.h" |
#define WIDTH 500 |
#define HEIGHT 500 |
@@ -36,14 +37,12 @@ static void setArray(SkPaint* paint, const SkScalar array[]) { |
paint->setColorFilter(SkColorMatrixFilter::Create(array))->unref(); |
} |
-namespace skiagm { |
- |
-class ColorMatrixGM : public GM { |
+class ColorMatrixGM : public skiagm::GM { |
SkDoOnce fOnce; |
robertphillips
2015/07/06 20:43:47
Can this not occur in onOnceBeforeDraw ?
reed2
2015/07/07 01:18:02
Done.
|
void init() { |
if (fOnce.once()) { |
- fSolidBitmap = this->createSolidBitmap(64, 64); |
- fTransparentBitmap = this->createTransparentBitmap(64, 64); |
+ fSolidImg.reset(this->createSolidBitmap(64, 64)); |
+ fTransparentImg.reset(this->createTransparentBitmap(64, 64)); |
} |
} |
@@ -61,7 +60,7 @@ protected: |
return SkISize::Make(WIDTH, HEIGHT); |
} |
robertphillips
2015/07/06 20:43:47
Can createSolidBitmap & createTransparentBitmap be
reed2
2015/07/07 01:18:02
Done.
|
- SkBitmap createSolidBitmap(int width, int height) { |
+ SkImage* createSolidBitmap(int width, int height) { |
SkBitmap bm; |
bm.allocN32Pixels(width, height); |
SkCanvas canvas(bm); |
@@ -74,11 +73,11 @@ protected: |
SkIntToScalar(y), SK_Scalar1, SK_Scalar1), paint); |
} |
} |
- return bm; |
+ return SkImage::NewFromBitmap(bm); |
} |
// creates a bitmap with shades of transparent gray. |
- SkBitmap createTransparentBitmap(int width, int height) { |
+ SkImage* createTransparentBitmap(int width, int height) { |
SkBitmap bm; |
bm.allocN32Pixels(width, height); |
SkCanvas canvas(bm); |
@@ -90,7 +89,7 @@ protected: |
paint.setShader(SkGradientShader::CreateLinear(pts, colors, NULL, 2, |
SkShader::kClamp_TileMode))->unref(); |
canvas.drawRect(SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)), paint); |
- return bm; |
+ return SkImage::NewFromBitmap(bm); |
} |
virtual void onDraw(SkCanvas* canvas) { |
@@ -100,48 +99,48 @@ protected: |
SkColorMatrix matrix; |
paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
- const SkBitmap bmps[] = { fSolidBitmap, fTransparentBitmap }; |
+ const SkImage* bmps[] = { fSolidImg, fTransparentImg }; |
for (size_t i = 0; i < SK_ARRAY_COUNT(bmps); ++i) { |
matrix.setIdentity(); |
setColorMatrix(&paint, matrix); |
- canvas->drawBitmap(bmps[i], 0, 0, &paint); |
+ canvas->drawImage(bmps[i], 0, 0, &paint); |
matrix.setRotate(SkColorMatrix::kR_Axis, 90); |
setColorMatrix(&paint, matrix); |
- canvas->drawBitmap(bmps[i], 80, 0, &paint); |
+ canvas->drawImage(bmps[i], 80, 0, &paint); |
matrix.setRotate(SkColorMatrix::kG_Axis, 90); |
setColorMatrix(&paint, matrix); |
- canvas->drawBitmap(bmps[i], 160, 0, &paint); |
+ canvas->drawImage(bmps[i], 160, 0, &paint); |
matrix.setRotate(SkColorMatrix::kB_Axis, 90); |
setColorMatrix(&paint, matrix); |
- canvas->drawBitmap(bmps[i], 240, 0, &paint); |
- |
+ canvas->drawImage(bmps[i], 240, 0, &paint); |
+ /////////////////////////////////////////////// |
matrix.setSaturation(0.0f); |
setColorMatrix(&paint, matrix); |
- canvas->drawBitmap(bmps[i], 0, 80, &paint); |
+ canvas->drawImage(bmps[i], 0, 80, &paint); |
matrix.setSaturation(0.5f); |
setColorMatrix(&paint, matrix); |
- canvas->drawBitmap(bmps[i], 80, 80, &paint); |
+ canvas->drawImage(bmps[i], 80, 80, &paint); |
matrix.setSaturation(1.0f); |
setColorMatrix(&paint, matrix); |
- canvas->drawBitmap(bmps[i], 160, 80, &paint); |
+ canvas->drawImage(bmps[i], 160, 80, &paint); |
matrix.setSaturation(2.0f); |
setColorMatrix(&paint, matrix); |
- canvas->drawBitmap(bmps[i], 240, 80, &paint); |
- |
+ canvas->drawImage(bmps[i], 240, 80, &paint); |
+ /////////////////////////////////////////////// |
matrix.setRGB2YUV(); |
setColorMatrix(&paint, matrix); |
- canvas->drawBitmap(bmps[i], 0, 160, &paint); |
+ canvas->drawImage(bmps[i], 0, 160, &paint); |
matrix.setYUV2RGB(); |
setColorMatrix(&paint, matrix); |
- canvas->drawBitmap(bmps[i], 80, 160, &paint); |
+ canvas->drawImage(bmps[i], 80, 160, &paint); |
SkScalar s1 = SK_Scalar1; |
SkScalar s255 = SkIntToScalar(255); |
@@ -154,21 +153,17 @@ protected: |
}; |
setArray(&paint, data); |
- canvas->drawBitmap(bmps[i], 160, 160, &paint); |
- |
+ canvas->drawImage(bmps[i], 160, 160, &paint); |
+ /////////////////////////////////////////////// |
canvas->translate(0, 240); |
} |
} |
private: |
- SkBitmap fSolidBitmap; |
- SkBitmap fTransparentBitmap; |
- typedef GM INHERITED; |
-}; |
- |
-////////////////////////////////////////////////////////////////////////////// |
+ SkAutoTUnref<SkImage> fSolidImg; |
+ SkAutoTUnref<SkImage> fTransparentImg; |
-static GM* MyFactory(void*) { return new ColorMatrixGM; } |
-static GMRegistry reg(MyFactory); |
+ typedef skiagm::GM INHERITED; |
+}; |
+DEF_GM( return new ColorMatrixGM; ) |
-} |