OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2008 The Android Open Source Project | 3 * Copyright 2008 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 } | 326 } |
327 | 327 |
328 bool SkBitmap::setAlphaType(SkAlphaType alphaType) { | 328 bool SkBitmap::setAlphaType(SkAlphaType alphaType) { |
329 if (!validate_alphaType(this->config(), alphaType, &alphaType)) { | 329 if (!validate_alphaType(this->config(), alphaType, &alphaType)) { |
330 return false; | 330 return false; |
331 } | 331 } |
332 fAlphaType = SkToU8(alphaType); | 332 fAlphaType = SkToU8(alphaType); |
333 return true; | 333 return true; |
334 } | 334 } |
335 | 335 |
| 336 SkPixelRef* SkBitmap::installPixelRef(SkPixelRef* pr, const SkIRect* subset) { |
| 337 if (NULL == pr) { |
| 338 this->reset(); |
| 339 return NULL; |
| 340 } |
| 341 |
| 342 const SkImageInfo& info = pr->info(); |
| 343 |
| 344 fConfig = SkColorTypeToBitmapConfig(info.fColorType); |
| 345 fAlphaType = info.fAlphaType; |
| 346 fBytesPerPixel = info.bytesPerPixel(); |
| 347 // not known until we're locked |
| 348 fRowBytes = 0; |
| 349 |
| 350 SkIRect bounds = { 0, 0, info.fWidth, info.fHeight }; |
| 351 if (subset && !bounds.intersect(*subset)) { |
| 352 bounds.setEmpty(); |
| 353 } |
| 354 |
| 355 fWidth = bounds.width(); |
| 356 fHeight = bounds.height(); |
| 357 return this->setPixelRef(pr, bounds.left(), bounds.top()); |
| 358 } |
| 359 |
336 void SkBitmap::updatePixelsFromRef() const { | 360 void SkBitmap::updatePixelsFromRef() const { |
337 if (NULL != fPixelRef) { | 361 if (NULL != fPixelRef) { |
338 if (fPixelLockCount > 0) { | 362 if (fPixelLockCount > 0) { |
339 SkASSERT(fPixelRef->isLocked()); | 363 SkASSERT(fPixelRef->isLocked()); |
340 | 364 |
341 void* p = fPixelRef->pixels(); | 365 void* p = fPixelRef->pixels(); |
342 if (NULL != p) { | 366 if (NULL != p) { |
343 p = (char*)p | 367 p = (char*)p |
344 + fPixelRefOrigin.fY * fRowBytes | 368 + fPixelRefOrigin.fY * fRowBytes |
345 + fPixelRefOrigin.fX * fBytesPerPixel; | 369 + fPixelRefOrigin.fX * fBytesPerPixel; |
(...skipping 1290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1636 if (NULL != uri) { | 1660 if (NULL != uri) { |
1637 str->appendf(" uri:\"%s\"", uri); | 1661 str->appendf(" uri:\"%s\"", uri); |
1638 } else { | 1662 } else { |
1639 str->appendf(" pixelref:%p", pr); | 1663 str->appendf(" pixelref:%p", pr); |
1640 } | 1664 } |
1641 } | 1665 } |
1642 | 1666 |
1643 str->append(")"); | 1667 str->append(")"); |
1644 } | 1668 } |
1645 #endif | 1669 #endif |
OLD | NEW |