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

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: wrap line and delete unneeded friends 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
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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
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.)
294 */ 294 */
295 GrTexture* lockAndRefScratchTexture(const GrTextureDesc&, ScratchTexMatch ma tch); 295 GrTexture* lockAndRefScratchTexture(const GrTextureDesc&, ScratchTexMatch ma tch);
296 296
297 /** 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
303 /**
304 * Creates a texture that is outside the cache. Does not count against 298 * Creates a texture that is outside the cache. Does not count against
305 * cache's budget. 299 * cache's budget.
306 */ 300 */
307 GrTexture* createUncachedTexture(const GrTextureDesc& desc, 301 GrTexture* createUncachedTexture(const GrTextureDesc& desc,
308 void* srcData, 302 void* srcData,
309 size_t rowBytes); 303 size_t rowBytes);
310 304
311 /** 305 /**
312 * Returns true if the specified use of an indexed texture is supported. 306 * Returns true if the specified use of an indexed texture is supported.
313 * Support may depend upon whether the texture params indicate that the 307 * Support may depend upon whether the texture params indicate that the
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 1038
1045 void internalDrawPath(GrDrawTarget* target, bool useAA, const SkPath& path, 1039 void internalDrawPath(GrDrawTarget* target, bool useAA, const SkPath& path,
1046 const GrStrokeInfo& stroke); 1040 const GrStrokeInfo& stroke);
1047 1041
1048 GrTexture* createResizedTexture(const GrTextureDesc& desc, 1042 GrTexture* createResizedTexture(const GrTextureDesc& desc,
1049 const GrCacheID& cacheID, 1043 const GrCacheID& cacheID,
1050 const void* srcData, 1044 const void* srcData,
1051 size_t rowBytes, 1045 size_t rowBytes,
1052 bool filter); 1046 bool filter);
1053 1047
1054 // Needed so GrTexture's returnToCache helper function can call 1048 bool addNewScratchTexture(const GrTextureDesc& desc);
1055 // addExistingTextureToCache
1056 friend class GrTexture;
1057 friend class GrStencilAndCoverPathRenderer;
1058 friend class GrStencilAndCoverTextContext;
1059
1060 // Add an existing texture to the texture cache. This is intended solely
1061 // for use with textures released from an GrAutoScratchTexture.
1062 void addExistingTextureToCache(GrTexture* texture);
1063 1049
1064 /** 1050 /**
1065 * These functions create premul <-> unpremul effects if it is possible to g enerate a pair 1051 * These functions create premul <-> unpremul effects if it is possible to g enerate a pair
1066 * of effects that make a readToUPM->writeToPM->readToUPM cycle invariant. O therwise, they 1052 * of effects that make a readToUPM->writeToPM->readToUPM cycle invariant. O therwise, they
1067 * return NULL. 1053 * return NULL.
1068 */ 1054 */
1069 const GrFragmentProcessor* createPMToUPMEffect(GrTexture*, bool swapRAndB, c onst SkMatrix&); 1055 const GrFragmentProcessor* createPMToUPMEffect(GrTexture*, bool swapRAndB, c onst SkMatrix&);
1070 const GrFragmentProcessor* createUPMToPMEffect(GrTexture*, bool swapRAndB, c onst SkMatrix&); 1056 const GrFragmentProcessor* createUPMToPMEffect(GrTexture*, bool swapRAndB, c onst SkMatrix&);
1071 1057
1072 /** 1058 /**
1073 * This callback allows the resource cache to callback into the GrContext 1059 * This callback allows the resource cache to callback into the GrContext
1074 * when the cache is still overbudget after a purge. 1060 * when the cache is still overbudget after a purge.
1075 */ 1061 */
1076 static bool OverbudgetCB(void* data); 1062 static bool OverbudgetCB(void* data);
1077 1063
1078 typedef SkRefCnt INHERITED; 1064 typedef SkRefCnt INHERITED;
1079 }; 1065 };
1080 1066
1081 /** 1067 /**
1082 * Gets and locks a scratch texture from a descriptor using either exact or appr oximate criteria. 1068 * This is deprecated. Don't use it.
1083 * Unlocks texture in the destructor.
1084 */ 1069 */
1085 class GrAutoScratchTexture : public ::SkNoncopyable { 1070 class GrAutoScratchTexture : public ::SkNoncopyable {
1086 public: 1071 public:
1087 GrAutoScratchTexture() 1072 GrAutoScratchTexture()
1088 : fContext(NULL) 1073 : fContext(NULL)
1089 , fTexture(NULL) { 1074 , fTexture(NULL) {
1090 } 1075 }
1091 1076
1092 GrAutoScratchTexture(GrContext* context, 1077 GrAutoScratchTexture(GrContext* context,
1093 const GrTextureDesc& desc, 1078 const GrTextureDesc& desc,
1094 GrContext::ScratchTexMatch match = GrContext::kApprox_S cratchTexMatch) 1079 GrContext::ScratchTexMatch match = GrContext::kApprox_S cratchTexMatch)
1095 : fContext(NULL) 1080 : fContext(NULL)
1096 , fTexture(NULL) { 1081 , fTexture(NULL) {
1097 this->set(context, desc, match); 1082 this->set(context, desc, match);
1098 } 1083 }
1099 1084
1100 ~GrAutoScratchTexture() { 1085 ~GrAutoScratchTexture() {
1101 this->reset(); 1086 this->reset();
1102 } 1087 }
1103 1088
1104 void reset() { 1089 void reset() {
1105 if (fContext && fTexture) { 1090 if (fContext && fTexture) {
1106 fContext->unlockScratchTexture(fTexture);
1107 fTexture->unref(); 1091 fTexture->unref();
1108 fTexture = NULL; 1092 fTexture = NULL;
1109 } 1093 }
1110 } 1094 }
1111 1095
1112 /* 1096 GrTexture* detach() {
1113 * When detaching a texture we do not unlock it in the texture cache but 1097 GrTexture* texture = fTexture;
1114 * we do set the returnToCache flag. In this way the texture remains 1098 fTexture = NULL;
1115 * "locked" in the texture cache until it is freed and recycled in 1099 return texture;
1116 * GrTexture::internal_dispose. In reality, the texture has been removed 1100 }
1117 * from the cache (because this is in AutoScratchTexture) and by not
1118 * calling unlockScratchTexture we simply don't re-add it. It will be
1119 * reattached in GrTexture::internal_dispose.
1120 *
1121 * Note that the caller is assumed to accept and manage the ref to the
1122 * returned texture.
1123 */
1124 GrTexture* detach();
1125 1101
1126 GrTexture* set(GrContext* context, 1102 GrTexture* set(GrContext* context,
1127 const GrTextureDesc& desc, 1103 const GrTextureDesc& desc,
1128 GrContext::ScratchTexMatch match = GrContext::kApprox_Scratch TexMatch) { 1104 GrContext::ScratchTexMatch match = GrContext::kApprox_Scratch TexMatch) {
1129 this->reset(); 1105 this->reset();
1130 1106
1131 fContext = context; 1107 fContext = context;
1132 if (fContext) { 1108 if (fContext) {
1133 fTexture = fContext->lockAndRefScratchTexture(desc, match); 1109 fTexture = fContext->lockAndRefScratchTexture(desc, match);
1134 if (NULL == fTexture) { 1110 if (NULL == fTexture) {
1135 fContext = NULL; 1111 fContext = NULL;
1136 } 1112 }
1137 return fTexture; 1113 return fTexture;
1138 } else { 1114 } else {
1139 return NULL; 1115 return NULL;
1140 } 1116 }
1141 } 1117 }
1142 1118
1143 GrTexture* texture() { return fTexture; } 1119 GrTexture* texture() { return fTexture; }
1144 1120
1145 private: 1121 private:
1146 GrContext* fContext; 1122 GrContext* fContext;
1147 GrTexture* fTexture; 1123 GrTexture* fTexture;
1148 }; 1124 };
1149 1125
1150 #endif 1126 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698