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

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

Issue 119753009: Revert of Add onNewLockPixels, that returns rowbytes and relies on info in pixelref (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 bool onNewLockPixels(LockRec*) SK_OVERRIDE; 202 virtual void* onLockPixels(SkColorTable**) 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
207 SkDiscardableMemory* fDM; 209 SkDiscardableMemory* fDM;
208 size_t fRB; 210 size_t fRB;
209 bool fFirstTime; 211 bool fFirstTime;
210 212
211 typedef SkPixelRef INHERITED; 213 typedef SkPixelRef INHERITED;
212 }; 214 };
213 215
214 SkOneShotDiscardablePixelRef::SkOneShotDiscardablePixelRef(const SkImageInfo& in fo, 216 SkOneShotDiscardablePixelRef::SkOneShotDiscardablePixelRef(const SkImageInfo& in fo,
215 SkDiscardableMemory* dm, 217 SkDiscardableMemory* dm,
216 size_t rowBytes) 218 size_t rowBytes)
217 : INHERITED(info) 219 : INHERITED(info)
218 , fDM(dm) 220 , fDM(dm)
219 , fRB(rowBytes) 221 , fRB(rowBytes)
220 { 222 {
223 fInfo = info; // remove this redundant field when SkPixelRef has info
224
221 SkASSERT(dm->data()); 225 SkASSERT(dm->data());
222 fFirstTime = true; 226 fFirstTime = true;
223 } 227 }
224 228
225 SkOneShotDiscardablePixelRef::~SkOneShotDiscardablePixelRef() { 229 SkOneShotDiscardablePixelRef::~SkOneShotDiscardablePixelRef() {
226 SkDELETE(fDM); 230 SkDELETE(fDM);
227 } 231 }
228 232
229 bool SkOneShotDiscardablePixelRef::onNewLockPixels(LockRec* rec) { 233 void* SkOneShotDiscardablePixelRef::onLockPixels(SkColorTable** ctable) {
230 if (fFirstTime) { 234 if (fFirstTime) {
231 // we're already locked 235 // we're already locked
232 SkASSERT(fDM->data()); 236 SkASSERT(fDM->data());
233 fFirstTime = false; 237 fFirstTime = false;
234 goto SUCCESS; 238 return fDM->data();
235 } 239 }
236 240
237 // A previous call to onUnlock may have deleted our DM, so check for that 241 // A previous call to onUnlock may have deleted our DM, so check for that
238 if (NULL == fDM) { 242 if (NULL == fDM) {
239 return false; 243 return NULL;
240 } 244 }
241 245
242 if (!fDM->lock()) { 246 if (!fDM->lock()) {
243 // since it failed, we delete it now, to free-up the resource 247 // since it failed, we delete it now, to free-up the resource
244 delete fDM; 248 delete fDM;
245 fDM = NULL; 249 fDM = NULL;
246 return false; 250 return NULL;
247 } 251 }
248 252 return fDM->data();
249 SUCCESS:
250 rec->fPixels = fDM->data();
251 rec->fColorTable = NULL;
252 rec->fRowBytes = fRB;
253 return true;
254 } 253 }
255 254
256 void SkOneShotDiscardablePixelRef::onUnlockPixels() { 255 void SkOneShotDiscardablePixelRef::onUnlockPixels() {
257 SkASSERT(!fFirstTime); 256 SkASSERT(!fFirstTime);
258 fDM->unlock(); 257 fDM->unlock();
259 } 258 }
260 259
261 size_t SkOneShotDiscardablePixelRef::getAllocatedSizeInBytes() const { 260 size_t SkOneShotDiscardablePixelRef::getAllocatedSizeInBytes() const {
262 return this->info().getSafeSize(fRB); 261 return fInfo.fHeight * fRB;
263 } 262 }
264 263
265 class SkScaledImageCacheDiscardableAllocator : public SkBitmap::Allocator { 264 class SkScaledImageCacheDiscardableAllocator : public SkBitmap::Allocator {
266 public: 265 public:
267 SkScaledImageCacheDiscardableAllocator( 266 SkScaledImageCacheDiscardableAllocator(
268 SkScaledImageCache::DiscardableFactory factory) { 267 SkScaledImageCache::DiscardableFactory factory) {
269 SkASSERT(factory); 268 SkASSERT(factory);
270 fFactory = factory; 269 fFactory = factory;
271 } 270 }
272 271
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 return SkScaledImageCache::GetBytesUsed(); 793 return SkScaledImageCache::GetBytesUsed();
795 } 794 }
796 795
797 size_t SkGraphics::GetImageCacheByteLimit() { 796 size_t SkGraphics::GetImageCacheByteLimit() {
798 return SkScaledImageCache::GetByteLimit(); 797 return SkScaledImageCache::GetByteLimit();
799 } 798 }
800 799
801 size_t SkGraphics::SetImageCacheByteLimit(size_t newLimit) { 800 size_t SkGraphics::SetImageCacheByteLimit(size_t newLimit) {
802 return SkScaledImageCache::SetByteLimit(newLimit); 801 return SkScaledImageCache::SetByteLimit(newLimit);
803 } 802 }
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