Flutter Engine
The Flutter Engine
GrTexture.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
8
13#include "include/gpu/GrTypes.h"
14#include "src/core/SkMipmap.h"
15#include "src/gpu/ResourceKey.h"
22
23#include <cstdint>
24
26 if (GrMipmapStatus::kValid == fMipmapStatus) {
27 fMipmapStatus = GrMipmapStatus::kDirty;
28 }
29}
30
33 fMipmapStatus = GrMipmapStatus::kValid;
34}
35
36size_t GrTexture::onGpuMemorySize() const {
37 return GrSurface::ComputeSize(this->backendFormat(), this->dimensions(),
38 /*colorSamplesPerPixel=*/1, this->mipmapped());
39}
40
41/////////////////////////////////////////////////////////////////////////////
43 const SkISize& dimensions,
44 GrProtected isProtected,
45 GrTextureType textureType,
46 GrMipmapStatus mipmapStatus,
47 std::string_view label)
48 : GrSurface(gpu, dimensions, isProtected, label)
49 , fTextureType(textureType)
50 , fMipmapStatus(mipmapStatus) {
51 if (fMipmapStatus == GrMipmapStatus::kNotAllocated) {
52 fMaxMipmapLevel = 0;
53 } else {
54 fMaxMipmapLevel = SkMipmap::ComputeLevelCount(this->width(), this->height());
55 }
56 if (textureType == GrTextureType::kExternal) {
57 this->setReadOnly();
58 }
59}
60
62 GrBackendTexture* backendTexture,
64 if (!texture->unique()) {
65 return false;
66 }
67
68 if (!texture->onStealBackendTexture(backendTexture, releaseProc)) {
69 return false;
70 }
71#ifdef SK_DEBUG
72 GrResourceCache* cache = texture->getContext()->priv().getResourceCache();
73 int preCount = cache->getResourceCount();
74#endif
75 // Ensure that the texture will be released by the cache when we drop the last ref.
76 // A texture that has no refs and no keys should be immediately removed.
77 if (texture->getUniqueKey().isValid()) {
78 texture->resourcePriv().removeUniqueKey();
79 }
80 if (texture->resourcePriv().getScratchKey().isValid()) {
81 texture->resourcePriv().removeScratchKey();
82 }
83#ifdef SK_DEBUG
84 texture.reset();
85 int postCount = cache->getResourceCount();
86 SkASSERT(postCount < preCount);
87#endif
88 return true;
89}
90
92 if (!this->getGpu()->caps()->isFormatCompressed(this->backendFormat())) {
93 int sampleCount = 1;
95 if (const auto* rt = this->asRenderTarget()) {
96 sampleCount = rt->numSamples();
97 renderable = GrRenderable::kYes;
98 }
100 ComputeScratchKey(*this->getGpu()->caps(), this->backendFormat(), this->dimensions(),
101 renderable, sampleCount, this->mipmapped(), isProtected, key);
102 }
103}
104
106 const GrBackendFormat& format,
107 SkISize dimensions,
108 GrRenderable renderable,
109 int sampleCnt,
110 skgpu::Mipmapped mipmapped,
111 GrProtected isProtected,
115 SkASSERT(sampleCnt > 0);
116 SkASSERT(1 == sampleCnt || renderable == GrRenderable::kYes);
117
118 SkASSERT(static_cast<uint32_t>(mipmapped) <= 1);
119 SkASSERT(static_cast<uint32_t>(isProtected) <= 1);
120 SkASSERT(static_cast<uint32_t>(renderable) <= 1);
121 SkASSERT(static_cast<uint32_t>(sampleCnt) < (1 << (32 - 3)));
122
123 uint64_t formatKey = caps.computeFormatKey(format);
124
126 builder[0] = dimensions.width();
128 builder[2] = formatKey & 0xFFFFFFFF;
129 builder[3] = (formatKey >> 32) & 0xFFFFFFFF;
130 builder[4] = (static_cast<uint32_t>(mipmapped) << 0)
131 | (static_cast<uint32_t>(isProtected) << 1)
132 | (static_cast<uint32_t>(renderable) << 2)
133 | (static_cast<uint32_t>(sampleCnt) << 3);
134}
GrMipmapStatus
Definition: GrTypesPriv.h:523
GrTextureType
Definition: GrTypesPriv.h:268
#define SkASSERT(cond)
Definition: SkAssert.h:116
static void releaseProc(const void *ptr, void *context)
Definition: GrCaps.h:57
virtual uint64_t computeFormatKey(const GrBackendFormat &) const =0
GrGpu * getGpu() const
Definition: GrGpu.h:62
virtual GrBackendFormat backendFormat() const =0
SkISize dimensions() const
Definition: GrSurface.h:27
bool isProtected() const
Definition: GrSurface.h:87
int height() const
Definition: GrSurface.h:37
static size_t ComputeSize(const GrBackendFormat &, SkISize dimensions, int colorSamplesPerPixel, skgpu::Mipmapped, bool binSize=false)
Definition: GrSurface.cpp:21
void setReadOnly()
Definition: GrSurface.h:130
virtual GrRenderTarget * asRenderTarget()
Definition: GrSurface.h:65
int width() const
Definition: GrSurface.h:32
void markMipmapsDirty()
Definition: GrTexture.cpp:25
void markMipmapsClean()
Definition: GrTexture.cpp:31
skgpu::Mipmapped mipmapped() const
Definition: GrTexture.h:62
GrTexture(GrGpu *, const SkISize &, GrProtected, GrTextureType, GrMipmapStatus, std::string_view label)
Definition: GrTexture.cpp:42
static bool StealBackendTexture(sk_sp< GrTexture >, GrBackendTexture *, SkImages::BackendTextureReleaseProc *)
Definition: GrTexture.cpp:61
static void ComputeScratchKey(const GrCaps &caps, const GrBackendFormat &format, SkISize dimensions, GrRenderable, int sampleCnt, skgpu::Mipmapped, GrProtected, skgpu::ScratchKey *key)
Definition: GrTexture.cpp:105
void computeScratchKey(skgpu::ScratchKey *) const override
Definition: GrTexture.cpp:91
static int ComputeLevelCount(int baseWidth, int baseHeight)
Definition: SkMipmap.cpp:134
static ResourceType GenerateResourceType()
Definition: ResourceKey.cpp:16
uint32_t ResourceType
Definition: ResourceKey.h:200
uint32_t uint32_t * format
FlTexture * texture
std::function< void(GrBackendTexture)> BackendTextureReleaseProc
Definition: SkImageGanesh.h:43
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets Path to the Flutter assets directory enable service port Allow the VM service to fallback to automatic port selection if binding to a specified port fails trace Trace early application lifecycle Automatically switches to an endless trace buffer trace skia Filters out all Skia trace event categories except those that are specified in this comma separated list dump skp on shader Automatically dump the skp that triggers new shader compilations This is useful for writing custom ShaderWarmUp to reduce jank By this is not enabled to reduce the overhead purge persistent cache
Definition: switches.h:191
Renderable
Definition: GpuTypes.h:69
Mipmapped
Definition: GpuTypes.h:53
Protected
Definition: GpuTypes.h:61
Definition: SkSize.h:16
bool isEmpty() const
Definition: SkSize.h:31
constexpr int32_t width() const
Definition: SkSize.h:36
constexpr int32_t height() const
Definition: SkSize.h:37