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.
|
|
|
|
*/
|
2018-12-13 15:08:05 +00:00
|
|
|
|
2011-12-02 19:11:17 +00:00
|
|
|
#include "gm.h"
|
2017-03-22 17:47:51 +00:00
|
|
|
#include "sk_tool_utils.h"
|
2018-12-13 15:08:05 +00:00
|
|
|
#include "SkFont.h"
|
2011-12-02 19:11:17 +00:00
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
2018-01-25 19:07:47 +00:00
|
|
|
static const char* color_type_name(SkColorType colorType) {
|
|
|
|
switch (colorType) {
|
|
|
|
case kUnknown_SkColorType: return "unknown";
|
|
|
|
case kAlpha_8_SkColorType: return "A8";
|
|
|
|
case kRGB_565_SkColorType: return "565";
|
|
|
|
case kARGB_4444_SkColorType: return "4444";
|
|
|
|
case kRGBA_8888_SkColorType: return "8888";
|
|
|
|
case kRGB_888x_SkColorType: return "888x";
|
|
|
|
case kBGRA_8888_SkColorType: return "8888";
|
|
|
|
case kRGBA_1010102_SkColorType: return "1010102";
|
|
|
|
case kRGB_101010x_SkColorType: return "101010x";
|
|
|
|
case kGray_8_SkColorType: return "G8";
|
2019-02-28 16:03:27 +00:00
|
|
|
case kRGBA_F16Norm_SkColorType: return "F16Norm";
|
2018-01-25 19:07:47 +00:00
|
|
|
case kRGBA_F16_SkColorType: return "F16";
|
2018-06-26 15:43:06 +00:00
|
|
|
case kRGBA_F32_SkColorType: return "F32";
|
2018-01-25 19:07:47 +00:00
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
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);
|
2017-02-22 18:21:42 +00:00
|
|
|
canvas->drawRect(SkRect::MakeIWH(width/2, height/2), paint);
|
2011-12-02 19:11:17 +00:00
|
|
|
paint.setColor(SK_ColorGREEN);
|
2017-02-22 18:21:42 +00:00
|
|
|
canvas->drawRect({ SkIntToScalar(width/2), 0, SkIntToScalar(width), SkIntToScalar(height/2) },
|
|
|
|
paint);
|
2011-12-02 19:11:17 +00:00
|
|
|
paint.setColor(SK_ColorBLUE);
|
2017-02-22 18:21:42 +00:00
|
|
|
canvas->drawRect({ 0, SkIntToScalar(height/2), SkIntToScalar(width/2), SkIntToScalar(height) },
|
|
|
|
paint);
|
2011-12-02 19:11:17 +00:00
|
|
|
paint.setColor(SK_ColorYELLOW);
|
2017-02-22 18:21:42 +00:00
|
|
|
canvas->drawRect({ 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() {
|
2018-08-16 14:17:03 +00:00
|
|
|
this->setBGColor(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;
|
2017-04-28 20:06:34 +00:00
|
|
|
src.allocN32Pixels(40, 40, kOpaque_SkAlphaType);
|
2014-02-13 17:14:46 +00:00
|
|
|
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) {
|
2017-04-28 15:15:22 +00:00
|
|
|
sk_tool_utils::copy_to(&fDst[i], gColorTypes[i], src);
|
2011-12-02 19:11:17 +00:00
|
|
|
}
|
|
|
|
|
2018-08-16 14:17:03 +00:00
|
|
|
canvas->clear(0xFFDDDDDD);
|
2011-12-02 19:11:17 +00:00
|
|
|
paint.setAntiAlias(true);
|
2018-12-13 15:08:05 +00:00
|
|
|
|
|
|
|
SkFont font(sk_tool_utils::create_portable_typeface());
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2011-12-02 19:11:17 +00:00
|
|
|
SkScalar width = SkIntToScalar(40);
|
|
|
|
SkScalar height = SkIntToScalar(40);
|
2018-12-13 15:08:05 +00:00
|
|
|
if (font.getSpacing() > height) {
|
|
|
|
height = font.getSpacing();
|
2011-12-02 19:11:17 +00:00
|
|
|
}
|
|
|
|
for (unsigned i = 0; i < NUM_CONFIGS; i++) {
|
2018-01-25 19:07:47 +00:00
|
|
|
const char* name = color_type_name(src.colorType());
|
2018-12-13 15:08:05 +00:00
|
|
|
SkScalar textWidth = font.measureText(name, strlen(name), kUTF8_SkTextEncoding);
|
2011-12-02 19:11:17 +00:00
|
|
|
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
|
2018-01-25 19:07:47 +00:00
|
|
|
const char* name = color_type_name(fDst[i].colorType());
|
2018-12-13 15:08:05 +00:00
|
|
|
SkScalar textWidth = font.measureText(name, strlen(name), kUTF8_SkTextEncoding);
|
2011-12-02 19:11:17 +00:00
|
|
|
SkScalar x = (width - textWidth) / SkScalar(2);
|
2018-12-13 15:08:05 +00:00
|
|
|
SkScalar y = font.getSpacing() / SkScalar(2);
|
|
|
|
canvas->drawSimpleText(name, strlen(name), kUTF8_SkTextEncoding, x, y, font, paint);
|
2011-12-02 19:11:17 +00:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-01-23 15:22:01 +00:00
|
|
|
DEF_GM( return new BitmapCopyGM; )
|
2011-12-02 19:11:17 +00:00
|
|
|
}
|