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

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

Issue 808853003: [M40 merge] Detect discarded SkPictureShader pixel refs. (Closed) Base URL: https://skia.googlesource.com/skia.git@m40
Patch Set: Created 6 years 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 | « no previous file | no next file » | 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 2014 Google Inc. 2 * Copyright 2014 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 "SkPictureShader.h" 8 #include "SkPictureShader.h"
9 9
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 virtual const Key& getKey() const SK_OVERRIDE { return fKey; } 70 virtual const Key& getKey() const SK_OVERRIDE { return fKey; }
71 virtual size_t bytesUsed() const SK_OVERRIDE { 71 virtual size_t bytesUsed() const SK_OVERRIDE {
72 return sizeof(fKey) + sizeof(SkShader) + fBitmapBytes; 72 return sizeof(fKey) + sizeof(SkShader) + fBitmapBytes;
73 } 73 }
74 74
75 static bool Visitor(const SkResourceCache::Rec& baseRec, void* contextShader ) { 75 static bool Visitor(const SkResourceCache::Rec& baseRec, void* contextShader ) {
76 const BitmapShaderRec& rec = static_cast<const BitmapShaderRec&>(baseRec ); 76 const BitmapShaderRec& rec = static_cast<const BitmapShaderRec&>(baseRec );
77 SkAutoTUnref<SkShader>* result = reinterpret_cast<SkAutoTUnref<SkShader> *>(contextShader); 77 SkAutoTUnref<SkShader>* result = reinterpret_cast<SkAutoTUnref<SkShader> *>(contextShader);
78 78
79 result->reset(SkRef(rec.fShader.get())); 79 result->reset(SkRef(rec.fShader.get()));
80 return true; 80
81 SkBitmap tile;
82 rec.fShader.get()->asABitmap(&tile, NULL, NULL);
83 // FIXME: this doesn't protect the pixels from being discarded as soon a s we unlock.
84 // Should be handled via a pixel ref generator instead
85 // (https://code.google.com/p/skia/issues/detail?id=3220).
86 SkAutoLockPixels alp(tile, true);
87 return tile.getPixels() != NULL;
81 } 88 }
82 }; 89 };
83 90
84 static bool cache_try_alloc_pixels(SkBitmap* bitmap) { 91 static bool cache_try_alloc_pixels(SkBitmap* bitmap) {
85 SkBitmap::Allocator* allocator = SkResourceCache::GetAllocator(); 92 SkBitmap::Allocator* allocator = SkResourceCache::GetAllocator();
86 93
87 return NULL != allocator 94 return NULL != allocator
88 ? allocator->allocPixelRef(bitmap, NULL) 95 ? allocator->allocPixelRef(bitmap, NULL)
89 : bitmap->tryAllocPixels(); 96 : bitmap->tryAllocPixels();
90 } 97 }
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 } 304 }
298 return bitmapShader->asFragmentProcessor(context, paint, NULL, paintColor, f p); 305 return bitmapShader->asFragmentProcessor(context, paint, NULL, paintColor, f p);
299 } 306 }
300 #else 307 #else
301 bool SkPictureShader::asFragmentProcessor(GrContext*, const SkPaint&, const SkMa trix*, GrColor*, 308 bool SkPictureShader::asFragmentProcessor(GrContext*, const SkPaint&, const SkMa trix*, GrColor*,
302 GrFragmentProcessor**) const { 309 GrFragmentProcessor**) const {
303 SkDEBUGFAIL("Should not call in GPU-less build"); 310 SkDEBUGFAIL("Should not call in GPU-less build");
304 return false; 311 return false;
305 } 312 }
306 #endif 313 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698