1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CanvasRenderingContext2DState_h
#define CanvasRenderingContext2DState_h
#include "core/css/CSSFontSelectorClient.h"
#include "modules/canvas2d/ClipList.h"
#include "platform/fonts/Font.h"
#include "platform/transforms/AffineTransform.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "wtf/Vector.h"
namespace blink {
class CanvasRenderingContext2D;
class CanvasStyle;
class CSSValue;
class Element;
class CanvasRenderingContext2DState final
: public GarbageCollectedFinalized<CanvasRenderingContext2DState>,
public CSSFontSelectorClient {
WTF_MAKE_NONCOPYABLE(CanvasRenderingContext2DState);
USING_GARBAGE_COLLECTED_MIXIN(CanvasRenderingContext2DState);
public:
static CanvasRenderingContext2DState* create() {
return new CanvasRenderingContext2DState;
}
~CanvasRenderingContext2DState() override;
DECLARE_VIRTUAL_TRACE();
enum ClipListCopyMode { CopyClipList, DontCopyClipList };
enum PaintType {
FillPaintType,
StrokePaintType,
ImagePaintType,
};
static CanvasRenderingContext2DState* create(
const CanvasRenderingContext2DState& other,
ClipListCopyMode mode) {
return new CanvasRenderingContext2DState(other, mode);
}
// CSSFontSelectorClient implementation
void fontsNeedUpdate(CSSFontSelector*) override;
bool hasUnrealizedSaves() const { return m_unrealizedSaveCount; }
void save() { ++m_unrealizedSaveCount; }
void restore() { --m_unrealizedSaveCount; }
void resetUnrealizedSaveCount() { m_unrealizedSaveCount = 0; }
void setLineDash(const Vector<double>&);
const Vector<double>& lineDash() const { return m_lineDash; }
void setShouldAntialias(bool);
bool shouldAntialias() const;
void setLineDashOffset(double);
double lineDashOffset() const { return m_lineDashOffset; }
// setTransform returns true iff transform is invertible;
void setTransform(const AffineTransform&);
void resetTransform();
AffineTransform transform() const { return m_transform; }
bool isTransformInvertible() const { return m_isTransformInvertible; }
void clipPath(const SkPath&, AntiAliasingMode);
bool hasClip() const { return m_hasClip; }
bool hasComplexClip() const { return m_hasComplexClip; }
void playbackClips(SkCanvas* canvas) const { m_clipList.playback(canvas); }
const SkPath& getCurrentClipPath() const {
return m_clipList.getCurrentClipPath();
}
void setFont(const Font&, CSSFontSelector*);
const Font& font() const;
bool hasRealizedFont() const { return m_realizedFont; }
void setUnparsedFont(const String& font) { m_unparsedFont = font; }
const String& unparsedFont() const { return m_unparsedFont; }
void setFontForFilter(const Font& font) { m_fontForFilter = font; }
void setFilter(const CSSValue*);
void setUnparsedFilter(const String& filterString) {
m_unparsedFilter = filterString;
}
const String& unparsedFilter() const { return m_unparsedFilter; }
sk_sp<SkImageFilter> getFilter(Element*,
IntSize canvasSize,
CanvasRenderingContext2D*) const;
bool hasFilter(Element*, IntSize canvasSize, CanvasRenderingContext2D*) const;
void clearResolvedFilter() const;
void setStrokeStyle(CanvasStyle*);
CanvasStyle* strokeStyle() const { return m_strokeStyle.get(); }
void setFillStyle(CanvasStyle*);
CanvasStyle* fillStyle() const { return m_fillStyle.get(); }
CanvasStyle* style(PaintType) const;
enum Direction { DirectionInherit, DirectionRTL, DirectionLTR };
void setDirection(Direction direction) { m_direction = direction; }
Direction getDirection() const { return m_direction; }
void setTextAlign(TextAlign align) { m_textAlign = align; }
TextAlign getTextAlign() const { return m_textAlign; }
void setTextBaseline(TextBaseline baseline) { m_textBaseline = baseline; }
TextBaseline getTextBaseline() const { return m_textBaseline; }
void setLineWidth(double lineWidth) {
m_strokePaint.setStrokeWidth(lineWidth);
}
double lineWidth() const { return m_strokePaint.getStrokeWidth(); }
void setLineCap(LineCap lineCap) {
m_strokePaint.setStrokeCap(static_cast<SkPaint::Cap>(lineCap));
}
LineCap getLineCap() const {
return static_cast<LineCap>(m_strokePaint.getStrokeCap());
}
void setLineJoin(LineJoin lineJoin) {
m_strokePaint.setStrokeJoin(static_cast<SkPaint::Join>(lineJoin));
}
LineJoin getLineJoin() const {
return static_cast<LineJoin>(m_strokePaint.getStrokeJoin());
}
void setMiterLimit(double miterLimit) {
m_strokePaint.setStrokeMiter(miterLimit);
}
double miterLimit() const { return m_strokePaint.getStrokeMiter(); }
void setShadowOffsetX(double);
void setShadowOffsetY(double);
const FloatSize& shadowOffset() const { return m_shadowOffset; }
void setShadowBlur(double);
double shadowBlur() const { return m_shadowBlur; }
void setShadowColor(SkColor);
SkColor shadowColor() const { return m_shadowColor; }
void setGlobalAlpha(double);
double globalAlpha() const { return m_globalAlpha; }
void setGlobalComposite(SkBlendMode);
SkBlendMode globalComposite() const;
void setImageSmoothingEnabled(bool);
bool imageSmoothingEnabled() const;
void setImageSmoothingQuality(const String&);
String imageSmoothingQuality() const;
void setUnparsedStrokeColor(const String& color) {
m_unparsedStrokeColor = color;
}
const String& unparsedStrokeColor() const { return m_unparsedStrokeColor; }
void setUnparsedFillColor(const String& color) {
m_unparsedFillColor = color;
}
const String& unparsedFillColor() const { return m_unparsedFillColor; }
bool shouldDrawShadows() const;
enum ImageType { NoImage, OpaqueImage, NonOpaqueImage };
// If paint will not be used for painting a bitmap, set bitmapOpacity to
// Opaque.
const SkPaint* getPaint(PaintType, ShadowMode, ImageType = NoImage) const;
private:
CanvasRenderingContext2DState();
CanvasRenderingContext2DState(const CanvasRenderingContext2DState&,
ClipListCopyMode);
void updateLineDash() const;
void updateStrokeStyle() const;
void updateFillStyle() const;
void updateFilterQuality() const;
void updateFilterQualityWithSkFilterQuality(const SkFilterQuality&) const;
void shadowParameterChanged();
SkDrawLooper* emptyDrawLooper() const;
SkDrawLooper* shadowOnlyDrawLooper() const;
SkDrawLooper* shadowAndForegroundDrawLooper() const;
sk_sp<SkImageFilter> shadowOnlyImageFilter() const;
sk_sp<SkImageFilter> shadowAndForegroundImageFilter() const;
unsigned m_unrealizedSaveCount;
String m_unparsedStrokeColor;
String m_unparsedFillColor;
Member<CanvasStyle> m_strokeStyle;
Member<CanvasStyle> m_fillStyle;
mutable SkPaint m_strokePaint;
mutable SkPaint m_fillPaint;
mutable SkPaint m_imagePaint;
FloatSize m_shadowOffset;
double m_shadowBlur;
SkColor m_shadowColor;
mutable sk_sp<SkDrawLooper> m_emptyDrawLooper;
mutable sk_sp<SkDrawLooper> m_shadowOnlyDrawLooper;
mutable sk_sp<SkDrawLooper> m_shadowAndForegroundDrawLooper;
mutable sk_sp<SkImageFilter> m_shadowOnlyImageFilter;
mutable sk_sp<SkImageFilter> m_shadowAndForegroundImageFilter;
double m_globalAlpha;
AffineTransform m_transform;
Vector<double> m_lineDash;
double m_lineDashOffset;
String m_unparsedFont;
Font m_font;
Font m_fontForFilter;
String m_unparsedFilter;
Member<const CSSValue> m_filterValue;
mutable sk_sp<SkImageFilter> m_resolvedFilter;
// Text state.
TextAlign m_textAlign;
TextBaseline m_textBaseline;
Direction m_direction;
bool m_realizedFont : 1;
bool m_isTransformInvertible : 1;
bool m_hasClip : 1;
bool m_hasComplexClip : 1;
mutable bool m_fillStyleDirty : 1;
mutable bool m_strokeStyleDirty : 1;
mutable bool m_lineDashDirty : 1;
bool m_imageSmoothingEnabled;
SkFilterQuality m_imageSmoothingQuality;
ClipList m_clipList;
};
} // namespace blink
#endif
|