diff options
author | halcanary <halcanary@google.com> | 2015-01-26 11:24:32 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-26 11:24:32 -0800 |
commit | 878fa0204bc246ec5fbaca4aa3c81aaefccc30a1 (patch) | |
tree | faef3e19c04dbabc482d43d33c4c2d15bc173639 /samplecode | |
parent | 4b952751c093801675307df6f3c4c25749e72925 (diff) |
Factor out checkerboard function in gm and sampleapp into tools.
Review URL: https://codereview.chromium.org/834303005
Diffstat (limited to 'samplecode')
-rw-r--r-- | samplecode/SampleColorFilter.cpp | 18 | ||||
-rw-r--r-- | samplecode/SampleFatBits.cpp | 16 | ||||
-rw-r--r-- | samplecode/SampleUnpremul.cpp | 9 |
3 files changed, 8 insertions, 35 deletions
diff --git a/samplecode/SampleColorFilter.cpp b/samplecode/SampleColorFilter.cpp index fb5d42744f..175f724710 100644 --- a/samplecode/SampleColorFilter.cpp +++ b/samplecode/SampleColorFilter.cpp @@ -5,6 +5,7 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ +#include "Checkerboard.h" #include "SampleCode.h" #include "SkView.h" #include "SkCanvas.h" @@ -84,20 +85,6 @@ static void test_5bits() { SkDebugf("--- trunc: %d %d round: %d %d new: %d %d\n", e0, ae0, e1, ae1, e2, ae2); } -// No longer marked static, since it is externed in SampleUnpremul. -SkShader* createChecker(); -SkShader* createChecker() { - SkBitmap bm; - bm.allocN32Pixels(2, 2); - bm.lockPixels(); - *bm.getAddr32(0, 0) = *bm.getAddr32(1, 1) = SkPreMultiplyColor(0xFFFFFFFF); - *bm.getAddr32(0, 1) = *bm.getAddr32(1, 0) = SkPreMultiplyColor(0xFFCCCCCC); - SkMatrix m; - m.setScale(12, 12); - return SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode, - SkShader::kRepeat_TileMode, &m); -} - static SkBitmap createBitmap(int n) { SkBitmap bitmap; bitmap.allocN32Pixels(n, n); @@ -131,7 +118,8 @@ class ColorFilterView : public SampleView { public: ColorFilterView() { fBitmap = createBitmap(N); - fShader = createChecker(); + fShader = sk_tools::CreateCheckerboardShader( + 0xFFCCCCCC, 0xFFFFFFFF, 12); if (false) { // avoid bit rot, suppress warning test_5bits(); diff --git a/samplecode/SampleFatBits.cpp b/samplecode/SampleFatBits.cpp index 9b9af3e3e9..9da351370a 100644 --- a/samplecode/SampleFatBits.cpp +++ b/samplecode/SampleFatBits.cpp @@ -5,6 +5,7 @@ * found in the LICENSE file. */ +#include "Checkerboard.h" #include "SampleCode.h" #include "SkView.h" #include "SkCanvas.h" @@ -35,18 +36,6 @@ static void erase(SkSurface* surface) { surface->getCanvas()->clear(SK_ColorTRANSPARENT); } -static SkShader* createChecker(const SkMatrix& localMatrix) { -// SkColor colors[] = { 0xFFFDFDFD, 0xFFF4F4F4 }; - SkColor colors[] = { 0xFFFFFFFF, 0xFFFFFFFF }; - SkBitmap bm; - bm.allocN32Pixels(2, 2); - bm.lockPixels(); - *bm.getAddr32(0, 0) = *bm.getAddr32(1, 1) = SkPreMultiplyColor(colors[0]); - *bm.getAddr32(0, 1) = *bm.getAddr32(1, 0) = SkPreMultiplyColor(colors[1]); - return SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode, - SkShader::kRepeat_TileMode, &localMatrix); -} - class FatBits { public: FatBits() { @@ -98,7 +87,8 @@ public: fBounds.set(0, 0, SkIntToScalar(width * zoom), SkIntToScalar(height * zoom)); fMatrix.setScale(SkIntToScalar(zoom), SkIntToScalar(zoom)); fInverse.setScale(SK_Scalar1 / zoom, SK_Scalar1 / zoom); - fShader.reset(createChecker(fMatrix)); + fShader.reset(sk_tools::CreateCheckerboardShader( + 0xFFCCCCCC, 0xFFFFFFFF, zoom)); SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); fMinSurface.reset(SkSurface::NewRaster(info)); diff --git a/samplecode/SampleUnpremul.cpp b/samplecode/SampleUnpremul.cpp index 9591fec159..889d06780e 100644 --- a/samplecode/SampleUnpremul.cpp +++ b/samplecode/SampleUnpremul.cpp @@ -7,6 +7,7 @@ #include "gm.h" +#include "Checkerboard.h" #include "Resources.h" #include "SampleCode.h" #include "SkBlurMask.h" @@ -25,9 +26,6 @@ __SK_FORCE_IMAGE_DECODER_LINKING; -// Defined in SampleColorFilter.cpp -extern SkShader* createChecker(); - /** * Interprets c as an unpremultiplied color, and returns the * premultiplied equivalent. @@ -78,10 +76,7 @@ protected: } void onDrawBackground(SkCanvas* canvas) SK_OVERRIDE { - SkPaint paint; - SkAutoTUnref<SkShader> shader(createChecker()); - paint.setShader(shader.get()); - canvas->drawPaint(paint); + sk_tools::DrawCheckerboard(canvas, 0xFFCCCCCC, 0xFFFFFFFF, 12); } void onDrawContent(SkCanvas* canvas) SK_OVERRIDE { |