Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
35
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;
94 GrRenderable renderable = GrRenderable::kNo;
95 if (const auto* rt = this->asRenderTarget()) {
96 sampleCount = rt->numSamples();
97 renderable = GrRenderable::kYes;
98 }
99 auto isProtected = this->isProtected() ? GrProtected::kYes : GrProtected::kNo;
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
125 skgpu::ScratchKey::Builder builder(key, kType, 5);
126 builder[0] = dimensions.width();
127 builder[1] = dimensions.height();
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
GrTextureType
#define SkASSERT(cond)
Definition SkAssert.h:116
static void releaseProc(const void *ptr, void *context)
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
size_t onGpuMemorySize() const override
Definition GrTexture.cpp:36
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)
void computeScratchKey(skgpu::ScratchKey *) const override
Definition GrTexture.cpp:91
static int ComputeLevelCount(int baseWidth, int baseHeight)
Definition SkMipmap.cpp:134
static ResourceType GenerateResourceType()
uint32_t ResourceType
uint32_t uint32_t * format
FlTexture * texture
std::function< void(GrBackendTexture)> BackendTextureReleaseProc
Renderable
Definition GpuTypes.h:69
Mipmapped
Definition GpuTypes.h:53
Protected
Definition GpuTypes.h:61
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