2013-05-24 14:58:44 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 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"
|
|
|
|
#include "include/core/SkCanvas.h"
|
2019-04-30 17:44:26 +00:00
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkPoint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkShader.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkTileMode.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/effects/SkGradientShader.h"
|
2013-05-24 14:58:44 +00:00
|
|
|
|
|
|
|
class AlphaGradientsGM : public skiagm::GM {
|
|
|
|
public:
|
|
|
|
AlphaGradientsGM() {}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2013-05-24 14:58:44 +00:00
|
|
|
return SkString("alphagradients");
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2013-05-24 14:58:44 +00:00
|
|
|
return SkISize::Make(640, 480);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_grad(SkCanvas* canvas, const SkRect& r,
|
|
|
|
SkColor c0, SkColor c1, bool doPreMul) {
|
|
|
|
SkColor colors[] = { c0, c1 };
|
|
|
|
SkPoint pts[] = { { r.fLeft, r.fTop }, { r.fRight, r.fBottom } };
|
|
|
|
SkPaint paint;
|
|
|
|
uint32_t flags = doPreMul ? SkGradientShader::kInterpolateColorsInPremul_Flag : 0;
|
2016-03-09 02:50:00 +00:00
|
|
|
paint.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, 2,
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode::kClamp, flags, nullptr));
|
2013-05-24 14:58:44 +00:00
|
|
|
canvas->drawRect(r, paint);
|
2013-05-25 07:01:12 +00:00
|
|
|
|
2015-08-27 14:41:13 +00:00
|
|
|
paint.setShader(nullptr);
|
2013-05-24 14:58:44 +00:00
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr struct {
|
2013-05-24 14:58:44 +00:00
|
|
|
SkColor fColor0;
|
|
|
|
SkColor fColor1;
|
|
|
|
} gRec[] = {
|
|
|
|
{ 0xFFFFFFFF, 0x00000000 },
|
|
|
|
{ 0xFFFFFFFF, 0x00FF0000 },
|
|
|
|
{ 0xFFFFFFFF, 0x00FFFF00 },
|
|
|
|
{ 0xFFFFFFFF, 0x00FFFFFF },
|
|
|
|
{ 0xFFFF0000, 0x00000000 },
|
|
|
|
{ 0xFFFF0000, 0x00FF0000 },
|
|
|
|
{ 0xFFFF0000, 0x00FFFF00 },
|
|
|
|
{ 0xFFFF0000, 0x00FFFFFF },
|
|
|
|
{ 0xFF0000FF, 0x00000000 },
|
|
|
|
{ 0xFF0000FF, 0x00FF0000 },
|
|
|
|
{ 0xFF0000FF, 0x00FFFF00 },
|
|
|
|
{ 0xFF0000FF, 0x00FFFFFF },
|
|
|
|
};
|
2013-05-25 07:01:12 +00:00
|
|
|
|
2013-05-24 14:58:44 +00:00
|
|
|
SkRect r = SkRect::MakeWH(300, 30);
|
2013-05-25 07:01:12 +00:00
|
|
|
|
2013-05-24 14:58:44 +00:00
|
|
|
canvas->translate(10, 10);
|
|
|
|
|
|
|
|
for (int doPreMul = 0; doPreMul <= 1; ++doPreMul) {
|
|
|
|
canvas->save();
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
|
|
|
|
draw_grad(canvas, r, gRec[i].fColor0, gRec[i].fColor1, SkToBool(doPreMul));
|
|
|
|
canvas->translate(0, r.height() + 8);
|
|
|
|
}
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(r.width() + 10, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = skiagm::GM;
|
2013-05-24 14:58:44 +00:00
|
|
|
};
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_GM(return new AlphaGradientsGM;)
|