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

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

Issue 1463373002: scaling API on SkPixmap (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 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
« no previous file with comments | « src/core/SkImageCacherator.cpp ('k') | src/image/SkImage.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 2015 Google Inc. 2 * Copyright 2015 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 "SkColorPriv.h" 8 #include "SkColorPriv.h"
9 #include "SkConfig8888.h" 9 #include "SkConfig8888.h"
10 #include "SkMask.h" 10 #include "SkMask.h"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 p = (uint32_t*)((char*)p + rowBytes); 198 p = (uint32_t*)((char*)p + rowBytes);
199 } 199 }
200 break; 200 break;
201 } 201 }
202 default: 202 default:
203 return false; // no change, so don't call notifyPixelsChanged() 203 return false; // no change, so don't call notifyPixelsChanged()
204 } 204 }
205 return true; 205 return true;
206 } 206 }
207 207
208 #include "SkBitmap.h"
209 #include "SkCanvas.h"
210 #include "SkSurface.h"
211 #include "SkXfermode.h"
212
213 bool SkPixmap::scalePixels(const SkPixmap& dst, SkFilterQuality quality) const {
214 // Can't do anthing with empty src or dst
215 if (this->width() <= 0 || this->height() <= 0 || dst.width() <= 0 || dst.hei ght() <= 0) {
216 return false;
217 }
218
219 // no scaling involved?
220 if (dst.width() == this->width() && dst.height() == this->height()) {
221 return this->readPixels(dst);
222 }
223
224 SkBitmap bitmap;
225 // we will only ready from this pixmap, but the bitmap setting takes void*, hence the cast
226 void* readOnlyAddr = const_cast<void*>(this->addr());
227 if (!bitmap.installPixels(this->info(), readOnlyAddr, this->rowBytes())) {
228 return false;
229 }
230 bitmap.setIsVolatile(true); // so we don't try to cache it
231
232 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterDirect(dst.info(), dst.w ritable_addr(),
233 dst.rowBytes()));
234 if (!surface) {
235 return false;
236 }
237
238 SkPaint paint;
239 paint.setFilterQuality(quality);
240 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
241 surface->getCanvas()->drawBitmapRect(bitmap, SkRect::MakeIWH(dst.width(), ds t.height()),
242 &paint);
243 return true;
244 }
245
208 //////////////////////////////////////////////////////////////////////////////// ////////////////// 246 //////////////////////////////////////////////////////////////////////////////// //////////////////
209 247
210 SkAutoPixmapStorage::SkAutoPixmapStorage() : fStorage(nullptr) {} 248 SkAutoPixmapStorage::SkAutoPixmapStorage() : fStorage(nullptr) {}
211 249
212 SkAutoPixmapStorage::~SkAutoPixmapStorage() { 250 SkAutoPixmapStorage::~SkAutoPixmapStorage() {
213 this->freeStorage(); 251 this->freeStorage();
214 } 252 }
215 253
216 bool SkAutoPixmapStorage::tryAlloc(const SkImageInfo& info) { 254 bool SkAutoPixmapStorage::tryAlloc(const SkImageInfo& info) {
217 this->freeStorage(); 255 this->freeStorage();
(...skipping 10 matching lines...) Expand all
228 this->reset(info, pixels, rb); 266 this->reset(info, pixels, rb);
229 fStorage = pixels; 267 fStorage = pixels;
230 return true; 268 return true;
231 } 269 }
232 270
233 void SkAutoPixmapStorage::alloc(const SkImageInfo& info) { 271 void SkAutoPixmapStorage::alloc(const SkImageInfo& info) {
234 if (!this->tryAlloc(info)) { 272 if (!this->tryAlloc(info)) {
235 sk_throw(); 273 sk_throw();
236 } 274 }
237 } 275 }
OLDNEW
« no previous file with comments | « src/core/SkImageCacherator.cpp ('k') | src/image/SkImage.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698