2011-12-21 14:27:14 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gm.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkPath.h"
|
|
|
|
|
|
|
|
/** Draw a 2px border around the target, then red behind the target;
|
|
|
|
set the clip to match the target, then draw >> the target in blue.
|
|
|
|
*/
|
|
|
|
|
2014-02-13 17:14:46 +00:00
|
|
|
static void draw(SkCanvas* canvas, SkRect& target, int x, int y) {
|
2011-12-21 14:27:14 +00:00
|
|
|
SkPaint borderPaint;
|
|
|
|
borderPaint.setColor(SkColorSetRGB(0x0, 0xDD, 0x0));
|
|
|
|
borderPaint.setAntiAlias(true);
|
|
|
|
SkPaint backgroundPaint;
|
|
|
|
backgroundPaint.setColor(SkColorSetRGB(0xDD, 0x0, 0x0));
|
|
|
|
backgroundPaint.setAntiAlias(true);
|
|
|
|
SkPaint foregroundPaint;
|
|
|
|
foregroundPaint.setColor(SkColorSetRGB(0x0, 0x0, 0xDD));
|
|
|
|
foregroundPaint.setAntiAlias(true);
|
|
|
|
|
|
|
|
canvas->save();
|
2011-12-28 19:40:48 +00:00
|
|
|
canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
|
|
|
|
target.inset(SkIntToScalar(-2), SkIntToScalar(-2));
|
2011-12-21 14:27:14 +00:00
|
|
|
canvas->drawRect(target, borderPaint);
|
2011-12-28 19:40:48 +00:00
|
|
|
target.inset(SkIntToScalar(2), SkIntToScalar(2));
|
2011-12-21 14:27:14 +00:00
|
|
|
canvas->drawRect(target, backgroundPaint);
|
|
|
|
canvas->clipRect(target, SkRegion::kIntersect_Op, true);
|
2011-12-28 19:40:48 +00:00
|
|
|
target.inset(SkIntToScalar(-4), SkIntToScalar(-4));
|
2011-12-21 14:27:14 +00:00
|
|
|
canvas->drawRect(target, foregroundPaint);
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
|
2014-02-13 17:14:46 +00:00
|
|
|
static void draw_square(SkCanvas* canvas, int x, int y) {
|
2011-12-21 14:27:14 +00:00
|
|
|
SkRect target (SkRect::MakeWH(10 * SK_Scalar1, 10 * SK_Scalar1));
|
|
|
|
draw(canvas, target, x, y);
|
|
|
|
}
|
|
|
|
|
2014-02-13 17:14:46 +00:00
|
|
|
static void draw_column(SkCanvas* canvas, int x, int y) {
|
2011-12-21 14:27:14 +00:00
|
|
|
SkRect target (SkRect::MakeWH(1 * SK_Scalar1, 10 * SK_Scalar1));
|
|
|
|
draw(canvas, target, x, y);
|
|
|
|
}
|
|
|
|
|
2014-02-13 17:14:46 +00:00
|
|
|
static void draw_bar(SkCanvas* canvas, int x, int y) {
|
2011-12-21 14:27:14 +00:00
|
|
|
SkRect target (SkRect::MakeWH(10 * SK_Scalar1, 1 * SK_Scalar1));
|
|
|
|
draw(canvas, target, x, y);
|
|
|
|
}
|
|
|
|
|
2014-02-13 17:14:46 +00:00
|
|
|
static void draw_rect_tests(SkCanvas* canvas) {
|
2011-12-21 14:27:14 +00:00
|
|
|
draw_square(canvas, 10, 10);
|
|
|
|
draw_column(canvas, 30, 10);
|
|
|
|
draw_bar(canvas, 10, 30);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Test a set of clipping problems discovered while writing blitAntiRect,
|
|
|
|
and test all the code paths through the clipping blitters.
|
|
|
|
Each region should show as a blue center surrounded by a 2px green
|
|
|
|
border, with no red.
|
|
|
|
*/
|
|
|
|
|
2013-05-23 17:04:19 +00:00
|
|
|
class AAClipGM : public skiagm::GM {
|
2011-12-21 14:27:14 +00:00
|
|
|
public:
|
|
|
|
AAClipGM() {
|
2012-09-18 15:14:33 +00:00
|
|
|
|
2011-12-21 14:27:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-01-09 18:06:39 +00:00
|
|
|
SkString onShortName() SK_OVERRIDE {
|
2011-12-21 14:27:14 +00:00
|
|
|
return SkString("aaclip");
|
|
|
|
}
|
|
|
|
|
2015-01-09 18:06:39 +00:00
|
|
|
SkISize onISize() SK_OVERRIDE {
|
2014-04-14 15:02:19 +00:00
|
|
|
return SkISize::Make(240, 120);
|
2011-12-21 14:27:14 +00:00
|
|
|
}
|
|
|
|
|
2015-01-09 18:06:39 +00:00
|
|
|
void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
2011-12-21 14:27:14 +00:00
|
|
|
// Initial pixel-boundary-aligned draw
|
|
|
|
draw_rect_tests(canvas);
|
|
|
|
|
|
|
|
// Repeat 4x with .2, .4, .6, .8 px offsets
|
|
|
|
canvas->translate(SK_Scalar1 / 5, SK_Scalar1 / 5);
|
2011-12-28 19:40:48 +00:00
|
|
|
canvas->translate(SkIntToScalar(50), 0);
|
2011-12-21 14:27:14 +00:00
|
|
|
draw_rect_tests(canvas);
|
|
|
|
|
|
|
|
canvas->translate(SK_Scalar1 / 5, SK_Scalar1 / 5);
|
2011-12-28 19:40:48 +00:00
|
|
|
canvas->translate(SkIntToScalar(50), 0);
|
2011-12-21 14:27:14 +00:00
|
|
|
draw_rect_tests(canvas);
|
|
|
|
|
|
|
|
canvas->translate(SK_Scalar1 / 5, SK_Scalar1 / 5);
|
2011-12-28 19:40:48 +00:00
|
|
|
canvas->translate(SkIntToScalar(50), 0);
|
2011-12-21 14:27:14 +00:00
|
|
|
draw_rect_tests(canvas);
|
|
|
|
|
|
|
|
canvas->translate(SK_Scalar1 / 5, SK_Scalar1 / 5);
|
2011-12-28 19:40:48 +00:00
|
|
|
canvas->translate(SkIntToScalar(50), 0);
|
2011-12-21 14:27:14 +00:00
|
|
|
draw_rect_tests(canvas);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-05-23 17:04:19 +00:00
|
|
|
typedef skiagm::GM INHERITED;
|
2011-12-21 14:27:14 +00:00
|
|
|
};
|
|
|
|
|
2013-05-23 17:04:19 +00:00
|
|
|
DEF_GM( return SkNEW(AAClipGM); )
|
2014-04-22 20:24:33 +00:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifdef SK_BUILD_FOR_MAC
|
|
|
|
|
|
|
|
static SkCanvas* make_canvas(const SkBitmap& bm) {
|
|
|
|
const SkImageInfo& info = bm.info();
|
|
|
|
if (info.bytesPerPixel() == 4) {
|
|
|
|
return SkCanvas::NewRasterDirectN32(info.width(), info.height(),
|
|
|
|
(SkPMColor*)bm.getPixels(),
|
|
|
|
bm.rowBytes());
|
|
|
|
} else {
|
|
|
|
return SkNEW_ARGS(SkCanvas, (bm));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "SkCGUtils.h"
|
|
|
|
static void test_image(SkCanvas* canvas, const SkImageInfo& info) {
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocPixels(info);
|
|
|
|
|
|
|
|
SkAutoTUnref<SkCanvas> newc(make_canvas(bm));
|
|
|
|
if (info.isOpaque()) {
|
|
|
|
bm.eraseColor(SK_ColorGREEN);
|
|
|
|
} else {
|
|
|
|
bm.eraseColor(0);
|
|
|
|
}
|
2014-04-23 03:04:11 +00:00
|
|
|
|
2014-04-22 20:24:33 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
newc->drawCircle(50, 50, 49, paint);
|
|
|
|
canvas->drawBitmap(bm, 10, 10);
|
2014-04-23 03:04:11 +00:00
|
|
|
|
2014-04-22 20:24:33 +00:00
|
|
|
CGImageRef image = SkCreateCGImageRefWithColorspace(bm, NULL);
|
2014-04-23 03:04:11 +00:00
|
|
|
|
2014-04-22 20:24:33 +00:00
|
|
|
SkBitmap bm2;
|
|
|
|
SkCreateBitmapFromCGImage(&bm2, image);
|
|
|
|
CGImageRelease(image);
|
2014-04-23 03:04:11 +00:00
|
|
|
|
2014-04-22 20:24:33 +00:00
|
|
|
canvas->drawBitmap(bm2, 10, 120);
|
|
|
|
}
|
|
|
|
|
|
|
|
class CGImageGM : public skiagm::GM {
|
|
|
|
public:
|
|
|
|
CGImageGM() {}
|
2014-04-23 03:04:11 +00:00
|
|
|
|
2014-04-22 20:24:33 +00:00
|
|
|
protected:
|
2015-01-09 18:06:39 +00:00
|
|
|
SkString onShortName() SK_OVERRIDE {
|
2014-04-22 20:24:33 +00:00
|
|
|
return SkString("cgimage");
|
|
|
|
}
|
2014-04-23 03:04:11 +00:00
|
|
|
|
2015-01-09 18:06:39 +00:00
|
|
|
SkISize onISize() SK_OVERRIDE {
|
2014-04-22 20:24:33 +00:00
|
|
|
return SkISize::Make(800, 250);
|
|
|
|
}
|
2014-04-23 03:04:11 +00:00
|
|
|
|
2015-01-09 18:06:39 +00:00
|
|
|
void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
2014-04-22 20:24:33 +00:00
|
|
|
const struct {
|
|
|
|
SkColorType fCT;
|
|
|
|
SkAlphaType fAT;
|
|
|
|
} rec[] = {
|
|
|
|
{ kRGB_565_SkColorType, kOpaque_SkAlphaType },
|
|
|
|
|
|
|
|
{ kRGBA_8888_SkColorType, kPremul_SkAlphaType },
|
|
|
|
{ kRGBA_8888_SkColorType, kUnpremul_SkAlphaType },
|
|
|
|
{ kRGBA_8888_SkColorType, kOpaque_SkAlphaType },
|
|
|
|
|
|
|
|
{ kBGRA_8888_SkColorType, kPremul_SkAlphaType },
|
|
|
|
{ kBGRA_8888_SkColorType, kUnpremul_SkAlphaType },
|
|
|
|
{ kBGRA_8888_SkColorType, kOpaque_SkAlphaType },
|
|
|
|
};
|
2014-04-23 03:04:11 +00:00
|
|
|
|
2014-04-22 20:24:33 +00:00
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) {
|
|
|
|
SkImageInfo info = SkImageInfo::Make(100, 100, rec[i].fCT, rec[i].fAT);
|
|
|
|
test_image(canvas, info);
|
|
|
|
canvas->translate(info.width() + 10, 0);
|
|
|
|
}
|
|
|
|
}
|
2014-04-23 03:04:11 +00:00
|
|
|
|
2014-04-22 20:24:33 +00:00
|
|
|
private:
|
|
|
|
typedef skiagm::GM INHERITED;
|
|
|
|
};
|
|
|
|
|
2014-04-23 18:05:36 +00:00
|
|
|
#if 0 // Disabled pending fix from reed@
|
2014-04-22 20:24:33 +00:00
|
|
|
DEF_GM( return SkNEW(CGImageGM); )
|
2014-04-23 18:05:36 +00:00
|
|
|
#endif
|
2014-04-22 20:24:33 +00:00
|
|
|
#endif
|