Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(473)

Side by Side Diff: src/gpu/gl/GrGLTexture.cpp

Issue 1862043002: Refactor to separate backend object lifecycle and GpuResource budget decision (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrGLTexture.h" 8 #include "GrGLTexture.h"
9 #include "GrGLGpu.h" 9 #include "GrGLGpu.h"
10 #include "SkTraceMemoryDump.h" 10 #include "SkTraceMemoryDump.h"
11 11
12 #define GPUGL static_cast<GrGLGpu*>(this->getGpu()) 12 #define GPUGL static_cast<GrGLGpu*>(this->getGpu())
13 #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X) 13 #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X)
14 14
15 inline static GrSLType sampler_type(const GrGLTexture::IDDesc& idDesc, const GrG LGpu* gpu) { 15 inline static GrSLType sampler_type(const GrGLTexture::IDDesc& idDesc, const GrG LGpu* gpu) {
16 if (idDesc.fInfo.fTarget == GR_GL_TEXTURE_EXTERNAL) { 16 if (idDesc.fInfo.fTarget == GR_GL_TEXTURE_EXTERNAL) {
17 SkASSERT(gpu->glCaps().glslCaps()->externalTextureSupport()); 17 SkASSERT(gpu->glCaps().glslCaps()->externalTextureSupport());
18 return kSamplerExternal_GrSLType; 18 return kSamplerExternal_GrSLType;
19 } else if (idDesc.fInfo.fTarget == GR_GL_TEXTURE_RECTANGLE) { 19 } else if (idDesc.fInfo.fTarget == GR_GL_TEXTURE_RECTANGLE) {
20 SkASSERT(gpu->glCaps().rectangleTextureSupport()); 20 SkASSERT(gpu->glCaps().rectangleTextureSupport());
21 return kSampler2DRect_GrSLType; 21 return kSampler2DRect_GrSLType;
22 } else { 22 } else {
23 SkASSERT(idDesc.fInfo.fTarget == GR_GL_TEXTURE_2D); 23 SkASSERT(idDesc.fInfo.fTarget == GR_GL_TEXTURE_2D);
24 return kSampler2D_GrSLType; 24 return kSampler2D_GrSLType;
25 } 25 }
26 } 26 }
27 27
28 // Because this class is virtually derived from GrSurface we must explicitly cal l its constructor. 28 // Because this class is virtually derived from GrSurface we must explicitly cal l its constructor.
29 GrGLTexture::GrGLTexture(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc) 29 GrGLTexture::GrGLTexture(GrGLGpu* gpu, SkBudgeted budgeted, const GrSurfaceDesc& desc,
30 : GrSurface(gpu, idDesc.fLifeCycle, desc) 30 const IDDesc& idDesc)
31 , INHERITED(gpu, idDesc.fLifeCycle, desc, sampler_type(idDesc, gpu), false) { 31 : GrSurface(gpu, desc)
32 , INHERITED(gpu, desc, sampler_type(idDesc, gpu), false) {
32 this->init(desc, idDesc); 33 this->init(desc, idDesc);
33 this->registerWithCache(); 34 this->registerWithCache(budgeted);
34 } 35 }
35 36
36 GrGLTexture::GrGLTexture(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc, 37 GrGLTexture::GrGLTexture(GrGLGpu* gpu, SkBudgeted budgeted, const GrSurfaceDesc& desc,
38 const IDDesc& idDesc,
37 bool wasMipMapDataProvided) 39 bool wasMipMapDataProvided)
38 : GrSurface(gpu, idDesc.fLifeCycle, desc) 40 : GrSurface(gpu, desc)
39 , INHERITED(gpu, idDesc.fLifeCycle, desc, sampler_type(idDesc, gpu), wasMipM apDataProvided) { 41 , INHERITED(gpu, desc, sampler_type(idDesc, gpu), wasMipMapDataProvided) {
40 this->init(desc, idDesc); 42 this->init(desc, idDesc);
41 this->registerWithCache(); 43 this->registerWithCache(budgeted);
42 } 44 }
43 45
44 GrGLTexture::GrGLTexture(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc, Derived) 46 GrGLTexture::GrGLTexture(GrGLGpu* gpu, Wrapped, const GrSurfaceDesc& desc, const IDDesc& idDesc)
45 : GrSurface(gpu, idDesc.fLifeCycle, desc) 47 : GrSurface(gpu, desc)
46 , INHERITED(gpu, idDesc.fLifeCycle, desc, sampler_type(idDesc, gpu), false) { 48 , INHERITED(gpu, desc, sampler_type(idDesc, gpu), false) {
49 this->init(desc, idDesc);
50 this->registerWithCacheWrapped();
51 }
52
53 GrGLTexture::GrGLTexture(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc)
54 : GrSurface(gpu, desc)
55 , INHERITED(gpu, desc, sampler_type(idDesc, gpu), false) {
47 this->init(desc, idDesc); 56 this->init(desc, idDesc);
48 } 57 }
49 58
50 void GrGLTexture::init(const GrSurfaceDesc& desc, const IDDesc& idDesc) { 59 void GrGLTexture::init(const GrSurfaceDesc& desc, const IDDesc& idDesc) {
51 SkASSERT(0 != idDesc.fInfo.fID); 60 SkASSERT(0 != idDesc.fInfo.fID);
52 fTexParams.invalidate(); 61 fTexParams.invalidate();
53 fTexParamsTimestamp = GrGpu::kExpiredTimestamp; 62 fTexParamsTimestamp = GrGpu::kExpiredTimestamp;
54 fInfo = idDesc.fInfo; 63 fInfo = idDesc.fInfo;
55 fTextureIDLifecycle = idDesc.fLifeCycle; 64 fTextureIDLifecycle = idDesc.fLifeCycle;
56 } 65 }
57 66
58 void GrGLTexture::onRelease() { 67 void GrGLTexture::onRelease() {
59 if (fInfo.fID) { 68 if (fInfo.fID) {
60 if (GrGpuResource::kBorrowed_LifeCycle != fTextureIDLifecycle) { 69 if (GrBackendObjectLifeCycle::kBorrowed != fTextureIDLifecycle) {
61 if (this->desc().fTextureStorageAllocator.fDeallocateTextureStorage) { 70 if (this->desc().fTextureStorageAllocator.fDeallocateTextureStorage) {
62 this->desc().fTextureStorageAllocator.fDeallocateTextureStorage( 71 this->desc().fTextureStorageAllocator.fDeallocateTextureStorage(
63 this->desc().fTextureStorageAllocator.fCtx, 72 this->desc().fTextureStorageAllocator.fCtx,
64 reinterpret_cast<GrBackendObject>(&fInfo)); 73 reinterpret_cast<GrBackendObject>(&fInfo));
65 } else { 74 } else {
66 GL_CALL(DeleteTextures(1, &fInfo.fID)); 75 GL_CALL(DeleteTextures(1, &fInfo.fID));
67 } 76 }
68 } 77 }
69 fInfo.fID = 0; 78 fInfo.fID = 0;
70 } 79 }
(...skipping 14 matching lines...) Expand all
85 #endif 94 #endif
86 } 95 }
87 96
88 void GrGLTexture::setMemoryBacking(SkTraceMemoryDump* traceMemoryDump, 97 void GrGLTexture::setMemoryBacking(SkTraceMemoryDump* traceMemoryDump,
89 const SkString& dumpName) const { 98 const SkString& dumpName) const {
90 SkString texture_id; 99 SkString texture_id;
91 texture_id.appendU32(this->textureID()); 100 texture_id.appendU32(this->textureID());
92 traceMemoryDump->setMemoryBacking(dumpName.c_str(), "gl_texture", 101 traceMemoryDump->setMemoryBacking(dumpName.c_str(), "gl_texture",
93 texture_id.c_str()); 102 texture_id.c_str());
94 } 103 }
104
105 GrGLTexture* GrGLTexture::CreateWrapped(GrGLGpu* gpu, const GrSurfaceDesc& desc,
106 const IDDesc& idDesc) {
107 return new GrGLTexture(gpu, kWrapped, desc, idDesc);
108 }
109
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698