Flutter Engine
The Flutter Engine
SkWebpCodec.h
Go to the documentation of this file.
1/*
2 * Copyright 2015 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 SkWebpCodec_DEFINED
9#define SkWebpCodec_DEFINED
10
13#include "include/core/SkData.h"
20
21#include <cstddef>
22#include <memory>
23#include <vector>
24
25class SkStream;
26class SkCodec;
27struct SkIRect;
28struct SkImageInfo;
29
30extern "C" {
31 struct WebPDemuxer;
32 void WebPDemuxDelete(WebPDemuxer* dmux);
33}
34
35class SkWebpCodec final : public SkScalingCodec {
36public:
37 // Assumes IsWebp was called and returned true.
38 static std::unique_ptr<SkCodec> MakeFromStream(std::unique_ptr<SkStream>, Result*);
39 static bool IsWebp(const void*, size_t);
40protected:
41 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, int*) override;
43
44 bool onGetValidSubset(SkIRect* /* desiredSubset */) const override;
45
46 int onGetFrameCount() override;
47 bool onGetFrameInfo(int, FrameInfo*) const override;
48 int onGetRepetitionCount() override;
49
50 const SkFrameHolder* getFrameHolder() const override {
51 return &fFrameHolder;
52 }
53
54private:
55 SkWebpCodec(SkEncodedInfo&&, std::unique_ptr<SkStream>, WebPDemuxer*, sk_sp<SkData>,
57
59
60 // fDemux has a pointer into this data.
61 // This should not be freed until the decode is completed.
62 sk_sp<SkData> fData;
63
64 class Frame : public SkFrame {
65 public:
66 Frame(int i, SkEncodedInfo::Alpha alpha)
67 : INHERITED(i)
68 , fReportedAlpha(alpha)
69 {}
70
71 protected:
72 SkEncodedInfo::Alpha onReportedAlpha() const override {
73 return fReportedAlpha;
74 }
75
76 private:
77 const SkEncodedInfo::Alpha fReportedAlpha;
78
79 using INHERITED = SkFrame;
80 };
81
82 class FrameHolder : public SkFrameHolder {
83 public:
84 ~FrameHolder() override {}
85 void setScreenSize(int w, int h) {
88 }
89 Frame* appendNewFrame(bool hasAlpha);
90 const Frame* frame(int i) const;
91 int size() const {
92 return static_cast<int>(fFrames.size());
93 }
94 void reserve(int size) {
95 fFrames.reserve(size);
96 }
97
98 protected:
99 const SkFrame* onGetFrame(int i) const override;
100
101 private:
102 std::vector<Frame> fFrames;
103 };
104
105 FrameHolder fFrameHolder;
106 // Set to true if WebPDemuxGetFrame fails. This only means
107 // that we will cap the frame count to the frames that
108 // succeed.
109 bool fFailed;
110
111 using INHERITED = SkScalingCodec;
112};
113#endif // SkWebpCodec_DEFINED
SkEncodedImageFormat
SkEncodedOrigin
#define INHERITED(method,...)
Definition: SkRecorder.cpp:128
void WebPDemuxDelete(WebPDemuxer *dmux)
Result
Definition: SkCodec.h:76
SkScalingCodec(SkEncodedInfo &&info, XformFormat srcFormat, std::unique_ptr< SkStream > stream, SkEncodedOrigin origin=kTopLeft_SkEncodedOrigin)
bool onGetFrameInfo(int, FrameInfo *) const override
SkEncodedImageFormat onGetEncodedFormat() const override
Definition: SkWebpCodec.h:42
int onGetFrameCount() override
static bool IsWebp(const void *, size_t)
Definition: SkWebpCodec.cpp:50
static std::unique_ptr< SkCodec > MakeFromStream(std::unique_ptr< SkStream >, Result *)
Definition: SkWebpCodec.cpp:60
bool onGetValidSubset(SkIRect *) const override
int onGetRepetitionCount() override
const SkFrameHolder * getFrameHolder() const override
Definition: SkWebpCodec.h:50
Result onGetPixels(const SkImageInfo &, void *, size_t, const Options &, int *) override
double frame
Definition: examples.cpp:31
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
SkScalar w
SkScalar h
Definition: SkRect.h:32