skia2/modules/sksg/include/SkSGGradient.h
Mike Klein c0bd9f9fe5 rewrite includes to not need so much -Ifoo
Current strategy: everything from the top

Things to look at first are the manual changes:

   - added tools/rewrite_includes.py
   - removed -Idirectives from BUILD.gn
   - various compile.sh simplifications
   - tweak tools/embed_resources.py
   - update gn/find_headers.py to write paths from the top
   - update gn/gn_to_bp.py SkUserConfig.h layout
     so that #include "include/config/SkUserConfig.h" always
     gets the header we want.

No-Presubmit: true
Change-Id: I73a4b181654e0e38d229bc456c0d0854bae3363e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/209706
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Hal Canary <halcanary@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
2019-04-24 16:27:11 +00:00

106 lines
2.7 KiB
C++

/*
* Copyright 2018 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkSGGradient_DEFINED
#define SkSGGradient_DEFINED
#include "modules/sksg/include/SkSGRenderEffect.h"
#include "include/core/SkColor.h"
#include "include/core/SkPoint.h"
#include "include/core/SkScalar.h"
#include "include/core/SkShader.h"
#include <vector>
namespace sksg {
/**
* Gradient base class.
*/
class Gradient : public Shader {
public:
struct ColorStop {
SkScalar fPosition;
SkColor fColor;
bool operator==(const ColorStop& other) const {
return fPosition == other.fPosition && fColor == other.fColor;
}
};
SG_ATTRIBUTE(ColorStops, std::vector<ColorStop>, fColorStops)
SG_ATTRIBUTE(TileMode , SkTileMode , fTileMode )
protected:
sk_sp<SkShader> onRevalidateShader() final;
virtual sk_sp<SkShader> onMakeShader(const std::vector<SkColor>& colors,
const std::vector<SkScalar>& positions) const = 0;
protected:
Gradient() = default;
private:
std::vector<ColorStop> fColorStops;
SkTileMode fTileMode = SkTileMode::kClamp;
using INHERITED = Shader;
};
class LinearGradient final : public Gradient {
public:
static sk_sp<LinearGradient> Make() {
return sk_sp<LinearGradient>(new LinearGradient());
}
SG_ATTRIBUTE(StartPoint, SkPoint, fStartPoint)
SG_ATTRIBUTE(EndPoint , SkPoint, fEndPoint )
protected:
sk_sp<SkShader> onMakeShader(const std::vector<SkColor>& colors,
const std::vector<SkScalar>& positions) const override;
private:
LinearGradient() = default;
SkPoint fStartPoint = SkPoint::Make(0, 0),
fEndPoint = SkPoint::Make(0, 0);
using INHERITED = Gradient;
};
class RadialGradient final : public Gradient {
public:
static sk_sp<RadialGradient> Make() {
return sk_sp<RadialGradient>(new RadialGradient());
}
SG_ATTRIBUTE(StartCenter, SkPoint , fStartCenter)
SG_ATTRIBUTE(EndCenter , SkPoint , fEndCenter )
SG_ATTRIBUTE(StartRadius, SkScalar, fStartRadius)
SG_ATTRIBUTE(EndRadius , SkScalar, fEndRadius )
protected:
sk_sp<SkShader> onMakeShader(const std::vector<SkColor>& colors,
const std::vector<SkScalar>& positions) const override;
private:
RadialGradient() = default;
SkPoint fStartCenter = SkPoint::Make(0, 0),
fEndCenter = SkPoint::Make(0, 0);
SkScalar fStartRadius = 0,
fEndRadius = 0;
using INHERITED = Gradient;
};
} // namespace sksg
#endif // SkSGGradient_DEFINED