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

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

Issue 1199473002: change old picture serialization to really handle images (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 6 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
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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 rec->fColorTable = fCTable.get(); 100 rec->fColorTable = fCTable.get();
101 rec->fRowBytes = fRowBytes; 101 rec->fRowBytes = fRowBytes;
102 return true; 102 return true;
103 } 103 }
104 104
105 void SkDiscardablePixelRef::onUnlockPixels() { 105 void SkDiscardablePixelRef::onUnlockPixels() {
106 fDiscardableMemory->unlock(); 106 fDiscardableMemory->unlock();
107 fDiscardableMemoryIsLocked = false; 107 fDiscardableMemoryIsLocked = false;
108 } 108 }
109 109
110 bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, SkBitmap* dst, 110 bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, const SkIRect* su bset, SkBitmap* dst,
111 SkDiscardableMemory::Factory* factory) { 111 SkDiscardableMemory::Factory* factory) {
112 SkAutoTDelete<SkImageGenerator> autoGenerator(generator); 112 SkAutoTDelete<SkImageGenerator> autoGenerator(generator);
113 if (NULL == autoGenerator.get()) { 113 if (NULL == autoGenerator.get()) {
114 return false; 114 return false;
115 } 115 }
116
117 SkIPoint origin = SkIPoint::Make(0, 0);
116 SkImageInfo info = autoGenerator->getInfo(); 118 SkImageInfo info = autoGenerator->getInfo();
117 if (info.isEmpty() || !dst->setInfo(info)) { 119 if (info.isEmpty()) {
118 return false; 120 return false;
119 } 121 }
122 if (subset) {
123 if (subset->isEmpty() || !SkIRect::MakeWH(info.width(), info.height()).c ontains(*subset)) {
124 return false;
125 }
126 info = info.makeWH(subset->width(), subset->height());
127 origin.set(subset->x(), subset->y());
128 }
129 if (!dst->setInfo(info)) {
130 return false;
131 }
132
120 // Since dst->setInfo() may have changed/fixed-up info, we copy it back from that bitmap 133 // Since dst->setInfo() may have changed/fixed-up info, we copy it back from that bitmap
121 info = dst->info(); 134 info = dst->info();
122
123 SkASSERT(info.colorType() != kUnknown_SkColorType); 135 SkASSERT(info.colorType() != kUnknown_SkColorType);
124 if (dst->empty()) { // Use a normal pixelref. 136 if (dst->empty()) { // Use a normal pixelref.
125 return dst->tryAllocPixels(); 137 return dst->tryAllocPixels();
126 } 138 }
127 SkAutoTUnref<SkDiscardablePixelRef> ref( 139 SkAutoTUnref<SkDiscardablePixelRef> ref(
128 SkNEW_ARGS(SkDiscardablePixelRef, 140 SkNEW_ARGS(SkDiscardablePixelRef,
129 (info, autoGenerator.detach(), dst->rowBytes(), factory))); 141 (info, autoGenerator.detach(), dst->rowBytes(), factory)));
130 dst->setPixelRef(ref); 142 dst->setPixelRef(ref, origin.x(), origin.y());
131 return true; 143 return true;
132 } 144 }
133 145
134 // These are the public API 146 // These are the public API
135 147
136 bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, SkBitmap* dst) { 148 bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, SkBitmap* dst) {
137 return SkInstallDiscardablePixelRef(generator, dst, NULL); 149 return SkInstallDiscardablePixelRef(generator, NULL, dst, NULL);
138 } 150 }
139 151
140 bool SkInstallDiscardablePixelRef(SkData* encoded, SkBitmap* dst) { 152 bool SkInstallDiscardablePixelRef(SkData* encoded, SkBitmap* dst) {
141 SkImageGenerator* generator = SkImageGenerator::NewFromData(encoded); 153 SkImageGenerator* generator = SkImageGenerator::NewFromData(encoded);
142 return generator ? SkInstallDiscardablePixelRef(generator, dst, NULL) : fals e; 154 return generator ? SkInstallDiscardablePixelRef(generator, NULL, dst, NULL) : false;
143 } 155 }
OLDNEW
« gm/factory.cpp ('K') | « src/lazy/SkDiscardablePixelRef.h ('k') | src/utils/SkLua.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698