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

Side by Side Diff: include/gpu/GrContext.h

Issue 608883003: GrResourceCache2 manages scratch texture. (Closed) Base URL: https://skia.googlesource.com/skia.git@surfimpl
Patch Set: remove todo Created 6 years, 2 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
« no previous file with comments | « gm/yuvtorgbeffect.cpp ('k') | include/gpu/GrGpuResource.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2010 Google Inc. 2 * Copyright 2010 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 #ifndef GrContext_DEFINED 8 #ifndef GrContext_DEFINED
9 #define GrContext_DEFINED 9 #define GrContext_DEFINED
10 10
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 * Returns a texture matching the desc. It's contents are unknown. Subsequen t 283 * Returns a texture matching the desc. It's contents are unknown. Subsequen t
284 * requests with the same descriptor are not guaranteed to return the same 284 * requests with the same descriptor are not guaranteed to return the same
285 * texture. The same texture is guaranteed not be returned again until it is 285 * texture. The same texture is guaranteed not be returned again until it is
286 * unlocked. Call must be balanced with an unlockTexture() call. The caller 286 * unlocked. Call must be balanced with an unlockTexture() call. The caller
287 * owns a ref on the returned texture and must balance with a call to unref. 287 * owns a ref on the returned texture and must balance with a call to unref.
288 * 288 *
289 * Textures created by createAndLockTexture() hide the complications of 289 * Textures created by createAndLockTexture() hide the complications of
290 * tiling non-power-of-two textures on APIs that don't support this (e.g. 290 * tiling non-power-of-two textures on APIs that don't support this (e.g.
291 * unextended GLES2). Tiling a NPOT texture created by lockScratchTexture on 291 * unextended GLES2). Tiling a NPOT texture created by lockScratchTexture on
292 * such an API will create gaps in the tiling pattern. This includes clamp 292 * such an API will create gaps in the tiling pattern. This includes clamp
293 * mode. (This may be addressed in a future update.) 293 * mode. (This may be addressed in a future update.)7
294 *
295 * internalFlag is a temporary workaround until changes in the internal
296 * architecture are complete. Use the default value.
294 */ 297 */
295 GrTexture* lockAndRefScratchTexture(const GrTextureDesc&, ScratchTexMatch ma tch); 298 GrTexture* lockAndRefScratchTexture(const GrTextureDesc&, ScratchTexMatch ma tch,
296 299 bool internalFlag = false);
297 /**
298 * When done with an entry, call unlockScratchTexture(entry) on it, which r eturns
299 * it to the cache, where it may be purged. This does not unref the texture .
300 */
301 void unlockScratchTexture(GrTexture* texture);
302 300
303 /** 301 /**
304 * Creates a texture that is outside the cache. Does not count against 302 * Creates a texture that is outside the cache. Does not count against
305 * cache's budget. 303 * cache's budget.
306 */ 304 */
307 GrTexture* createUncachedTexture(const GrTextureDesc& desc, 305 GrTexture* createUncachedTexture(const GrTextureDesc& desc,
308 void* srcData, 306 void* srcData,
309 size_t rowBytes); 307 size_t rowBytes);
310 308
311 /** 309 /**
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 942
945 /////////////////////////////////////////////////////////////////////////// 943 ///////////////////////////////////////////////////////////////////////////
946 // Functions intended for internal use only. 944 // Functions intended for internal use only.
947 GrGpu* getGpu() { return fGpu; } 945 GrGpu* getGpu() { return fGpu; }
948 const GrGpu* getGpu() const { return fGpu; } 946 const GrGpu* getGpu() const { return fGpu; }
949 GrFontCache* getFontCache() { return fFontCache; } 947 GrFontCache* getFontCache() { return fFontCache; }
950 GrLayerCache* getLayerCache() { return fLayerCache.get(); } 948 GrLayerCache* getLayerCache() { return fLayerCache.get(); }
951 GrDrawTarget* getTextTarget(); 949 GrDrawTarget* getTextTarget();
952 const GrIndexBuffer* getQuadIndexBuffer() const; 950 const GrIndexBuffer* getQuadIndexBuffer() const;
953 GrAARectRenderer* getAARectRenderer() { return fAARectRenderer; } 951 GrAARectRenderer* getAARectRenderer() { return fAARectRenderer; }
952 GrResourceCache* getResourceCache() { return fResourceCache; }
954 GrResourceCache2* getResourceCache2() { return fResourceCache2; } 953 GrResourceCache2* getResourceCache2() { return fResourceCache2; }
955 954
956 // Called by tests that draw directly to the context via GrDrawTarget 955 // Called by tests that draw directly to the context via GrDrawTarget
957 void getTestTarget(GrTestTarget*); 956 void getTestTarget(GrTestTarget*);
958 957
959 void addGpuTraceMarker(const GrGpuTraceMarker* marker); 958 void addGpuTraceMarker(const GrGpuTraceMarker* marker);
960 void removeGpuTraceMarker(const GrGpuTraceMarker* marker); 959 void removeGpuTraceMarker(const GrGpuTraceMarker* marker);
961 960
962 /** 961 /**
963 * Stencil buffers add themselves to the cache using addStencilBuffer. findS tencilBuffer is 962 * Stencil buffers add themselves to the cache using addStencilBuffer. findS tencilBuffer is
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 1067
1069 void internalDrawPath(GrDrawTarget* target, bool useAA, const SkPath& path, 1068 void internalDrawPath(GrDrawTarget* target, bool useAA, const SkPath& path,
1070 const GrStrokeInfo& stroke); 1069 const GrStrokeInfo& stroke);
1071 1070
1072 GrTexture* createResizedTexture(const GrTextureDesc& desc, 1071 GrTexture* createResizedTexture(const GrTextureDesc& desc,
1073 const GrCacheID& cacheID, 1072 const GrCacheID& cacheID,
1074 const void* srcData, 1073 const void* srcData,
1075 size_t rowBytes, 1074 size_t rowBytes,
1076 bool filter); 1075 bool filter);
1077 1076
1078 // Needed so GrTexture's returnToCache helper function can call 1077 GrTexture* createNewScratchTexture(const GrTextureDesc& desc);
1079 // addExistingTextureToCache
1080 friend class GrTexture;
1081 friend class GrStencilAndCoverPathRenderer;
1082 friend class GrStencilAndCoverTextContext;
1083
1084 // Add an existing texture to the texture cache. This is intended solely
1085 // for use with textures released from an GrAutoScratchTexture.
1086 void addExistingTextureToCache(GrTexture* texture);
1087 1078
1088 /** 1079 /**
1089 * These functions create premul <-> unpremul effects if it is possible to g enerate a pair 1080 * These functions create premul <-> unpremul effects if it is possible to g enerate a pair
1090 * of effects that make a readToUPM->writeToPM->readToUPM cycle invariant. O therwise, they 1081 * of effects that make a readToUPM->writeToPM->readToUPM cycle invariant. O therwise, they
1091 * return NULL. 1082 * return NULL.
1092 */ 1083 */
1093 const GrFragmentProcessor* createPMToUPMEffect(GrTexture*, bool swapRAndB, c onst SkMatrix&); 1084 const GrFragmentProcessor* createPMToUPMEffect(GrTexture*, bool swapRAndB, c onst SkMatrix&);
1094 const GrFragmentProcessor* createUPMToPMEffect(GrTexture*, bool swapRAndB, c onst SkMatrix&); 1085 const GrFragmentProcessor* createUPMToPMEffect(GrTexture*, bool swapRAndB, c onst SkMatrix&);
1095 1086
1096 /** 1087 /**
1097 * This callback allows the resource cache to callback into the GrContext 1088 * This callback allows the resource cache to callback into the GrContext
1098 * when the cache is still overbudget after a purge. 1089 * when the cache is still overbudget after a purge.
1099 */ 1090 */
1100 static bool OverbudgetCB(void* data); 1091 static bool OverbudgetCB(void* data);
1101 1092
1102 typedef SkRefCnt INHERITED; 1093 typedef SkRefCnt INHERITED;
1103 }; 1094 };
1104 1095
1105 /** 1096 /**
1106 * Gets and locks a scratch texture from a descriptor using either exact or appr oximate criteria. 1097 * This is deprecated. Don't use it.
1107 * Unlocks texture in the destructor.
1108 */ 1098 */
1109 class SK_API GrAutoScratchTexture : public ::SkNoncopyable { 1099 class SK_API GrAutoScratchTexture : public ::SkNoncopyable {
1110 public: 1100 public:
1111 GrAutoScratchTexture() 1101 GrAutoScratchTexture()
1112 : fContext(NULL) 1102 : fContext(NULL)
1113 , fTexture(NULL) { 1103 , fTexture(NULL) {
1114 } 1104 }
1115 1105
1116 GrAutoScratchTexture(GrContext* context, 1106 GrAutoScratchTexture(GrContext* context,
1117 const GrTextureDesc& desc, 1107 const GrTextureDesc& desc,
1118 GrContext::ScratchTexMatch match = GrContext::kApprox_S cratchTexMatch) 1108 GrContext::ScratchTexMatch match = GrContext::kApprox_S cratchTexMatch,
1109 bool internalFlag = false)
1119 : fContext(NULL) 1110 : fContext(NULL)
1120 , fTexture(NULL) { 1111 , fTexture(NULL) {
1121 this->set(context, desc, match); 1112 this->set(context, desc, match, internalFlag);
1122 } 1113 }
1123 1114
1124 ~GrAutoScratchTexture() { 1115 ~GrAutoScratchTexture() {
1125 this->reset(); 1116 this->reset();
1126 } 1117 }
1127 1118
1128 void reset() { 1119 void reset() {
1129 if (fContext && fTexture) { 1120 if (fContext && fTexture) {
1130 fContext->unlockScratchTexture(fTexture);
1131 fTexture->unref(); 1121 fTexture->unref();
1132 fTexture = NULL; 1122 fTexture = NULL;
1133 } 1123 }
1134 } 1124 }
1135 1125
1136 /* 1126 GrTexture* detach() {
1137 * When detaching a texture we do not unlock it in the texture cache but 1127 GrTexture* texture = fTexture;
1138 * we do set the returnToCache flag. In this way the texture remains 1128 fTexture = NULL;
1139 * "locked" in the texture cache until it is freed and recycled in 1129 return texture;
1140 * GrTexture::internal_dispose. In reality, the texture has been removed 1130 }
1141 * from the cache (because this is in AutoScratchTexture) and by not
1142 * calling unlockScratchTexture we simply don't re-add it. It will be
1143 * reattached in GrTexture::internal_dispose.
1144 *
1145 * Note that the caller is assumed to accept and manage the ref to the
1146 * returned texture.
1147 */
1148 GrTexture* detach();
1149 1131
1150 GrTexture* set(GrContext* context, 1132 GrTexture* set(GrContext* context,
1151 const GrTextureDesc& desc, 1133 const GrTextureDesc& desc,
1152 GrContext::ScratchTexMatch match = GrContext::kApprox_Scratch TexMatch) { 1134 GrContext::ScratchTexMatch match = GrContext::kApprox_Scratch TexMatch,
1135 bool internalFlag = 0) {
1153 this->reset(); 1136 this->reset();
1154 1137
1155 fContext = context; 1138 fContext = context;
1156 if (fContext) { 1139 if (fContext) {
1157 fTexture = fContext->lockAndRefScratchTexture(desc, match); 1140 fTexture = fContext->lockAndRefScratchTexture(desc, match, internalF lag);
1158 if (NULL == fTexture) { 1141 if (NULL == fTexture) {
1159 fContext = NULL; 1142 fContext = NULL;
1160 } 1143 }
1161 return fTexture; 1144 return fTexture;
1162 } else { 1145 } else {
1163 return NULL; 1146 return NULL;
1164 } 1147 }
1165 } 1148 }
1166 1149
1167 GrTexture* texture() { return fTexture; } 1150 GrTexture* texture() { return fTexture; }
1168 1151
1169 private: 1152 private:
1170 GrContext* fContext; 1153 GrContext* fContext;
1171 GrTexture* fTexture; 1154 GrTexture* fTexture;
1172 }; 1155 };
1173 1156
1174 #endif 1157 #endif
OLDNEW
« no previous file with comments | « gm/yuvtorgbeffect.cpp ('k') | include/gpu/GrGpuResource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698