Flutter Engine
The Flutter Engine
SkImage_RasterPinnable.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
9
21#include "src/gpu/ganesh/SkGr.h"
24
25#include <memory>
26#include <tuple>
27
28std::tuple<GrSurfaceProxyView, GrColorType> SkImage_RasterPinnable::asView(
29 GrRecordingContext* rContext,
30 skgpu::Mipmapped mipmapped,
32 if (fPinnedData) {
33 // We ignore the mipmap request here. If the pinned view isn't mipmapped then we will
34 // fallback to bilinear. The pin API is used by Android Framework which does not expose
35 // mipmapping. Moreover, we're moving towards requiring that images be made with mip levels
36 // if mipmapping is desired (skbug.com/10411)
37 mipmapped = skgpu::Mipmapped::kNo;
40 rContext,
41 fPinnedData->fPinnedView,
42 mipmapped,
43 policy,
44 /*label=*/"TextureForPinnableRasterImageWithPolicyNotEqualKDraw"),
45 fPinnedData->fPinnedColorType};
46 }
47 return {fPinnedData->fPinnedView, fPinnedData->fPinnedColorType};
48 }
49 return skgpu::ganesh::RasterAsView(rContext, this, mipmapped, policy);
50}
51
52namespace SkImages {
53
55 if (!SkImageInfoIsValid(bm.info()) || bm.rowBytes() < bm.info().minRowBytes()) {
56 return nullptr;
57 }
58
59 return sk_make_sp<SkImage_RasterPinnable>(bm);
60}
61
62} // namespace SkImages
63
64namespace skgpu::ganesh {
65
67 auto ib = as_IB(img);
68 if (ib->type() != SkImage_Base::Type::kRasterPinnable) {
69 // Cannot pin images which are not of subclass SkImage_RasterPinnable
70 return false;
71 }
72 auto raster = static_cast<SkImage_RasterPinnable*>(ib);
73 if (!raster->fPinnedData) {
74 auto data = std::make_unique<PinnedData>();
75 std::tie(data->fPinnedView, data->fPinnedColorType) =
77 raster->bitmap(),
78 /*label=*/"ganesh_PinAsTexture",
80 if (!data->fPinnedView) {
81 return false;
82 }
83 data->fPinnedUniqueID = raster->bitmap().getGenerationID();
84 data->fPinnedContextID = rContext->priv().contextID();
85 raster->fPinnedData.swap(data);
86 } else {
87 SkASSERT(raster->fPinnedData->fPinnedCount > 0);
88 SkASSERT(raster->fPinnedData->fPinnedUniqueID != 0);
89 if (rContext->priv().contextID() != raster->fPinnedData->fPinnedContextID) {
90 return false;
91 }
92 }
93 // Note: we only increment if the texture was successfully pinned
94 raster->fPinnedData->fPinnedCount++;
95 return true;
96}
97
99 auto ib = as_IB(img);
100 if (ib->type() != SkImage_Base::Type::kRasterPinnable) {
101 // Cannot pin images which are not of subclass SkImage_RasterPinnable
102 return;
103 }
104 auto raster = static_cast<SkImage_RasterPinnable*>(ib);
105 if (!raster->fPinnedData) {
106 SkASSERT(false);
107 return;
108 }
109
110 SkASSERT(raster->fPinnedData->fPinnedCount > 0);
111 SkASSERT(raster->fPinnedData->fPinnedUniqueID != 0);
112 // It would be good to check rContext->priv().contextID() != fPinnedContextID
113 // but Android used to (maybe still does) call Unpin with a freed context ptr
114
115 raster->fPinnedData->fPinnedCount--;
116 if (raster->fPinnedData->fPinnedCount <= 0) {
117 raster->fPinnedData.reset(nullptr);
118 }
119}
120
121} // namespace skgpu::ganesh
#define SkASSERT(cond)
Definition: SkAssert.h:116
std::tuple< GrSurfaceProxyView, GrColorType > GrMakeCachedBitmapProxyView(GrRecordingContext *rContext, const SkBitmap &bitmap, std::string_view label, skgpu::Mipmapped mipmapped)
Definition: SkGr.cpp:188
GrImageTexGenPolicy
Definition: SkGr.h:141
static bool SkImageInfoIsValid(const SkImageInfo &info)
static SkImage_Base * as_IB(SkImage *image)
Definition: SkImage_Base.h:201
uint32_t contextID() const
GrRecordingContextPriv priv()
size_t rowBytes() const
Definition: SkBitmap.h:238
const SkImageInfo & info() const
Definition: SkBitmap.h:139
std::tuple< GrSurfaceProxyView, GrColorType > asView(GrRecordingContext *, skgpu::Mipmapped, GrImageTexGenPolicy) const
std::unique_ptr< PinnedData > fPinnedData
SK_API sk_sp< SkImage > PinnableRasterFromBitmap(const SkBitmap &)
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 policy
Definition: switches.h:248
std::tuple< GrSurfaceProxyView, GrColorType > RasterAsView(GrRecordingContext *rContext, const SkImage_Raster *raster, skgpu::Mipmapped mipmapped, GrImageTexGenPolicy policy)
bool PinAsTexture(GrRecordingContext *, SkImage *)
GrSurfaceProxyView CopyView(GrRecordingContext *context, GrSurfaceProxyView src, skgpu::Mipmapped mipmapped, GrImageTexGenPolicy policy, std::string_view label)
void UnpinTexture(GrRecordingContext *, SkImage *)
Mipmapped
Definition: GpuTypes.h:53
size_t minRowBytes() const
Definition: SkImageInfo.h:517
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63