Flutter Engine
The Flutter Engine
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
SkFrameHolder Class Referenceabstract

#include <SkFrameHolder.h>

Inheritance diagram for SkFrameHolder:
SkNoncopyable SkJpegxlCodecPriv SkWuffsFrameHolder

Public Member Functions

 SkFrameHolder ()
 
virtual ~SkFrameHolder ()
 
int screenWidth () const
 
int screenHeight () const
 
void setAlphaAndRequiredFrame (SkFrame *)
 
const SkFramegetFrame (int i) const
 
- Public Member Functions inherited from SkNoncopyable
 SkNoncopyable ()=default
 
 SkNoncopyable (SkNoncopyable &&)=default
 
SkNoncopyableoperator= (SkNoncopyable &&)=default
 

Protected Member Functions

virtual const SkFrameonGetFrame (int i) const =0
 

Protected Attributes

int fScreenWidth
 
int fScreenHeight
 

Detailed Description

Base class for an object which holds the SkFrames of an image sequence.

Definition at line 169 of file SkFrameHolder.h.

Constructor & Destructor Documentation

◆ SkFrameHolder()

SkFrameHolder::SkFrameHolder ( )
inline

Definition at line 171 of file SkFrameHolder.h.

172 : fScreenWidth(0)
173 , fScreenHeight(0)
174 {}

◆ ~SkFrameHolder()

virtual SkFrameHolder::~SkFrameHolder ( )
inlinevirtual

Definition at line 176 of file SkFrameHolder.h.

176{}

Member Function Documentation

◆ getFrame()

const SkFrame * SkFrameHolder::getFrame ( int  i) const
inline

Return the frame with frameId i.

Definition at line 195 of file SkFrameHolder.h.

195 {
196 return this->onGetFrame(i);
197 }
virtual const SkFrame * onGetFrame(int i) const =0

◆ onGetFrame()

virtual const SkFrame * SkFrameHolder::onGetFrame ( int  i) const
protectedpure virtual

Implemented in SkJpegxlCodecPriv, and SkWuffsFrameHolder.

◆ screenHeight()

int SkFrameHolder::screenHeight ( ) const
inline

Definition at line 183 of file SkFrameHolder.h.

183{ return fScreenHeight; }

◆ screenWidth()

int SkFrameHolder::screenWidth ( ) const
inline

Size of the image. Each frame will be contained in these dimensions (possibly after clipping).

Definition at line 182 of file SkFrameHolder.h.

182{ return fScreenWidth; }

◆ setAlphaAndRequiredFrame()

void SkFrameHolder::setAlphaAndRequiredFrame ( SkFrame frame)

Compute the opacity and required frame, based on the frame's reportedAlpha and how it blends with prior frames.

Definition at line 972 of file SkCodec.cpp.

972 {
973 const bool reportsAlpha = frame->reportedAlpha() != SkEncodedInfo::kOpaque_Alpha;
974 const auto screenRect = SkIRect::MakeWH(fScreenWidth, fScreenHeight);
975 const auto frameRect = frame_rect_on_screen(frame->frameRect(), screenRect);
976
977 const int i = frame->frameId();
978 if (0 == i) {
979 frame->setHasAlpha(reportsAlpha || frameRect != screenRect);
980 frame->setRequiredFrame(SkCodec::kNoFrame); // IND1
981 return;
982 }
983
984
985 const bool blendWithPrevFrame = frame->getBlend() == SkCodecAnimation::Blend::kSrcOver;
986 if ((!reportsAlpha || !blendWithPrevFrame) && frameRect == screenRect) {
987 frame->setHasAlpha(reportsAlpha);
988 frame->setRequiredFrame(SkCodec::kNoFrame); // IND2
989 return;
990 }
991
992 const SkFrame* prevFrame = this->getFrame(i-1);
994 const int prevId = prevFrame->frameId();
995 if (0 == prevId) {
996 frame->setHasAlpha(true);
997 frame->setRequiredFrame(SkCodec::kNoFrame); // IND3
998 return;
999 }
1000
1001 prevFrame = this->getFrame(prevId - 1);
1002 }
1003
1004 const bool clearPrevFrame = restore_bg(*prevFrame);
1005 auto prevFrameRect = frame_rect_on_screen(prevFrame->frameRect(), screenRect);
1006
1007 if (clearPrevFrame) {
1008 if (prevFrameRect == screenRect || independent(*prevFrame)) {
1009 frame->setHasAlpha(true);
1010 frame->setRequiredFrame(SkCodec::kNoFrame); // IND4
1011 return;
1012 }
1013 }
1014
1015 if (reportsAlpha && blendWithPrevFrame) {
1016 // Note: We could be more aggressive here. If prevFrame clears
1017 // to background color and covers its required frame (and that
1018 // frame is independent), prevFrame could be marked independent.
1019 // Would this extra complexity be worth it?
1020 frame->setRequiredFrame(prevFrame->frameId()); // DEP5
1021 frame->setHasAlpha(prevFrame->hasAlpha() || clearPrevFrame);
1022 return;
1023 }
1024
1025 while (frameRect.contains(prevFrameRect)) {
1026 const int prevRequiredFrame = prevFrame->getRequiredFrame();
1027 if (prevRequiredFrame == SkCodec::kNoFrame) {
1028 frame->setRequiredFrame(SkCodec::kNoFrame); // IND6
1029 frame->setHasAlpha(true);
1030 return;
1031 }
1032
1033 prevFrame = this->getFrame(prevRequiredFrame);
1034 prevFrameRect = frame_rect_on_screen(prevFrame->frameRect(), screenRect);
1035 }
1036
1037 frame->setRequiredFrame(prevFrame->frameId()); // DEP7
1038 if (restore_bg(*prevFrame)) {
1039 frame->setHasAlpha(true);
1040 return;
1041 }
1043 frame->setHasAlpha(prevFrame->hasAlpha() || (reportsAlpha && !blendWithPrevFrame));
1044}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static bool restore_bg(const SkFrame &frame)
Definition: SkCodec.cpp:926
static SkIRect frame_rect_on_screen(SkIRect frameRect, const SkIRect &screenRect)
Definition: SkCodec.cpp:334
static bool independent(const SkFrame &frame)
Definition: SkCodec.cpp:922
static constexpr int kNoFrame
Definition: SkCodec.h:650
const SkFrame * getFrame(int i) const
int frameId() const
Definition: SkFrameHolder.h:53
SkCodecAnimation::DisposalMethod getDisposalMethod() const
SkIRect frameRect() const
bool hasAlpha() const
Definition: SkFrameHolder.h:70
int getRequiredFrame() const
Definition: SkFrameHolder.h:88
double frame
Definition: examples.cpp:31
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition: SkRect.h:56

Member Data Documentation

◆ fScreenHeight

int SkFrameHolder::fScreenHeight
protected

Definition at line 201 of file SkFrameHolder.h.

◆ fScreenWidth

int SkFrameHolder::fScreenWidth
protected

Definition at line 200 of file SkFrameHolder.h.


The documentation for this class was generated from the following files: