2015-09-18 19:03:13 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkBlendMode.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkFont.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkTextBlob.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkTypeface.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/ToolUtils.h"
|
2015-09-18 19:03:13 +00:00
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr int kWidth = 750;
|
|
|
|
constexpr int kHeight = 750;
|
2015-09-18 19:03:13 +00:00
|
|
|
|
|
|
|
class LcdOverlapGM : public skiagm::GM {
|
|
|
|
public:
|
|
|
|
LcdOverlapGM() {
|
|
|
|
const int kPointSize = 25;
|
|
|
|
fTextHeight = SkIntToScalar(kPointSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkString onShortName() override {
|
|
|
|
return SkString("lcdoverlap");
|
|
|
|
}
|
|
|
|
|
|
|
|
void onOnceBeforeDraw() override {
|
|
|
|
// build text blob
|
|
|
|
SkTextBlobBuilder builder;
|
|
|
|
|
2019-03-20 16:12:10 +00:00
|
|
|
SkFont font(ToolUtils::create_portable_typeface(), 32);
|
2015-09-18 19:03:13 +00:00
|
|
|
const char* text = "able was I ere I saw elba";
|
2018-12-23 03:29:45 +00:00
|
|
|
font.setSubpixel(true);
|
|
|
|
font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
|
|
|
|
// If we use SkTextBlob::MakeFromText, we get very different positioning ... why?
|
2019-03-20 16:12:10 +00:00
|
|
|
ToolUtils::add_to_text_blob(&builder, text, font, 0, 0);
|
2016-09-13 17:00:23 +00:00
|
|
|
fBlob = builder.make();
|
2015-09-18 19:03:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SkISize onISize() override { return SkISize::Make(kWidth, kHeight); }
|
|
|
|
|
2016-10-06 00:33:02 +00:00
|
|
|
void drawTestCase(SkCanvas* canvas, SkScalar x, SkScalar y, SkBlendMode mode,
|
|
|
|
SkBlendMode mode2) {
|
2015-09-18 19:03:13 +00:00
|
|
|
const SkColor colors[] {
|
|
|
|
SK_ColorRED,
|
|
|
|
SK_ColorGREEN,
|
|
|
|
SK_ColorBLUE,
|
|
|
|
SK_ColorYELLOW,
|
|
|
|
SK_ColorCYAN,
|
|
|
|
SK_ColorMAGENTA,
|
|
|
|
};
|
|
|
|
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(colors); i++) {
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(x, y);
|
|
|
|
canvas->rotate(360.0f / SK_ARRAY_COUNT(colors) * i);
|
|
|
|
canvas->translate(-fBlob->bounds().width() / 2.0f + 0.5f, 0);
|
|
|
|
|
|
|
|
SkPaint textPaint;
|
|
|
|
textPaint.setColor(colors[i]);
|
2016-10-06 00:33:02 +00:00
|
|
|
textPaint.setBlendMode(i % 2 == 0 ? mode : mode2);
|
2015-09-18 19:03:13 +00:00
|
|
|
canvas->drawTextBlob(fBlob, 0, 0, textPaint);
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void onDraw(SkCanvas* canvas) override {
|
|
|
|
SkScalar offsetX = kWidth / 4.0f;
|
|
|
|
SkScalar offsetY = kHeight / 4.0f;
|
2016-10-06 00:33:02 +00:00
|
|
|
drawTestCase(canvas, offsetX, offsetY, SkBlendMode::kSrc, SkBlendMode::kSrc);
|
|
|
|
drawTestCase(canvas, 3 * offsetX, offsetY, SkBlendMode::kSrcOver, SkBlendMode::kSrcOver);
|
|
|
|
drawTestCase(canvas, offsetX, 3 * offsetY, SkBlendMode::kHardLight,
|
|
|
|
SkBlendMode::kLuminosity);
|
|
|
|
drawTestCase(canvas, 3 * offsetX, 3 * offsetY, SkBlendMode::kSrcOver, SkBlendMode::kSrc);
|
2015-09-18 19:03:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkScalar fTextHeight;
|
2016-09-13 17:00:23 +00:00
|
|
|
sk_sp<SkTextBlob> fBlob;
|
2015-09-18 19:03:13 +00:00
|
|
|
typedef skiagm::GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
DEF_GM( return new LcdOverlapGM; )
|
|
|
|
}
|