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

Side by Side Diff: src/core/SkImageCacherator.cpp

Issue 1411353002: Revert recent CLs around GrTextureMaker/GrTextureParamsAdjuster (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 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 | « src/core/SkImageCacherator.h ('k') | src/gpu/GrGpu.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 2015 Google Inc. 2 * Copyright 2015 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 "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkBitmapCache.h" 9 #include "SkBitmapCache.h"
10 #include "SkImage_Base.h" 10 #include "SkImage_Base.h"
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 bool onGetYUVSizes(SkISize sizes[3]) override { 197 bool onGetYUVSizes(SkISize sizes[3]) override {
198 return fGen->getYUV8Planes(sizes, nullptr, nullptr, nullptr); 198 return fGen->getYUV8Planes(sizes, nullptr, nullptr, nullptr);
199 } 199 }
200 bool onGetYUVPlanes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], 200 bool onGetYUVPlanes(SkISize sizes[3], void* planes[3], size_t rowBytes[3],
201 SkYUVColorSpace* space) override { 201 SkYUVColorSpace* space) override {
202 return fGen->getYUV8Planes(sizes, planes, rowBytes, space); 202 return fGen->getYUV8Planes(sizes, planes, rowBytes, space);
203 } 203 }
204 }; 204 };
205 205
206 static GrTexture* set_key_and_return(GrTexture* tex, const GrUniqueKey& key) { 206 static GrTexture* set_key_and_return(GrTexture* tex, const GrUniqueKey& key) {
207 if (key.isValid()) { 207 tex->resourcePriv().setUniqueKey(key);
208 tex->resourcePriv().setUniqueKey(key);
209 }
210 return tex; 208 return tex;
211 } 209 }
212 210
213 /* 211 /*
214 * We have a 5 ways to try to return a texture (in sorted order) 212 * We have a 5 ways to try to return a texture (in sorted order)
215 * 213 *
216 * 1. Check the cache for a pre-existing one 214 * 1. Check the cache for a pre-existing one
217 * 2. Ask the generator to natively create one 215 * 2. Ask the generator to natively create one
218 * 3. Ask the generator to return a compressed form that the GPU might support 216 * 3. Ask the generator to return a compressed form that the GPU might support
219 * 4. Ask the generator to return YUV planes, which the GPU can convert 217 * 4. Ask the generator to return YUV planes, which the GPU can convert
220 * 5. Ask the generator to return RGB(A) data, which the GPU can convert 218 * 5. Ask the generator to return RGB(A) data, which the GPU can convert
221 */ 219 */
222 GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& key , 220 GrTexture* SkImageCacherator::lockUnstretchedTexture(GrContext* ctx, const SkIma ge* client) {
223 const SkImage* client) { 221 // textures (at least the texture-key) only support 16bit dimensions, so abo rt early
224 // 1. Check the cache for a pre-existing one 222 // if we're too big.
225 if (key.isValid()) { 223 if (fInfo.width() > 0xFFFF || fInfo.height() > 0xFFFF) {
226 if (GrTexture* tex = ctx->textureProvider()->findAndRefTextureByUniqueKe y(key)) { 224 return nullptr;
227 return tex;
228 }
229 } 225 }
230 226
231 // 2. Ask the generator to natively create one 227 GrUniqueKey key;
228 const GrTextureParams& noStretchParams = GrTextureParams::ClampNoFilter();
229 GrMakeKeyFromImageID(&key, fUniqueID, SkIRect::MakeWH(fInfo.width(), fInfo.h eight()),
230 *ctx->caps(), noStretchParams);
231
232 // 1. Check the cache for a pre-existing one
233 if (GrTexture* tex = ctx->textureProvider()->findAndRefTextureByUniqueKey(ke y)) {
234 return tex;
235 }
236
237 // 2. Ask the genreator to natively create one
232 { 238 {
233 ScopedGenerator generator(this); 239 ScopedGenerator generator(this);
234 SkIRect subset = SkIRect::MakeXYWH(fOrigin.x(), fOrigin.y(), fInfo.width (), fInfo.height()); 240 SkIRect subset = SkIRect::MakeXYWH(fOrigin.x(), fOrigin.y(), fInfo.width (), fInfo.height());
235 if (GrTexture* tex = generator->generateTexture(ctx, &subset)) { 241 if (GrTexture* tex = generator->generateTexture(ctx, &subset)) {
236 return set_key_and_return(tex, key); 242 return set_key_and_return(tex, key);
237 } 243 }
238 } 244 }
239 245
240 const GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(fInfo); 246 const GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(fInfo);
241 247
(...skipping 12 matching lines...) Expand all
254 Generator_GrYUVProvider provider(generator); 260 Generator_GrYUVProvider provider(generator);
255 GrTexture* tex = provider.refAsTexture(ctx, desc, true); 261 GrTexture* tex = provider.refAsTexture(ctx, desc, true);
256 if (tex) { 262 if (tex) {
257 return set_key_and_return(tex, key); 263 return set_key_and_return(tex, key);
258 } 264 }
259 } 265 }
260 266
261 // 5. Ask the generator to return RGB(A) data, which the GPU can convert 267 // 5. Ask the generator to return RGB(A) data, which the GPU can convert
262 SkBitmap bitmap; 268 SkBitmap bitmap;
263 if (this->tryLockAsBitmap(&bitmap, client)) { 269 if (this->tryLockAsBitmap(&bitmap, client)) {
264 GrTexture* tex = GrUploadBitmapToTexture(ctx, bitmap); 270 return GrRefCachedBitmapTexture(ctx, bitmap, noStretchParams);
265 if (tex) {
266 return set_key_and_return(tex, key);
267 }
268 } 271 }
269 return nullptr; 272 return nullptr;
270 } 273 }
271 274
272 //////////////////////////////////////////////////////////////////////////////// /////////////////// 275 //////////////////////////////////////////////////////////////////////////////// ///////////////////
273 276
274 #include "GrTextureParamsAdjuster.h" 277 #include "GrTextureMaker.h"
275 278
276 class Cacherator_GrTextureParamsAdjuster : public GrTextureParamsAdjuster { 279 class Cacherator_GrTextureMaker : public GrTextureMaker {
277 public: 280 public:
278 Cacherator_GrTextureParamsAdjuster(SkImageCacherator* cacher, const SkImage* client) 281 Cacherator_GrTextureMaker(SkImageCacherator* cacher, const SkImage* client,
282 const GrUniqueKey& unstretchedKey)
279 : INHERITED(cacher->info().width(), cacher->info().height()) 283 : INHERITED(cacher->info().width(), cacher->info().height())
280 , fCacher(cacher) 284 , fCacher(cacher)
281 , fClient(client) 285 , fClient(client)
282 { 286 , fUnstretchedKey(unstretchedKey)
283 if (client) { 287 {}
284 GrMakeKeyFromImageID(&fOriginalKey, client->uniqueID(),
285 SkIRect::MakeWH(this->width(), this->height())) ;
286 }
287 }
288 288
289 protected: 289 protected:
290 // TODO: consider overriding this, for the case where the underlying generat or might be 290 // TODO: consider overriding this, for the case where the underlying generat or might be
291 // able to efficiently produce a "stretched" texture natively (e.g. pi cture-backed) 291 // able to efficiently produce a "stretched" texture natively (e.g. pi cture-backed)
292 // GrTexture* generateTextureForParams(GrContext*, const SkGrStretch&) ov erride; 292 // GrTexture* onGenerateStretchedTexture(GrContext*, const SkGrStretch&) over ride;
293 293
294 GrTexture* refOriginalTexture(GrContext* ctx) override { 294 GrTexture* onRefUnstretchedTexture(GrContext* ctx) override {
295 return fCacher->lockTexture(ctx, fOriginalKey, fClient); 295 return fCacher->lockUnstretchedTexture(ctx, fClient);
296 } 296 }
297 297
298 void makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey) over ride { 298 bool onMakeStretchedKey(const SkGrStretch& stretch, GrUniqueKey* stretchedKe y) override {
299 if (fOriginalKey.isValid()) { 299 return GrMakeStretchedKey(fUnstretchedKey, stretch, stretchedKey);
300 MakeCopyKeyFromOrigKey(fOriginalKey, stretch, paramsCopyKey);
301 }
302 } 300 }
303 301
304 void didCacheCopy(const GrUniqueKey& copyKey) override { 302 void onNotifyStretchCached(const GrUniqueKey& stretchedKey) override {
305 if (fClient) { 303 if (fClient) {
306 as_IB(fClient)->notifyAddedToCache(); 304 as_IB(fClient)->notifyAddedToCache();
307 } 305 }
308 } 306 }
309 307
310 bool getROBitmap(SkBitmap* bitmap) override { 308 bool onGetROBitmap(SkBitmap* bitmap) override {
311 return fCacher->lockAsBitmap(bitmap, fClient); 309 return fCacher->lockAsBitmap(bitmap, fClient);
312 } 310 }
313 311
314 private: 312 private:
315 SkImageCacherator* fCacher; 313 SkImageCacherator* fCacher;
316 const SkImage* fClient; 314 const SkImage* fClient;
317 GrUniqueKey fOriginalKey; 315 const GrUniqueKey fUnstretchedKey;
318 316
319 typedef GrTextureParamsAdjuster INHERITED; 317 typedef GrTextureMaker INHERITED;
320 }; 318 };
321 319
322 GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, const GrTextureParam s& params, 320 GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, const GrTextureParam s& params,
323 const SkImage* client) { 321 const SkImage* client) {
324 if (!ctx) { 322 if (!ctx) {
325 return nullptr; 323 return nullptr;
326 } 324 }
327 325
328 return Cacherator_GrTextureParamsAdjuster(this, client).refTextureForParams( ctx, params); 326 GrUniqueKey key;
327 GrMakeKeyFromImageID(&key, this->uniqueID(),
328 SkIRect::MakeWH(this->info().width(), this->info().heig ht()),
329 *ctx->caps(), GrTextureParams::ClampNoFilter());
330
331 return Cacherator_GrTextureMaker(this, client, key).refCachedTexture(ctx, pa rams);
329 } 332 }
330 333
331 #else 334 #else
332 335
333 GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, const GrTextureParam s&, 336 GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, const GrTextureParam s&,
334 const SkImage* client) { 337 const SkImage* client) {
335 return nullptr; 338 return nullptr;
336 } 339 }
337 340
338 #endif 341 #endif
OLDNEW
« no previous file with comments | « src/core/SkImageCacherator.h ('k') | src/gpu/GrGpu.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698