2011-12-02 19:11:17 +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"
|
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
2014-02-23 03:59:35 +00:00
|
|
|
static const char* gColorTypeNames[] = {
|
|
|
|
"unknown",
|
2011-12-02 19:11:17 +00:00
|
|
|
"A8",
|
|
|
|
"565",
|
|
|
|
"4444",
|
2014-02-23 03:59:35 +00:00
|
|
|
"8888",
|
|
|
|
"8888",
|
|
|
|
"Index8",
|
2011-12-02 19:11:17 +00:00
|
|
|
};
|
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr SkColorType gColorTypes[] = {
|
2014-02-23 03:59:35 +00:00
|
|
|
kRGB_565_SkColorType,
|
|
|
|
kARGB_4444_SkColorType,
|
2014-04-11 17:15:40 +00:00
|
|
|
kN32_SkColorType,
|
2011-12-02 19:11:17 +00:00
|
|
|
};
|
|
|
|
|
2014-02-23 03:59:35 +00:00
|
|
|
#define NUM_CONFIGS SK_ARRAY_COUNT(gColorTypes)
|
2011-12-02 19:11:17 +00:00
|
|
|
|
|
|
|
static void draw_checks(SkCanvas* canvas, int width, int height) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(SK_ColorRED);
|
2012-04-10 17:42:21 +00:00
|
|
|
canvas->drawRectCoords(SkIntToScalar(0), SkIntToScalar(0),
|
|
|
|
SkIntToScalar(width / 2), SkIntToScalar(height / 2), paint);
|
2011-12-02 19:11:17 +00:00
|
|
|
paint.setColor(SK_ColorGREEN);
|
2012-04-10 17:42:21 +00:00
|
|
|
canvas->drawRectCoords(SkIntToScalar(width / 2), SkIntToScalar(0),
|
|
|
|
SkIntToScalar(width), SkIntToScalar(height / 2), paint);
|
2011-12-02 19:11:17 +00:00
|
|
|
paint.setColor(SK_ColorBLUE);
|
2012-04-10 17:42:21 +00:00
|
|
|
canvas->drawRectCoords(SkIntToScalar(0), SkIntToScalar(height / 2),
|
|
|
|
SkIntToScalar(width / 2), SkIntToScalar(height), paint);
|
2011-12-02 19:11:17 +00:00
|
|
|
paint.setColor(SK_ColorYELLOW);
|
2012-04-10 17:42:21 +00:00
|
|
|
canvas->drawRectCoords(SkIntToScalar(width / 2), SkIntToScalar(height / 2),
|
|
|
|
SkIntToScalar(width), SkIntToScalar(height), paint);
|
2011-12-02 19:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class BitmapCopyGM : public GM {
|
|
|
|
public:
|
|
|
|
SkBitmap fDst[NUM_CONFIGS];
|
|
|
|
|
|
|
|
BitmapCopyGM() {
|
2015-06-15 13:51:08 +00:00
|
|
|
this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD));
|
2011-12-02 19:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual SkString onShortName() {
|
|
|
|
return SkString("bitmapcopy");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual SkISize onISize() {
|
2014-06-10 06:59:03 +00:00
|
|
|
return SkISize::Make(540, 330);
|
2011-12-02 19:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void onDraw(SkCanvas* canvas) {
|
|
|
|
SkPaint paint;
|
2014-02-13 17:14:46 +00:00
|
|
|
SkScalar horizMargin = 10;
|
|
|
|
SkScalar vertMargin = 10;
|
2011-12-02 19:11:17 +00:00
|
|
|
|
2014-02-13 17:14:46 +00:00
|
|
|
SkBitmap src;
|
|
|
|
src.allocN32Pixels(40, 40);
|
|
|
|
SkCanvas canvasTmp(src);
|
2013-08-08 07:01:20 +00:00
|
|
|
|
2013-08-07 17:03:09 +00:00
|
|
|
draw_checks(&canvasTmp, 40, 40);
|
2011-12-02 19:11:17 +00:00
|
|
|
|
|
|
|
for (unsigned i = 0; i < NUM_CONFIGS; ++i) {
|
2014-02-23 03:59:35 +00:00
|
|
|
src.copyTo(&fDst[i], gColorTypes[i]);
|
2011-12-02 19:11:17 +00:00
|
|
|
}
|
|
|
|
|
2015-06-15 13:51:08 +00:00
|
|
|
canvas->clear(sk_tool_utils::color_to_565(0xFFDDDDDD));
|
2011-12-02 19:11:17 +00:00
|
|
|
paint.setAntiAlias(true);
|
2015-07-24 19:09:25 +00:00
|
|
|
sk_tool_utils::set_portable_typeface(&paint);
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2011-12-02 19:11:17 +00:00
|
|
|
SkScalar width = SkIntToScalar(40);
|
|
|
|
SkScalar height = SkIntToScalar(40);
|
|
|
|
if (paint.getFontSpacing() > height) {
|
|
|
|
height = paint.getFontSpacing();
|
|
|
|
}
|
|
|
|
for (unsigned i = 0; i < NUM_CONFIGS; i++) {
|
2014-02-23 03:59:35 +00:00
|
|
|
const char* name = gColorTypeNames[src.colorType()];
|
2011-12-02 19:11:17 +00:00
|
|
|
SkScalar textWidth = paint.measureText(name, strlen(name));
|
|
|
|
if (textWidth > width) {
|
|
|
|
width = textWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SkScalar horizOffset = width + horizMargin;
|
|
|
|
SkScalar vertOffset = height + vertMargin;
|
|
|
|
canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < NUM_CONFIGS; i++) {
|
|
|
|
canvas->save();
|
|
|
|
// Draw destination config name
|
2014-02-23 03:59:35 +00:00
|
|
|
const char* name = gColorTypeNames[fDst[i].colorType()];
|
2011-12-02 19:11:17 +00:00
|
|
|
SkScalar textWidth = paint.measureText(name, strlen(name));
|
|
|
|
SkScalar x = (width - textWidth) / SkScalar(2);
|
|
|
|
SkScalar y = paint.getFontSpacing() / SkScalar(2);
|
|
|
|
canvas->drawText(name, strlen(name), x, y, paint);
|
|
|
|
|
|
|
|
// Draw destination bitmap
|
|
|
|
canvas->translate(0, vertOffset);
|
|
|
|
x = (width - 40) / SkScalar(2);
|
|
|
|
canvas->drawBitmap(fDst[i], x, 0, &paint);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
canvas->translate(horizOffset, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static GM* MyFactory(void*) { return new BitmapCopyGM; }
|
|
|
|
static GMRegistry reg(MyFactory);
|
|
|
|
}
|