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
|
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "GrGLTexture.h"
#include "GrGLGpu.h"
#include "SkTraceMemoryDump.h"
#define GPUGL static_cast<GrGLGpu*>(this->getGpu())
#define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X)
inline static GrSLType sampler_type(const GrGLTexture::IDDesc& idDesc, const GrGLGpu* gpu) {
if (idDesc.fInfo.fTarget == GR_GL_TEXTURE_EXTERNAL) {
SkASSERT(gpu->glCaps().glslCaps()->externalTextureSupport());
return kSamplerExternal_GrSLType;
} else if (idDesc.fInfo.fTarget == GR_GL_TEXTURE_RECTANGLE) {
SkASSERT(gpu->glCaps().rectangleTextureSupport());
return kSampler2DRect_GrSLType;
} else {
SkASSERT(idDesc.fInfo.fTarget == GR_GL_TEXTURE_2D);
return kSampler2D_GrSLType;
}
}
// Because this class is virtually derived from GrSurface we must explicitly call its constructor.
GrGLTexture::GrGLTexture(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc)
: GrSurface(gpu, idDesc.fLifeCycle, desc)
, INHERITED(gpu, idDesc.fLifeCycle, desc, sampler_type(idDesc, gpu), false) {
this->init(desc, idDesc);
this->registerWithCache();
}
GrGLTexture::GrGLTexture(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc,
bool wasMipMapDataProvided)
: GrSurface(gpu, idDesc.fLifeCycle, desc)
, INHERITED(gpu, idDesc.fLifeCycle, desc, sampler_type(idDesc, gpu), wasMipMapDataProvided) {
this->init(desc, idDesc);
this->registerWithCache();
}
GrGLTexture::GrGLTexture(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc, Derived)
: GrSurface(gpu, idDesc.fLifeCycle, desc)
, INHERITED(gpu, idDesc.fLifeCycle, desc, sampler_type(idDesc, gpu), false) {
this->init(desc, idDesc);
}
void GrGLTexture::init(const GrSurfaceDesc& desc, const IDDesc& idDesc) {
SkASSERT(0 != idDesc.fInfo.fID);
fTexParams.invalidate();
fTexParamsTimestamp = GrGpu::kExpiredTimestamp;
fInfo = idDesc.fInfo;
fTextureIDLifecycle = idDesc.fLifeCycle;
}
void GrGLTexture::onRelease() {
if (fInfo.fID) {
if (GrGpuResource::kBorrowed_LifeCycle != fTextureIDLifecycle) {
if (this->desc().fTextureStorageAllocator.fDeallocateTextureStorage) {
this->desc().fTextureStorageAllocator.fDeallocateTextureStorage(
this->desc().fTextureStorageAllocator.fCtx,
reinterpret_cast<GrBackendObject>(&fInfo));
} else {
GL_CALL(DeleteTextures(1, &fInfo.fID));
}
}
fInfo.fID = 0;
}
INHERITED::onRelease();
}
void GrGLTexture::onAbandon() {
fInfo.fTarget = 0;
fInfo.fID = 0;
INHERITED::onAbandon();
}
GrBackendObject GrGLTexture::getTextureHandle() const {
#ifdef SK_IGNORE_GL_TEXTURE_TARGET
return static_cast<GrBackendObject>(this->textureID());
#else
return reinterpret_cast<GrBackendObject>(&fInfo);
#endif
}
void GrGLTexture::setMemoryBacking(SkTraceMemoryDump* traceMemoryDump,
const SkString& dumpName) const {
SkString texture_id;
texture_id.appendU32(this->textureID());
traceMemoryDump->setMemoryBacking(dumpName.c_str(), "gl_texture",
texture_id.c_str());
}
|