Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkFrameHolder.h
Go to the documentation of this file.
1/*
2 * Copyright 2017 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkFrameHolder_DEFINED
9#define SkFrameHolder_DEFINED
10
13#include "include/core/SkRect.h"
17
18/**
19 * Base class for a single frame of an animated image.
20 *
21 * Separate from SkCodec::FrameInfo, which is a pared down
22 * interface that only contains the info the client needs.
23 */
24class SkFrame : public SkNoncopyable {
25public:
26 SkFrame(int id)
27 : fId(id)
28 , fHasAlpha(false)
29 , fRequiredFrame(kUninitialized)
30 , fDisposalMethod(SkCodecAnimation::DisposalMethod::kKeep)
31 , fDuration(0)
32 , fBlend(SkCodecAnimation::Blend::kSrcOver)
33 {
34 fRect.setEmpty();
35 }
36
37 virtual ~SkFrame() {}
38
39 /**
40 * An explicit move constructor, as
41 * https://en.cppreference.com/w/cpp/language/move_constructor says that
42 * there is no implicit move constructor if there are user-declared
43 * destructors, and we have one, immediately above.
44 *
45 * Without a move constructor, it is harder to use an SkFrame, or an
46 * SkFrame subclass, inside a std::vector.
47 */
48 SkFrame(SkFrame&&) = default;
49
50 /**
51 * 0-based index of the frame in the image sequence.
52 */
53 int frameId() const { return fId; }
54
55 /**
56 * How this frame reports its alpha.
57 *
58 * This only considers the rectangle of this frame, and
59 * considers it to have alpha even if it is opaque once
60 * blended with the frame behind it.
61 */
63 return this->onReportedAlpha();
64 }
65
66 /**
67 * Cached value representing whether the frame has alpha,
68 * after compositing with the prior frame.
69 */
70 bool hasAlpha() const { return fHasAlpha; }
71
72 /**
73 * Cache whether the finished frame has alpha.
74 */
75 void setHasAlpha(bool alpha) { fHasAlpha = alpha; }
76
77 /**
78 * Whether enough of the frame has been read to determine
79 * fRequiredFrame and fHasAlpha.
80 */
81 bool reachedStartOfData() const { return fRequiredFrame != kUninitialized; }
82
83 /**
84 * The frame this one depends on.
85 *
86 * Must not be called until fRequiredFrame has been set properly.
87 */
88 int getRequiredFrame() const {
90 return fRequiredFrame;
91 }
92
93 /**
94 * Set the frame that this frame depends on.
95 */
96 void setRequiredFrame(int req) { fRequiredFrame = req; }
97
98 /**
99 * Set the rectangle that is updated by this frame.
100 */
101 void setXYWH(int x, int y, int width, int height) {
102 fRect.setXYWH(x, y, width, height);
103 }
104
105 /**
106 * The rectangle that is updated by this frame.
107 */
108 SkIRect frameRect() const { return fRect; }
109
110 int xOffset() const { return fRect.x(); }
111 int yOffset() const { return fRect.y(); }
112 int width() const { return fRect.width(); }
113 int height() const { return fRect.height(); }
114
116 return fDisposalMethod;
117 }
118
120 fDisposalMethod = disposalMethod;
121 }
122
123 /**
124 * Set the duration (in ms) to show this frame.
125 */
127 fDuration = duration;
128 }
129
130 /**
131 * Duration in ms to show this frame.
132 */
133 int getDuration() const {
134 return fDuration;
135 }
136
138 fBlend = blend;
139 }
140
142 return fBlend;
143 }
144
145 /**
146 * Fill in the FrameInfo with details from this object.
147 */
148 void fillIn(SkCodec::FrameInfo*, bool fullyReceived) const;
149
150protected:
152
153private:
154 inline static constexpr int kUninitialized = -2;
155
156 const int fId;
157 bool fHasAlpha;
158 int fRequiredFrame;
159 SkIRect fRect;
160 SkCodecAnimation::DisposalMethod fDisposalMethod;
161 int fDuration;
163};
164
165/**
166 * Base class for an object which holds the SkFrames of an
167 * image sequence.
168 */
170public:
172 : fScreenWidth(0)
173 , fScreenHeight(0)
174 {}
175
176 virtual ~SkFrameHolder() {}
177
178 /**
179 * Size of the image. Each frame will be contained in
180 * these dimensions (possibly after clipping).
181 */
182 int screenWidth() const { return fScreenWidth; }
183 int screenHeight() const { return fScreenHeight; }
184
185 /**
186 * Compute the opacity and required frame, based on
187 * the frame's reportedAlpha and how it blends
188 * with prior frames.
189 */
191
192 /**
193 * Return the frame with frameId i.
194 */
195 const SkFrame* getFrame(int i) const {
196 return this->onGetFrame(i);
197 }
198
199protected:
202
203 virtual const SkFrame* onGetFrame(int i) const = 0;
204};
205
206#endif // SkFrameHolder_DEFINED
#define SkASSERT(cond)
Definition SkAssert.h:116
@ kSrcOver
r = s + (1-sa)*d
int screenHeight() const
const SkFrame * getFrame(int i) const
virtual ~SkFrameHolder()
int screenWidth() const
virtual const SkFrame * onGetFrame(int i) const =0
void setAlphaAndRequiredFrame(SkFrame *)
Definition SkCodec.cpp:972
int frameId() const
SkFrame(int id)
SkCodecAnimation::DisposalMethod getDisposalMethod() const
void setBlend(SkCodecAnimation::Blend blend)
void setDuration(int duration)
virtual SkEncodedInfo::Alpha onReportedAlpha() const =0
SkFrame(SkFrame &&)=default
void setRequiredFrame(int req)
void fillIn(SkCodec::FrameInfo *, bool fullyReceived) const
Definition SkCodec.cpp:908
void setHasAlpha(bool alpha)
int xOffset() const
SkIRect frameRect() const
int yOffset() const
SkCodecAnimation::Blend getBlend() const
bool hasAlpha() const
SkEncodedInfo::Alpha reportedAlpha() const
int getRequiredFrame() const
void setDisposalMethod(SkCodecAnimation::DisposalMethod disposalMethod)
int getDuration() const
int height() const
void setXYWH(int x, int y, int width, int height)
bool reachedStartOfData() const
int width() const
virtual ~SkFrame()
double duration
Definition examples.cpp:30
static SkColor blend(SkColor dst, SkColor src, void(*mode)(float, float, float, float *, float *, float *))
Definition hsl.cpp:142
double y
double x
constexpr int32_t x() const
Definition SkRect.h:141
constexpr int32_t y() const
Definition SkRect.h:148
constexpr int32_t height() const
Definition SkRect.h:165
constexpr int32_t width() const
Definition SkRect.h:158
void setEmpty()
Definition SkRect.h:242
void setXYWH(int32_t x, int32_t y, int32_t width, int32_t height)
Definition SkRect.h:268
const uintptr_t id