Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
SkWriteBuffer.cpp File Reference
#include "src/core/SkWriteBuffer.h"
#include "include/core/SkAlphaType.h"
#include "include/core/SkData.h"
#include "include/core/SkFlattenable.h"
#include "include/core/SkImage.h"
#include "include/core/SkPoint.h"
#include "include/core/SkPoint3.h"
#include "include/core/SkRect.h"
#include "include/core/SkTypeface.h"
#include "include/private/base/SkAssert.h"
#include "include/private/base/SkTFitsIn.h"
#include "include/private/base/SkTo.h"
#include "src/core/SkMatrixPriv.h"
#include "src/core/SkMipmap.h"
#include "src/core/SkPaintPriv.h"
#include "src/core/SkPtrRecorder.h"
#include "src/image/SkImage_Base.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkStream.h"
#include "include/encode/SkPngEncoder.h"
#include <cstring>
#include <utility>

Go to the source code of this file.

Functions

static sk_sp< SkDataserialize_image (const SkImage *image, SkSerialProcs procs)
 
static sk_sp< SkDataserialize_mipmap (const SkMipmap *mipmap, SkSerialProcs procs)
 

Function Documentation

◆ serialize_image()

static sk_sp< SkData > serialize_image ( const SkImage image,
SkSerialProcs  procs 
)
static

Definition at line 162 of file SkWriteBuffer.cpp.

162 {
164 if (procs.fImageProc) {
165 data = procs.fImageProc(const_cast<SkImage*>(image), procs.fImageCtx);
166 }
167 if (data) {
168 return data;
169 }
170 // Check to see if the image's source was an encoded block of data.
171 // If so, just use that.
173 if (data) {
174 return data;
175 }
176#if !defined(SK_DISABLE_LEGACY_PNG_WRITEBUFFER)
177 SkBitmap bm;
178 auto ib = as_IB(image);
179 if (!ib->getROPixels(ib->directContext(), &bm)) {
180 return nullptr;
181 }
183 if (SkPngEncoder::Encode(&stream, bm.pixmap(), SkPngEncoder::Options())) {
184 return stream.detachAsData();
185 }
186#endif
187 return nullptr;
188}
static SkImage_Base * as_IB(SkImage *image)
const SkPixmap & pixmap() const
Definition SkBitmap.h:133
sk_sp< SkData > refEncodedData() const
Definition SkImage.cpp:214
sk_sp< SkImage > image
Definition examples.cpp:29
SK_API bool Encode(SkWStream *dst, const SkPixmap &src, const Options &options)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41
SkSerialImageProc fImageProc

◆ serialize_mipmap()

static sk_sp< SkData > serialize_mipmap ( const SkMipmap mipmap,
SkSerialProcs  procs 
)
static

Definition at line 190 of file SkWriteBuffer.cpp.

190 {
191 /* Format
192 count_levels:32
193 for each level, starting with the biggest (index 0 in our iterator)
194 encoded_size:32
195 encoded_data (padded)
196 */
197 const int count = mipmap->countLevels();
198
199 // This buffer does not need procs because it is just writing SkDatas
202 for (int i = 0; i < count; ++i) {
204 if (mipmap->getLevel(i, &level)) {
205 sk_sp<SkImage> levelImage = SkImages::RasterFromPixmap(level.fPixmap, nullptr, nullptr);
206 sk_sp<SkData> levelData = serialize_image(levelImage.get(), procs);
207 buffer.writeDataAsByteArray(levelData.get());
208 } else {
209 return nullptr;
210 }
211 }
212 return buffer.snapshotAsData();
213}
int count
static sk_sp< SkData > serialize_image(const SkImage *image, SkSerialProcs procs)
int countLevels() const
Definition SkMipmap.cpp:276
bool getLevel(int index, Level *) const
Definition SkMipmap.cpp:280
void write32(int32_t value)
T * get() const
Definition SkRefCnt.h:303
static const uint8_t buffer[]
SK_API sk_sp< SkImage > RasterFromPixmap(const SkPixmap &pixmap, RasterReleaseProc rasterReleaseProc, ReleaseContext releaseContext)