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

Side by Side Diff: src/lazy/SkDiscardablePixelRef.cpp

Issue 108613005: Ensure we call onUnlock only if onLock succeeded (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « src/lazy/SkCachingPixelRef.cpp ('k') | 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 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 "SkDiscardablePixelRef.h" 8 #include "SkDiscardablePixelRef.h"
9 #include "SkDiscardableMemory.h" 9 #include "SkDiscardableMemory.h"
10 #include "SkImageGenerator.h" 10 #include "SkImageGenerator.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 if (fDMFactory != NULL) { 49 if (fDMFactory != NULL) {
50 fDiscardableMemory = fDMFactory->create(fSize); 50 fDiscardableMemory = fDMFactory->create(fSize);
51 } else { 51 } else {
52 fDiscardableMemory = SkDiscardableMemory::Create(fSize); 52 fDiscardableMemory = SkDiscardableMemory::Create(fSize);
53 } 53 }
54 if (NULL == fDiscardableMemory) { 54 if (NULL == fDiscardableMemory) {
55 return NULL; // Memory allocation failed. 55 return NULL; // Memory allocation failed.
56 } 56 }
57 void* pixels = fDiscardableMemory->data(); 57 void* pixels = fDiscardableMemory->data();
58 if (!fGenerator->getPixels(fInfo, pixels, fRowBytes)) { 58 if (!fGenerator->getPixels(fInfo, pixels, fRowBytes)) {
59 return NULL; // TODO(halcanary) Find out correct thing to do. 59 fDiscardableMemory->unlock();
60 SkDELETE(fDiscardableMemory);
61 fDiscardableMemory = NULL;
62 return NULL;
60 } 63 }
61 return pixels; 64 return pixels;
62 } 65 }
63 void SkDiscardablePixelRef::onUnlockPixels() { 66 void SkDiscardablePixelRef::onUnlockPixels() {
64 if (fDiscardableMemory != NULL) { 67 fDiscardableMemory->unlock();
65 fDiscardableMemory->unlock();
66 }
67 } 68 }
68 69
69 bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, 70 bool SkInstallDiscardablePixelRef(SkImageGenerator* generator,
70 SkBitmap* dst, 71 SkBitmap* dst,
71 SkDiscardableMemory::Factory* factory) { 72 SkDiscardableMemory::Factory* factory) {
72 SkImageInfo info; 73 SkImageInfo info;
73 SkASSERT(generator != NULL); 74 SkASSERT(generator != NULL);
74 if ((NULL == generator) 75 if ((NULL == generator)
75 || (!generator->getInfo(&info)) 76 || (!generator->getInfo(&info))
76 || (!dst->setConfig(info, 0))) { 77 || (!dst->setConfig(info, 0))) {
77 SkDELETE(generator); 78 SkDELETE(generator);
78 return false; 79 return false;
79 } 80 }
80 SkASSERT(dst->config() != SkBitmap::kNo_Config); 81 SkASSERT(dst->config() != SkBitmap::kNo_Config);
81 if (dst->empty()) { // Use a normal pixelref. 82 if (dst->empty()) { // Use a normal pixelref.
82 SkDELETE(generator); // Do not need this anymore. 83 SkDELETE(generator); // Do not need this anymore.
83 return dst->allocPixels(NULL, NULL); 84 return dst->allocPixels(NULL, NULL);
84 } 85 }
85 SkAutoTUnref<SkDiscardablePixelRef> ref(SkNEW_ARGS(SkDiscardablePixelRef, 86 SkAutoTUnref<SkDiscardablePixelRef> ref(SkNEW_ARGS(SkDiscardablePixelRef,
86 (generator, info, 87 (generator, info,
87 dst->getSize(), 88 dst->getSize(),
88 dst->rowBytes(), 89 dst->rowBytes(),
89 factory))); 90 factory)));
90 dst->setPixelRef(ref); 91 dst->setPixelRef(ref);
91 return true; 92 return true;
92 } 93 }
OLDNEW
« no previous file with comments | « src/lazy/SkCachingPixelRef.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698