1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "GrTextureProxy.h"
#include "GrTextureProxyPriv.h"
#include "GrContext.h"
#include "GrContextPriv.h"
#include "GrDeferredProxyUploader.h"
#include "GrProxyProvider.h"
#include "GrTexturePriv.h"
// Deferred version - with data
GrTextureProxy::GrTextureProxy(const GrSurfaceDesc& srcDesc, GrMipMapped mipMapped,
SkBackingFit fit, SkBudgeted budgeted, const void* srcData,
size_t /*rowBytes*/, uint32_t flags)
: INHERITED(srcDesc, kTopLeft_GrSurfaceOrigin, fit, budgeted, flags)
, fMipMapped(mipMapped)
, fProxyProvider(nullptr)
, fDeferredUploader(nullptr) {
SkASSERT(!srcData); // currently handled in Make()
}
// Deferred version - no data
GrTextureProxy::GrTextureProxy(const GrSurfaceDesc& srcDesc, GrSurfaceOrigin origin,
GrMipMapped mipMapped, SkBackingFit fit, SkBudgeted budgeted,
uint32_t flags)
: INHERITED(srcDesc, origin, fit, budgeted, flags)
, fMipMapped(mipMapped)
, fProxyProvider(nullptr)
, fDeferredUploader(nullptr) {}
// Lazy-callback version
GrTextureProxy::GrTextureProxy(LazyInstantiateCallback&& callback, LazyInstantiationType lazyType,
const GrSurfaceDesc& desc, GrSurfaceOrigin origin,
GrMipMapped mipMapped, SkBackingFit fit, SkBudgeted budgeted,
uint32_t flags)
: INHERITED(std::move(callback), lazyType, desc, origin, fit, budgeted, flags)
, fMipMapped(mipMapped)
, fProxyProvider(nullptr)
, fDeferredUploader(nullptr) {}
// Wrapped version
GrTextureProxy::GrTextureProxy(sk_sp<GrSurface> surf, GrSurfaceOrigin origin)
: INHERITED(std::move(surf), origin, SkBackingFit::kExact)
, fMipMapped(fTarget->asTexture()->texturePriv().mipMapped())
, fProxyProvider(nullptr)
, fDeferredUploader(nullptr) {
if (fTarget->getUniqueKey().isValid()) {
fProxyProvider = fTarget->asTexture()->getContext()->contextPriv().proxyProvider();
fProxyProvider->adoptUniqueKeyFromSurface(this, fTarget);
}
}
GrTextureProxy::~GrTextureProxy() {
// Due to the order of cleanup the GrSurface this proxy may have wrapped may have gone away
// at this point. Zero out the pointer so the cache invalidation code doesn't try to use it.
fTarget = nullptr;
if (fUniqueKey.isValid()) {
fProxyProvider->processInvalidProxyUniqueKey(fUniqueKey, this, false);
} else {
SkASSERT(!fProxyProvider);
}
}
bool GrTextureProxy::instantiate(GrResourceProvider* resourceProvider) {
if (LazyState::kNot != this->lazyInstantiationState()) {
return false;
}
if (!this->instantiateImpl(resourceProvider, 1, /* needsStencil = */ false,
kNone_GrSurfaceFlags, fMipMapped,
fUniqueKey.isValid() ? &fUniqueKey : nullptr)) {
return false;
}
SkASSERT(!fTarget->asRenderTarget());
SkASSERT(fTarget->asTexture());
return true;
}
sk_sp<GrSurface> GrTextureProxy::createSurface(GrResourceProvider* resourceProvider) const {
sk_sp<GrSurface> surface= this->createSurfaceImpl(resourceProvider, 1,
/* needsStencil = */ false,
kNone_GrSurfaceFlags,
fMipMapped);
if (!surface) {
return nullptr;
}
SkASSERT(!surface->asRenderTarget());
SkASSERT(surface->asTexture());
return surface;
}
void GrTextureProxyPriv::setDeferredUploader(std::unique_ptr<GrDeferredProxyUploader> uploader) {
SkASSERT(!fTextureProxy->fDeferredUploader);
fTextureProxy->fDeferredUploader = std::move(uploader);
}
void GrTextureProxyPriv::scheduleUpload(GrOpFlushState* flushState) {
// The texture proxy's contents may already have been uploaded or instantiation may have failed
if (fTextureProxy->fDeferredUploader && fTextureProxy->fTarget) {
fTextureProxy->fDeferredUploader->scheduleUpload(flushState, fTextureProxy);
}
}
void GrTextureProxyPriv::resetDeferredUploader() {
SkASSERT(fTextureProxy->fDeferredUploader);
fTextureProxy->fDeferredUploader.reset();
}
// This method parallels the highest_filter_mode functions in GrGLTexture & GrVkTexture.
GrSamplerState::Filter GrTextureProxy::highestFilterMode() const {
if (fTarget) {
return fTarget->asTexture()->texturePriv().highestFilterMode();
}
// In OpenGL, GR_GL_TEXTURE_RECTANGLE and GR_GL_TEXTURE_EXTERNAL (which have a highest filter
// mode of bilerp) can only be created via wrapping.
return GrSamplerState::Filter::kMipMap;
}
GrMipMapped GrTextureProxy::mipMapped() const {
if (this->priv().isInstantiated()) {
return this->priv().peekTexture()->texturePriv().mipMapped();
}
return fMipMapped;
}
size_t GrTextureProxy::onUninstantiatedGpuMemorySize() const {
return GrSurface::ComputeSize(this->config(), this->width(), this->height(), 1,
this->texPriv().proxyMipMapped(), !this->priv().isExact());
}
void GrTextureProxy::setUniqueKey(GrProxyProvider* proxyProvider, const GrUniqueKey& key) {
SkASSERT(key.isValid());
SkASSERT(!fUniqueKey.isValid()); // proxies can only ever get one uniqueKey
if (fTarget) {
if (!fTarget->getUniqueKey().isValid()) {
fTarget->resourcePriv().setUniqueKey(key);
}
SkASSERT(fTarget->getUniqueKey() == key);
}
fUniqueKey = key;
fProxyProvider = proxyProvider;
}
void GrTextureProxy::clearUniqueKey() {
fUniqueKey.reset();
fProxyProvider = nullptr;
}
#ifdef SK_DEBUG
void GrTextureProxy::validateLazySurface(const GrSurface* surface) {
SkASSERT(!surface->asRenderTarget());
// Anything that is checked here should be duplicated in GrTextureRenderTargetProxy's version
SkASSERT(surface->asTexture());
SkASSERT(GrMipMapped::kNo == this->texPriv().proxyMipMapped() ||
GrMipMapped::kYes == surface->asTexture()->texturePriv().mipMapped());
}
#endif
|