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

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

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