Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
SkReadBuffer.cpp File Reference
#include "src/core/SkReadBuffer.h"
#include "include/core/SkAlphaType.h"
#include "include/core/SkData.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageGenerator.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkM44.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPath.h"
#include "include/core/SkPixmap.h"
#include "include/core/SkPoint3.h"
#include "include/core/SkRRect.h"
#include "include/core/SkRegion.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkTypeface.h"
#include "include/private/base/SkMalloc.h"
#include "src/base/SkAutoMalloc.h"
#include "src/base/SkMathPriv.h"
#include "src/base/SkSafeMath.h"
#include "src/core/SkMatrixPriv.h"
#include "src/core/SkMipmapBuilder.h"
#include "src/core/SkWriteBuffer.h"
#include <memory>
#include <optional>
#include <utility>

Go to the source code of this file.

Functions

static sk_sp< SkImagedeserialize_image (sk_sp< SkData > data, SkDeserialProcs dProcs, std::optional< SkAlphaType > alphaType)
 
static sk_sp< SkImageadd_mipmaps (sk_sp< SkImage > img, sk_sp< SkData > data, SkDeserialProcs dProcs, std::optional< SkAlphaType > alphaType)
 

Function Documentation

◆ add_mipmaps()

static sk_sp< SkImage > add_mipmaps ( sk_sp< SkImage img,
sk_sp< SkData data,
SkDeserialProcs  dProcs,
std::optional< SkAlphaType alphaType 
)
static

Definition at line 364 of file SkReadBuffer.cpp.

365 {
367
368 SkReadBuffer buffer(data->data(), data->size());
369 int count = buffer.read32();
370 if (builder.countLevels() != count) {
371 return img;
372 }
373 for (int i = 0; i < count; ++i) {
374 size_t size = buffer.read32();
375 const void* ptr = buffer.skip(size);
376 if (!ptr) {
377 return img;
378 }
379 // This use of SkData::MakeWithoutCopy is safe because the image goes
380 // out of scope after we read the pixels from it, so we are sure the
381 // data (from buffer) outlives the image.
383 alphaType);
384 if (!mip) {
385 return img;
386 }
387
388 SkPixmap pm = builder.level(i);
389 if (mip->dimensions() != pm.dimensions()) {
390 return img;
391 }
392 if (!mip->readPixels(nullptr, pm, 0, 0)) {
393 return img;
394 }
395 }
396 if (!buffer.isValid()) {
397 return img;
398 }
399 sk_sp<SkImage> raster = img->makeRasterImage();
400 if (!raster) {
401 return img;
402 }
403 sk_sp<SkImage> rasterWithMips = builder.attachTo(raster);
404 SkASSERT(rasterWithMips); // attachTo should never return null
405 return rasterWithMips;
406}
int count
#define SkASSERT(cond)
Definition SkAssert.h:116
static sk_sp< SkImage > deserialize_image(sk_sp< SkData > data, SkDeserialProcs dProcs, std::optional< SkAlphaType > alphaType)
static sk_sp< SkData > MakeWithoutCopy(const void *data, size_t length)
Definition SkData.h:116
sk_sp< SkImage > makeRasterImage(GrDirectContext *, CachingHint cachingHint=kDisallow_CachingHint) const
Definition SkImage.cpp:267
const SkImageInfo & imageInfo() const
Definition SkImage.h:279
SkISize dimensions() const
Definition SkPixmap.h:171
static const uint8_t buffer[]
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
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

◆ deserialize_image()

static sk_sp< SkImage > deserialize_image ( sk_sp< SkData data,
SkDeserialProcs  dProcs,
std::optional< SkAlphaType alphaType 
)
static

Definition at line 338 of file SkReadBuffer.cpp.

339 {
341 if (dProcs.fImageDataProc) {
342 image = dProcs.fImageDataProc(data, alphaType, dProcs.fImageCtx);
343 } else if (dProcs.fImageProc) {
344#if !defined(SK_LEGACY_DESERIAL_IMAGE_PROC)
345 image = dProcs.fImageProc(data->data(), data->size(), dProcs.fImageCtx);
346#else
347 image = dProcs.fImageProc(data->data(), data->size(), alphaType, dProcs.fImageCtx);
348#endif
349 }
350 if (image) {
351 return image;
352 }
353#if !defined(SK_DISABLE_LEGACY_IMAGE_READBUFFER)
354 // The default implementation will encode to PNG unless the input SkImages came from
355 // a codec that was built-in (e.g. JPEG/WEBP). Thus, we should be sure to try all
356 // available codecs when reading images out of an SKP.
357 return SkImages::DeferredFromEncodedData(std::move(data), alphaType);
358#else
359 SkDEBUGFAIL("Need to set image proc in SkDeserialProcs");
360 return nullptr;
361#endif
362}
#define SkDEBUGFAIL(message)
Definition SkAssert.h:118
sk_sp< SkImage > image
Definition examples.cpp:29
SK_API sk_sp< SkImage > DeferredFromEncodedData(sk_sp< SkData > encoded, std::optional< SkAlphaType > alphaType=std::nullopt)
SkDeserialImageProc fImageProc
SkDeserialImageFromDataProc fImageDataProc