s/sk_tools::DrawCheckerboard/sk_tool_utils::draw_checkerboard/

BUG=skia:

Review URL: https://codereview.chromium.org/873333004
This commit is contained in:
halcanary 2015-01-26 12:49:00 -08:00 committed by Commit bot
parent 2445216b7a
commit b0cce2c1d3
17 changed files with 54 additions and 93 deletions

View File

@ -5,7 +5,7 @@
* found in the LICENSE file.
*/
#include "Checkerboard.h"
#include "sk_tool_utils.h"
#include "Resources.h"
#include "SkData.h"
#include "gm.h"
@ -31,7 +31,7 @@ static void draw_bitmap(SkCanvas* canvas, const char* resource, int x, int y) {
background and compression artifacts.
*/
DEF_SIMPLE_GM(colorwheel, canvas, 256, 256) {
sk_tools::DrawCheckerboard(canvas);
sk_tool_utils::draw_checkerboard(canvas);
draw_bitmap(canvas, "color_wheel.png", 0, 0); // top left
draw_bitmap(canvas, "color_wheel.gif", 128, 0); // top right
draw_bitmap(canvas, "color_wheel.webp", 0, 128); // bottom left

View File

@ -5,7 +5,7 @@
* found in the LICENSE file.
*/
#include "Checkerboard.h"
#include "sk_tool_utils.h"
#include "SkBitmapSource.h"
#include "SkDisplacementMapEffect.h"
#include "gm.h"
@ -48,7 +48,7 @@ protected:
void make_checkerboard(SkBitmap* bitmap, int w, int h) {
bitmap->allocN32Pixels(w, h);
SkCanvas canvas(*bitmap);
sk_tools::DrawCheckerboard(&canvas, 0xFF244484, 0xFF804020, 8);
sk_tool_utils::draw_checkerboard(&canvas, 0xFF244484, 0xFF804020, 8);
}
virtual SkISize onISize() {

View File

@ -5,7 +5,7 @@
* found in the LICENSE file.
*/
#include "Checkerboard.h"
#include "sk_tool_utils.h"
#include "SkBitmapSource.h"
#include "SkBlurImageFilter.h"
#include "SkColor.h"
@ -64,7 +64,7 @@ protected:
if (!fInitialized) {
fCheckerboard.allocN32Pixels(64, 64);
SkCanvas checkerboardCanvas(fCheckerboard);
sk_tools::DrawCheckerboard(&checkerboardCanvas, 0xFFA0A0A0, 0xFF404040, 8);
sk_tool_utils::draw_checkerboard(&checkerboardCanvas, 0xFFA0A0A0, 0xFF404040, 8);
this->make_gradient_circle(64, 64);
fInitialized = true;

View File

@ -5,7 +5,7 @@
* found in the LICENSE file.
*/
#include "Checkerboard.h"
#include "sk_tool_utils.h"
#include "SkBitmapSource.h"
#include "SkBlurImageFilter.h"
#include "SkColor.h"
@ -64,7 +64,7 @@ protected:
if (!fInitialized) {
fCheckerboard.allocN32Pixels(64, 64);
SkCanvas checkerboardCanvas(fCheckerboard);
sk_tools::DrawCheckerboard(&checkerboardCanvas, 0xFFA0A0A0, 0xFF404040, 8);
sk_tool_utils::draw_checkerboard(&checkerboardCanvas, 0xFFA0A0A0, 0xFF404040, 8);
this->make_gradient_circle(64, 64);
fInitialized = true;

View File

@ -5,7 +5,7 @@
* found in the LICENSE file.
*/
#include "Checkerboard.h"
#include "sk_tool_utils.h"
#include "SkBitmapSource.h"
#include "SkOffsetImageFilter.h"
#include "gm.h"
@ -73,7 +73,7 @@ protected:
fCheckerboard.allocN32Pixels(80, 80);
SkCanvas checkerboardCanvas(fCheckerboard);
sk_tools::DrawCheckerboard(&checkerboardCanvas, 0xFFA0A0A0, 0xFF404040, 8);
sk_tool_utils::draw_checkerboard(&checkerboardCanvas, 0xFFA0A0A0, 0xFF404040, 8);
fInitialized = true;
}

View File

@ -5,7 +5,7 @@
* found in the LICENSE file.
*/
#include "Checkerboard.h"
#include "sk_tool_utils.h"
#include "SkBitmapSource.h"
#include "SkColorFilterImageFilter.h"
#include "SkColorMatrixFilter.h"
@ -52,7 +52,7 @@ protected:
fCheckerboard.allocN32Pixels(80, 80);
SkCanvas checkerboardCanvas(fCheckerboard);
sk_tools::DrawCheckerboard(&checkerboardCanvas, 0xFFA0A0A0, 0xFF404040, 8);
sk_tool_utils::draw_checkerboard(&checkerboardCanvas, 0xFFA0A0A0, 0xFF404040, 8);
fInitialized = true;
}

View File

@ -6,7 +6,7 @@
*/
#include "gm.h"
#include "Checkerboard.h"
#include "sk_tool_utils.h"
#include "SkArithmeticMode.h"
#include "SkOffsetImageFilter.h"
#include "SkXfermodeImageFilter.h"
@ -70,7 +70,7 @@ protected:
fCheckerboard.allocN32Pixels(80, 80);
SkCanvas checkerboardCanvas(fCheckerboard);
sk_tools::DrawCheckerboard(&checkerboardCanvas, 0xFFA0A0A0, 0xFF404040, 8);
sk_tool_utils::draw_checkerboard(&checkerboardCanvas, 0xFFA0A0A0, 0xFF404040, 8);
}
void onDraw(SkCanvas* canvas) SK_OVERRIDE {

View File

@ -152,7 +152,6 @@
'skia_lib.gyp:skia_lib',
'tools.gyp:resources',
'tools.gyp:sk_tool_utils',
'tools.gyp:checkerboard',
'views.gyp:views',
'views_animated.gyp:views_animated',
'xml.gyp:xml',

View File

@ -7,9 +7,6 @@
'../src/images',
'../src/lazy',
],
'dependencies': [
'tools.gyp:checkerboard',
],
'conditions': [
# If we're building SampleApp on the bots, no need to link in the GM slides.
# We're not going to run it; we're only making sure it still builds.

View File

@ -88,13 +88,6 @@
'include_dirs': [ '../tools', ],
},
},
{
'target_name': 'checkerboard',
'type': 'static_library',
'sources': [ '../tools/Checkerboard.cpp', ],
'dependencies': [ 'skia_lib.gyp:skia_lib', ],
'direct_dependent_settings': { 'include_dirs': [ '../tools', ], },
},
{
'target_name' : 'timer',
'type': 'static_library',

View File

@ -5,7 +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 "sk_tool_utils.h"
#include "SampleCode.h"
#include "SkView.h"
#include "SkCanvas.h"
@ -118,7 +118,7 @@ class ColorFilterView : public SampleView {
public:
ColorFilterView() {
fBitmap = createBitmap(N);
fShader = sk_tools::CreateCheckerboardShader(
fShader = sk_tool_utils::create_checkerboard_shader(
0xFFCCCCCC, 0xFFFFFFFF, 12);
if (false) { // avoid bit rot, suppress warning

View File

@ -5,7 +5,7 @@
* found in the LICENSE file.
*/
#include "Checkerboard.h"
#include "sk_tool_utils.h"
#include "SampleCode.h"
#include "SkView.h"
#include "SkCanvas.h"
@ -87,7 +87,7 @@ 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(sk_tools::CreateCheckerboardShader(
fShader.reset(sk_tool_utils::create_checkerboard_shader(
0xFFCCCCCC, 0xFFFFFFFF, zoom));
SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);

View File

@ -7,7 +7,7 @@
#include "gm.h"
#include "Checkerboard.h"
#include "sk_tool_utils.h"
#include "Resources.h"
#include "SampleCode.h"
#include "SkBlurMask.h"
@ -76,7 +76,7 @@ protected:
}
void onDrawBackground(SkCanvas* canvas) SK_OVERRIDE {
sk_tools::DrawCheckerboard(canvas, 0xFFCCCCCC, 0xFFFFFFFF, 12);
sk_tool_utils::draw_checkerboard(canvas, 0xFFCCCCCC, 0xFFFFFFFF, 12);
}
void onDrawContent(SkCanvas* canvas) SK_OVERRIDE {

View File

@ -1,28 +0,0 @@
/*
* 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 "Checkerboard.h"
#include "SkCanvas.h"
#include "SkShader.h"
SkShader* sk_tools::CreateCheckerboardShader(
SkColor c1, SkColor c2, int size) {
SkBitmap bm;
bm.allocN32Pixels(2 * size, 2 * size);
bm.eraseColor(c1);
bm.eraseArea(SkIRect::MakeLTRB(0, 0, size, size), c2);
bm.eraseArea(SkIRect::MakeLTRB(size, size, 2 * size, 2 * size), c2);
return SkShader::CreateBitmapShader(
bm, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);
}
void sk_tools::DrawCheckerboard(SkCanvas* canvas,
SkColor c1, SkColor c2, int size) {
SkPaint paint;
paint.setShader(CreateCheckerboardShader(c1, c2, size))->unref();
canvas->drawPaint(paint);
}

View File

@ -1,34 +0,0 @@
/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef Checkerboard_DEFINED
#define Checkerboard_DEFINED
#include "SkColor.h"
class SkCanvas;
class SkShader;
namespace sk_tools {
/** Returns a newly created CheckerboardShader. */
SkShader* CreateCheckerboardShader(SkColor c1, SkColor c2, int size);
/** Draw a checkerboard pattern in the current canvas, restricted to
the current clip. */
void DrawCheckerboard(SkCanvas* canvas,
SkColor color1,
SkColor color2,
int size);
/** A default checkerboard. */
inline void DrawCheckerboard(SkCanvas* canvas) {
sk_tools::DrawCheckerboard(canvas, 0xFF999999, 0xFF666666, 8);
}
} // namespace sk_tools
#endif // Checkerboard_DEFINED

View File

@ -10,6 +10,7 @@
#include "SkBitmap.h"
#include "SkCanvas.h"
#include "SkShader.h"
#include "SkTestScalerContext.h"
DEFINE_bool(portableFonts, false, "Use portable fonts");
@ -59,4 +60,20 @@ void write_pixels(SkCanvas* canvas, const SkBitmap& bitmap, int x, int y,
canvas->writePixels(info, tmp.getPixels(), tmp.rowBytes(), x, y);
}
SkShader* create_checkerboard_shader(SkColor c1, SkColor c2, int size) {
SkBitmap bm;
bm.allocN32Pixels(2 * size, 2 * size);
bm.eraseColor(c1);
bm.eraseArea(SkIRect::MakeLTRB(0, 0, size, size), c2);
bm.eraseArea(SkIRect::MakeLTRB(size, size, 2 * size, 2 * size), c2);
return SkShader::CreateBitmapShader(
bm, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);
}
void draw_checkerboard(SkCanvas* canvas, SkColor c1, SkColor c2, int size) {
SkPaint paint;
paint.setShader(create_checkerboard_shader(c1, c2, size))->unref();
canvas->drawPaint(paint);
}
} // namespace sk_tool_utils

View File

@ -8,12 +8,14 @@
#ifndef sk_tool_utils_DEFINED
#define sk_tool_utils_DEFINED
#include "SkColor.h"
#include "SkImageInfo.h"
#include "SkTypeface.h"
class SkBitmap;
class SkCanvas;
class SkPaint;
class SkShader;
class SkTestFont;
namespace sk_tool_utils {
@ -38,6 +40,21 @@ namespace sk_tool_utils {
SkTypeface* create_font(const char* name, SkTypeface::Style );
SkTypeface* resource_font(const char* name, SkTypeface::Style );
/** Returns a newly created CheckerboardShader. */
SkShader* create_checkerboard_shader(SkColor c1, SkColor c2, int size);
/** Draw a checkerboard pattern in the current canvas, restricted to
the current clip. */
void draw_checkerboard(SkCanvas* canvas,
SkColor color1,
SkColor color2,
int size);
/** A default checkerboard. */
inline void draw_checkerboard(SkCanvas* canvas) {
sk_tool_utils::draw_checkerboard(canvas, 0xFF999999, 0xFF666666, 8);
}
} // namespace sk_tool_utils
#endif // sk_tool_utils_DEFINED