| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 } |
| OLD | NEW |