Flutter Engine
The Flutter Engine
SkImageGenerator_FromEncoded.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2023 Google LLC
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
10#include "include/core/SkData.h"
18
19#include <memory>
20#include <optional>
21#include <utility>
22
24
26SkGraphics::SetImageGeneratorFromEncodedDataFactory(ImageGeneratorFromEncodedDataFactory factory)
27{
29 gFactory = factory;
30 return prev;
31}
32
34
35std::unique_ptr<SkImageGenerator> MakeFromEncoded(sk_sp<SkData> data,
36 std::optional<SkAlphaType> at) {
37 if (!data || at == kOpaque_SkAlphaType) {
38 return nullptr;
39 }
40 if (gFactory) {
41 if (std::unique_ptr<SkImageGenerator> generator = gFactory(data)) {
42 return generator;
43 }
44 }
46}
47
48} // namespace SkImageGenerators
49
50namespace SkImages {
51
53 std::optional<SkAlphaType> alphaType) {
54 if (nullptr == encoded || encoded->isEmpty()) {
55 return nullptr;
56 }
57 return DeferredFromGenerator(SkImageGenerators::MakeFromEncoded(std::move(encoded), alphaType));
58}
59
60} // namespace SkImages
61
62namespace SkCodecs {
63
64sk_sp<SkImage> DeferredImage(std::unique_ptr<SkCodec> codec, std::optional<SkAlphaType> alphaType) {
66 SkCodecImageGenerator::MakeFromCodec(std::move(codec), alphaType));
67}
68
69} // namespace SkCodecs
static float prev(float f)
@ kOpaque_SkAlphaType
pixel is opaque
Definition: SkAlphaType.h:28
static SkGraphics::ImageGeneratorFromEncodedDataFactory gFactory
static std::unique_ptr< SkImageGenerator > MakeFromEncodedCodec(sk_sp< SkData >, std::optional< SkAlphaType >=std::nullopt)
static std::unique_ptr< SkImageGenerator > MakeFromCodec(std::unique_ptr< SkCodec >, std::optional< SkAlphaType >=std::nullopt)
bool isEmpty() const
Definition: SkData.h:32
std::unique_ptr< SkImageGenerator >(* ImageGeneratorFromEncodedDataFactory)(sk_sp< SkData >)
Definition: SkGraphics.h:144
static ImageGeneratorFromEncodedDataFactory SetImageGeneratorFromEncodedDataFactory(ImageGeneratorFromEncodedDataFactory)
SK_API sk_sp< SkImage > DeferredImage(std::unique_ptr< SkCodec > codec, std::optional< SkAlphaType > alphaType=std::nullopt)
std::unique_ptr< SkImageGenerator > MakeFromEncoded(sk_sp< SkData > data, std::optional< SkAlphaType > at)
SK_API sk_sp< SkImage > DeferredFromEncodedData(sk_sp< SkData > encoded, std::optional< SkAlphaType > alphaType=std::nullopt)
SK_API sk_sp< SkImage > DeferredFromGenerator(std::unique_ptr< SkImageGenerator > imageGenerator)
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63