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

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

Issue 119753010: Revert "Revert of https://codereview.chromium.org/110593003/" (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « src/core/SkPixelRef.cpp ('k') | src/gpu/SkGrPixelRef.cpp » ('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 2013 Google Inc. 2 * Copyright 2013 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 "SkScaledImageCache.h" 8 #include "SkScaledImageCache.h"
9 #include "SkMipMap.h" 9 #include "SkMipMap.h"
10 #include "SkOnce.h" 10 #include "SkOnce.h"
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 192
193 class SkOneShotDiscardablePixelRef : public SkPixelRef { 193 class SkOneShotDiscardablePixelRef : public SkPixelRef {
194 public: 194 public:
195 // Ownership of the discardablememory is transfered to the pixelref 195 // Ownership of the discardablememory is transfered to the pixelref
196 SkOneShotDiscardablePixelRef(const SkImageInfo&, SkDiscardableMemory*, size_ t rowBytes); 196 SkOneShotDiscardablePixelRef(const SkImageInfo&, SkDiscardableMemory*, size_ t rowBytes);
197 ~SkOneShotDiscardablePixelRef(); 197 ~SkOneShotDiscardablePixelRef();
198 198
199 SK_DECLARE_UNFLATTENABLE_OBJECT() 199 SK_DECLARE_UNFLATTENABLE_OBJECT()
200 200
201 protected: 201 protected:
202 virtual void* onLockPixels(SkColorTable**) SK_OVERRIDE; 202 virtual bool onNewLockPixels(LockRec*) SK_OVERRIDE;
203 virtual void onUnlockPixels() SK_OVERRIDE; 203 virtual void onUnlockPixels() SK_OVERRIDE;
204 virtual size_t getAllocatedSizeInBytes() const SK_OVERRIDE; 204 virtual size_t getAllocatedSizeInBytes() const SK_OVERRIDE;
205 205
206 private: 206 private:
207 SkImageInfo fInfo; // remove when SkPixelRef gets this in baseclass
208
209 SkDiscardableMemory* fDM; 207 SkDiscardableMemory* fDM;
210 size_t fRB; 208 size_t fRB;
211 bool fFirstTime; 209 bool fFirstTime;
212 210
213 typedef SkPixelRef INHERITED; 211 typedef SkPixelRef INHERITED;
214 }; 212 };
215 213
216 SkOneShotDiscardablePixelRef::SkOneShotDiscardablePixelRef(const SkImageInfo& in fo, 214 SkOneShotDiscardablePixelRef::SkOneShotDiscardablePixelRef(const SkImageInfo& in fo,
217 SkDiscardableMemory* dm, 215 SkDiscardableMemory* dm,
218 size_t rowBytes) 216 size_t rowBytes)
219 : INHERITED(info) 217 : INHERITED(info)
220 , fDM(dm) 218 , fDM(dm)
221 , fRB(rowBytes) 219 , fRB(rowBytes)
222 { 220 {
223 fInfo = info; // remove this redundant field when SkPixelRef has info
224
225 SkASSERT(dm->data()); 221 SkASSERT(dm->data());
226 fFirstTime = true; 222 fFirstTime = true;
227 } 223 }
228 224
229 SkOneShotDiscardablePixelRef::~SkOneShotDiscardablePixelRef() { 225 SkOneShotDiscardablePixelRef::~SkOneShotDiscardablePixelRef() {
230 SkDELETE(fDM); 226 SkDELETE(fDM);
231 } 227 }
232 228
233 void* SkOneShotDiscardablePixelRef::onLockPixels(SkColorTable** ctable) { 229 bool SkOneShotDiscardablePixelRef::onNewLockPixels(LockRec* rec) {
234 if (fFirstTime) { 230 if (fFirstTime) {
235 // we're already locked 231 // we're already locked
236 SkASSERT(fDM->data()); 232 SkASSERT(fDM->data());
237 fFirstTime = false; 233 fFirstTime = false;
238 return fDM->data(); 234 goto SUCCESS;
239 } 235 }
240 236
241 // A previous call to onUnlock may have deleted our DM, so check for that 237 // A previous call to onUnlock may have deleted our DM, so check for that
242 if (NULL == fDM) { 238 if (NULL == fDM) {
243 return NULL; 239 return false;
244 } 240 }
245 241
246 if (!fDM->lock()) { 242 if (!fDM->lock()) {
247 // since it failed, we delete it now, to free-up the resource 243 // since it failed, we delete it now, to free-up the resource
248 delete fDM; 244 delete fDM;
249 fDM = NULL; 245 fDM = NULL;
250 return NULL; 246 return false;
251 } 247 }
252 return fDM->data(); 248
249 SUCCESS:
250 rec->fPixels = fDM->data();
251 rec->fColorTable = NULL;
252 rec->fRowBytes = fRB;
253 return true;
253 } 254 }
254 255
255 void SkOneShotDiscardablePixelRef::onUnlockPixels() { 256 void SkOneShotDiscardablePixelRef::onUnlockPixels() {
256 SkASSERT(!fFirstTime); 257 SkASSERT(!fFirstTime);
257 fDM->unlock(); 258 fDM->unlock();
258 } 259 }
259 260
260 size_t SkOneShotDiscardablePixelRef::getAllocatedSizeInBytes() const { 261 size_t SkOneShotDiscardablePixelRef::getAllocatedSizeInBytes() const {
261 return fInfo.fHeight * fRB; 262 return this->info().getSafeSize(fRB);
262 } 263 }
263 264
264 class SkScaledImageCacheDiscardableAllocator : public SkBitmap::Allocator { 265 class SkScaledImageCacheDiscardableAllocator : public SkBitmap::Allocator {
265 public: 266 public:
266 SkScaledImageCacheDiscardableAllocator( 267 SkScaledImageCacheDiscardableAllocator(
267 SkScaledImageCache::DiscardableFactory factory) { 268 SkScaledImageCache::DiscardableFactory factory) {
268 SkASSERT(factory); 269 SkASSERT(factory);
269 fFactory = factory; 270 fFactory = factory;
270 } 271 }
271 272
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 return SkScaledImageCache::GetBytesUsed(); 794 return SkScaledImageCache::GetBytesUsed();
794 } 795 }
795 796
796 size_t SkGraphics::GetImageCacheByteLimit() { 797 size_t SkGraphics::GetImageCacheByteLimit() {
797 return SkScaledImageCache::GetByteLimit(); 798 return SkScaledImageCache::GetByteLimit();
798 } 799 }
799 800
800 size_t SkGraphics::SetImageCacheByteLimit(size_t newLimit) { 801 size_t SkGraphics::SetImageCacheByteLimit(size_t newLimit) {
801 return SkScaledImageCache::SetByteLimit(newLimit); 802 return SkScaledImageCache::SetByteLimit(newLimit);
802 } 803 }
OLDNEW
« no previous file with comments | « src/core/SkPixelRef.cpp ('k') | src/gpu/SkGrPixelRef.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698