OLD | NEW |
---|---|
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 Loading... | |
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 |
bsalomon
2014/10/07 04:07:55
will remove the stray 7 and fix up sentence in sub
| |
294 * | |
295 * internalFlags is a temporary workaround until changes in the internal | |
296 * architectural changes 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 uint32_t internalFlags = 0); |
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 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1068 | 1066 |
1069 void internalDrawPath(GrDrawTarget* target, bool useAA, const SkPath& path, | 1067 void internalDrawPath(GrDrawTarget* target, bool useAA, const SkPath& path, |
1070 const GrStrokeInfo& stroke); | 1068 const GrStrokeInfo& stroke); |
1071 | 1069 |
1072 GrTexture* createResizedTexture(const GrTextureDesc& desc, | 1070 GrTexture* createResizedTexture(const GrTextureDesc& desc, |
1073 const GrCacheID& cacheID, | 1071 const GrCacheID& cacheID, |
1074 const void* srcData, | 1072 const void* srcData, |
1075 size_t rowBytes, | 1073 size_t rowBytes, |
1076 bool filter); | 1074 bool filter); |
1077 | 1075 |
1078 // Needed so GrTexture's returnToCache helper function can call | 1076 bool 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 | 1077 |
1088 /** | 1078 /** |
1089 * These functions create premul <-> unpremul effects if it is possible to g enerate a pair | 1079 * 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 | 1080 * of effects that make a readToUPM->writeToPM->readToUPM cycle invariant. O therwise, they |
1091 * return NULL. | 1081 * return NULL. |
1092 */ | 1082 */ |
1093 const GrFragmentProcessor* createPMToUPMEffect(GrTexture*, bool swapRAndB, c onst SkMatrix&); | 1083 const GrFragmentProcessor* createPMToUPMEffect(GrTexture*, bool swapRAndB, c onst SkMatrix&); |
1094 const GrFragmentProcessor* createUPMToPMEffect(GrTexture*, bool swapRAndB, c onst SkMatrix&); | 1084 const GrFragmentProcessor* createUPMToPMEffect(GrTexture*, bool swapRAndB, c onst SkMatrix&); |
1095 | 1085 |
1096 /** | 1086 /** |
1097 * This callback allows the resource cache to callback into the GrContext | 1087 * This callback allows the resource cache to callback into the GrContext |
1098 * when the cache is still overbudget after a purge. | 1088 * when the cache is still overbudget after a purge. |
1099 */ | 1089 */ |
1100 static bool OverbudgetCB(void* data); | 1090 static bool OverbudgetCB(void* data); |
1101 | 1091 |
1102 typedef SkRefCnt INHERITED; | 1092 typedef SkRefCnt INHERITED; |
1103 }; | 1093 }; |
1104 | 1094 |
1105 /** | 1095 /** |
1106 * Gets and locks a scratch texture from a descriptor using either exact or appr oximate criteria. | 1096 * This is deprecated. Don't use it. |
1107 * Unlocks texture in the destructor. | |
1108 */ | 1097 */ |
1109 class SK_API GrAutoScratchTexture : public ::SkNoncopyable { | 1098 class SK_API GrAutoScratchTexture : public ::SkNoncopyable { |
1110 public: | 1099 public: |
1111 GrAutoScratchTexture() | 1100 GrAutoScratchTexture() |
1112 : fContext(NULL) | 1101 : fContext(NULL) |
1113 , fTexture(NULL) { | 1102 , fTexture(NULL) { |
1114 } | 1103 } |
1115 | 1104 |
1116 GrAutoScratchTexture(GrContext* context, | 1105 GrAutoScratchTexture(GrContext* context, |
1117 const GrTextureDesc& desc, | 1106 const GrTextureDesc& desc, |
1118 GrContext::ScratchTexMatch match = GrContext::kApprox_S cratchTexMatch) | 1107 GrContext::ScratchTexMatch match = GrContext::kApprox_S cratchTexMatch, |
1108 uint32_t internalFlags = 0) | |
1119 : fContext(NULL) | 1109 : fContext(NULL) |
1120 , fTexture(NULL) { | 1110 , fTexture(NULL) { |
1121 this->set(context, desc, match); | 1111 this->set(context, desc, match, internalFlags); |
1122 } | 1112 } |
1123 | 1113 |
1124 ~GrAutoScratchTexture() { | 1114 ~GrAutoScratchTexture() { |
1125 this->reset(); | 1115 this->reset(); |
1126 } | 1116 } |
1127 | 1117 |
1128 void reset() { | 1118 void reset() { |
1129 if (fContext && fTexture) { | 1119 if (fContext && fTexture) { |
1130 fContext->unlockScratchTexture(fTexture); | |
1131 fTexture->unref(); | 1120 fTexture->unref(); |
1132 fTexture = NULL; | 1121 fTexture = NULL; |
1133 } | 1122 } |
1134 } | 1123 } |
1135 | 1124 |
1136 /* | 1125 GrTexture* detach() { |
1137 * When detaching a texture we do not unlock it in the texture cache but | 1126 GrTexture* texture = fTexture; |
1138 * we do set the returnToCache flag. In this way the texture remains | 1127 fTexture = NULL; |
1139 * "locked" in the texture cache until it is freed and recycled in | 1128 return texture; |
1140 * GrTexture::internal_dispose. In reality, the texture has been removed | 1129 } |
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 | 1130 |
1150 GrTexture* set(GrContext* context, | 1131 GrTexture* set(GrContext* context, |
1151 const GrTextureDesc& desc, | 1132 const GrTextureDesc& desc, |
1152 GrContext::ScratchTexMatch match = GrContext::kApprox_Scratch TexMatch) { | 1133 GrContext::ScratchTexMatch match = GrContext::kApprox_Scratch TexMatch, |
1134 uint32_t internalFlags = 0) { | |
1153 this->reset(); | 1135 this->reset(); |
1154 | 1136 |
1155 fContext = context; | 1137 fContext = context; |
1156 if (fContext) { | 1138 if (fContext) { |
1157 fTexture = fContext->lockAndRefScratchTexture(desc, match); | 1139 fTexture = fContext->lockAndRefScratchTexture(desc, match, internalF lags); |
1158 if (NULL == fTexture) { | 1140 if (NULL == fTexture) { |
1159 fContext = NULL; | 1141 fContext = NULL; |
1160 } | 1142 } |
1161 return fTexture; | 1143 return fTexture; |
1162 } else { | 1144 } else { |
1163 return NULL; | 1145 return NULL; |
1164 } | 1146 } |
1165 } | 1147 } |
1166 | 1148 |
1167 GrTexture* texture() { return fTexture; } | 1149 GrTexture* texture() { return fTexture; } |
1168 | 1150 |
1169 private: | 1151 private: |
1170 GrContext* fContext; | 1152 GrContext* fContext; |
1171 GrTexture* fTexture; | 1153 GrTexture* fTexture; |
1172 }; | 1154 }; |
1173 | 1155 |
1174 #endif | 1156 #endif |
OLD | NEW |