Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrTextureGenerator.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
11#include "include/core/SkSize.h"
14#include "include/gpu/GrTypes.h"
20#include "src/gpu/Swizzle.h"
26#include <cstdint>
27#include <memory>
28#include <utility>
29
30enum class GrImageTexGenPolicy : int;
31
32namespace skgpu {
33enum class Mipmapped : bool;
34}
35
36static void dispose_external_texture(void *context) {
37 // Reify the unique_ptr so that we delete the `GrExternalTexture` at the end of scope.
38 auto texture = std::unique_ptr<GrExternalTexture>(reinterpret_cast<GrExternalTexture *>(context));
39 texture->dispose();
40}
41
43 : SkImageGenerator(info, uniqueID) {}
44
46 const SkImageInfo& info,
47 skgpu::Mipmapped mipmapped,
48 GrImageTexGenPolicy texGenPolicy) {
49 SkASSERT_RELEASE(fInfo.dimensions() == info.dimensions());
50
51 if (!ctx || ctx->abandoned()) {
52 return {};
53 }
54
55 return this->onGenerateTexture(ctx, info, mipmapped, texGenPolicy);
56}
57
59
61 const SkImageInfo& info,
62 skgpu::Mipmapped mipmapped,
63 GrImageTexGenPolicy texGenPolicy) {
64 std::unique_ptr<GrExternalTexture> externalTexture = generateExternalTexture(ctx, mipmapped);
65 GrBackendTexture backendTexture = externalTexture->getBackendTexture();
66 const GrBackendFormat& format = backendTexture.getBackendFormat();
69 return {};
70 }
71
72 auto cleanupCallback = skgpu::RefCntedCallback::Make(dispose_external_texture, externalTexture.release());
74 backendTexture,
78 std::move(cleanupCallback));
79 if (!proxy) {
80 return {};
81 }
82 static constexpr auto kOrigin = kTopLeft_GrSurfaceOrigin;
84 return GrSurfaceProxyView(std::move(proxy), kOrigin, swizzle);
85}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
static void dispose_external_texture(void *context)
@ kRead_GrIOType
@ kBorrow_GrWrapOwnership
Definition GrTypesPriv.h:78
GrColorType
static constexpr GrColorType SkColorTypeToGrColorType(SkColorType ct)
@ kTopLeft_GrSurfaceOrigin
Definition GrTypes.h:148
#define SkASSERT_RELEASE(cond)
Definition SkAssert.h:100
GrImageTexGenPolicy
Definition SkGr.h:141
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
Type::kYUV Type::kRGBA() int(0.7 *637)
GrBackendFormat getBackendFormat() const
const GrCaps * caps() const
bool areColorTypeAndFormatCompatible(GrColorType grCT, const GrBackendFormat &format) const
Definition GrCaps.cpp:428
skgpu::Swizzle getReadSwizzle(const GrBackendFormat &format, GrColorType colorType) const
Definition GrCaps.cpp:443
virtual std::unique_ptr< GrExternalTexture > generateExternalTexture(GrRecordingContext *, skgpu::Mipmapped)=0
GrSurfaceProxyView onGenerateTexture(GrRecordingContext *, const SkImageInfo &, skgpu::Mipmapped, GrImageTexGenPolicy) override
GrExternalTextureGenerator(const SkImageInfo &info)
sk_sp< GrTextureProxy > wrapBackendTexture(const GrBackendTexture &, GrWrapOwnership, GrWrapCacheable, GrIOType, sk_sp< skgpu::RefCntedCallback >=nullptr)
GrProxyProvider * proxyProvider()
GrRecordingContextPriv priv()
bool abandoned() override
GrTextureGenerator(const SkImageInfo &info, uint32_t uniqueId=kNeedNewImageUniqueID)
GrSurfaceProxyView generateTexture(GrRecordingContext *, const SkImageInfo &info, skgpu::Mipmapped mipmapped, GrImageTexGenPolicy)
virtual GrSurfaceProxyView onGenerateTexture(GrRecordingContext *, const SkImageInfo &, skgpu::Mipmapped, GrImageTexGenPolicy)=0
const SkImageInfo fInfo
static sk_sp< RefCntedCallback > Make(Callback proc, Context ctx)
uint32_t uint32_t * format
FlTexture * texture
Mipmapped
Definition GpuTypes.h:53
SkISize dimensions() const