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

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

Issue 105523008: Revert "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/lazy/SkDiscardablePixelRef.h ('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 18 matching lines...) Expand all
29 29
30 SkDiscardablePixelRef::~SkDiscardablePixelRef() { 30 SkDiscardablePixelRef::~SkDiscardablePixelRef() {
31 if (this->isLocked()) { 31 if (this->isLocked()) {
32 fDiscardableMemory->unlock(); 32 fDiscardableMemory->unlock();
33 } 33 }
34 SkDELETE(fDiscardableMemory); 34 SkDELETE(fDiscardableMemory);
35 SkSafeUnref(fDMFactory); 35 SkSafeUnref(fDMFactory);
36 SkDELETE(fGenerator); 36 SkDELETE(fGenerator);
37 } 37 }
38 38
39 bool SkDiscardablePixelRef::onNewLockPixels(LockRec* rec) { 39 void* SkDiscardablePixelRef::onLockPixels(SkColorTable**) {
40 if (fDiscardableMemory != NULL) { 40 if (fDiscardableMemory != NULL) {
41 if (fDiscardableMemory->lock()) { 41 if (fDiscardableMemory->lock()) {
42 rec->fPixels = fDiscardableMemory->data(); 42 return fDiscardableMemory->data();
43 rec->fColorTable = NULL;
44 rec->fRowBytes = fRowBytes;
45 return true;
46 } 43 }
47 SkDELETE(fDiscardableMemory); 44 SkDELETE(fDiscardableMemory);
48 fDiscardableMemory = NULL; 45 fDiscardableMemory = NULL;
49 } 46 }
50 47
51 const size_t size = this->info().getSafeSize(fRowBytes); 48 const size_t size = this->info().getSafeSize(fRowBytes);
52 49
53 if (fDMFactory != NULL) { 50 if (fDMFactory != NULL) {
54 fDiscardableMemory = fDMFactory->create(size); 51 fDiscardableMemory = fDMFactory->create(size);
55 } else { 52 } else {
56 fDiscardableMemory = SkDiscardableMemory::Create(size); 53 fDiscardableMemory = SkDiscardableMemory::Create(size);
57 } 54 }
58 if (NULL == fDiscardableMemory) { 55 if (NULL == fDiscardableMemory) {
59 return false; // Memory allocation failed. 56 return NULL; // Memory allocation failed.
60 } 57 }
61
62 void* pixels = fDiscardableMemory->data(); 58 void* pixels = fDiscardableMemory->data();
63 if (!fGenerator->getPixels(this->info(), pixels, fRowBytes)) { 59 if (!fGenerator->getPixels(this->info(), pixels, fRowBytes)) {
64 fDiscardableMemory->unlock(); 60 fDiscardableMemory->unlock();
65 SkDELETE(fDiscardableMemory); 61 SkDELETE(fDiscardableMemory);
66 fDiscardableMemory = NULL; 62 fDiscardableMemory = NULL;
67 return false; 63 return NULL;
68 } 64 }
69 65 return pixels;
70 rec->fPixels = pixels;
71 rec->fColorTable = NULL;
72 rec->fRowBytes = fRowBytes;
73 return true;
74 } 66 }
75
76 void SkDiscardablePixelRef::onUnlockPixels() { 67 void SkDiscardablePixelRef::onUnlockPixels() {
77 fDiscardableMemory->unlock(); 68 fDiscardableMemory->unlock();
78 } 69 }
79 70
80 bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, 71 bool SkInstallDiscardablePixelRef(SkImageGenerator* generator,
81 SkBitmap* dst, 72 SkBitmap* dst,
82 SkDiscardableMemory::Factory* factory) { 73 SkDiscardableMemory::Factory* factory) {
83 SkImageInfo info; 74 SkImageInfo info;
84 SkAutoTDelete<SkImageGenerator> autoGenerator(generator); 75 SkAutoTDelete<SkImageGenerator> autoGenerator(generator);
85 if ((NULL == autoGenerator.get()) 76 if ((NULL == autoGenerator.get())
86 || (!autoGenerator->getInfo(&info)) 77 || (!autoGenerator->getInfo(&info))
87 || (!dst->setConfig(info, 0))) { 78 || (!dst->setConfig(info, 0))) {
88 return false; 79 return false;
89 } 80 }
90 SkASSERT(dst->config() != SkBitmap::kNo_Config); 81 SkASSERT(dst->config() != SkBitmap::kNo_Config);
91 if (dst->empty()) { // Use a normal pixelref. 82 if (dst->empty()) { // Use a normal pixelref.
92 return dst->allocPixels(NULL, NULL); 83 return dst->allocPixels(NULL, NULL);
93 } 84 }
94 SkAutoTUnref<SkDiscardablePixelRef> ref( 85 SkAutoTUnref<SkDiscardablePixelRef> ref(
95 SkNEW_ARGS(SkDiscardablePixelRef, 86 SkNEW_ARGS(SkDiscardablePixelRef,
96 (info, autoGenerator.detach(), dst->rowBytes(), factory))); 87 (info, autoGenerator.detach(), dst->rowBytes(), factory)));
97 dst->setPixelRef(ref); 88 dst->setPixelRef(ref);
98 return true; 89 return true;
99 } 90 }
OLDNEW
« no previous file with comments | « src/lazy/SkDiscardablePixelRef.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698