| 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 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 } | 303 } |
| 304 if (ctOut) { | 304 if (ctOut) { |
| 305 *ctOut = ct; | 305 *ctOut = ct; |
| 306 } | 306 } |
| 307 return true; | 307 return true; |
| 308 } | 308 } |
| 309 | 309 |
| 310 SkPixelRef* SkBitmap::setPixelRef(SkPixelRef* pr, int dx, int dy) { | 310 SkPixelRef* SkBitmap::setPixelRef(SkPixelRef* pr, int dx, int dy) { |
| 311 #ifdef SK_DEBUG | 311 #ifdef SK_DEBUG |
| 312 if (pr) { | 312 if (pr) { |
| 313 SkImageInfo info; | 313 if (kUnknown_SkColorType != fInfo.colorType()) { |
| 314 if (this->asImageInfo(&info)) { | |
| 315 const SkImageInfo& prInfo = pr->info(); | 314 const SkImageInfo& prInfo = pr->info(); |
| 316 SkASSERT(info.fWidth <= prInfo.fWidth); | 315 SkASSERT(fInfo.fWidth <= prInfo.fWidth); |
| 317 SkASSERT(info.fHeight <= prInfo.fHeight); | 316 SkASSERT(fInfo.fHeight <= prInfo.fHeight); |
| 318 SkASSERT(info.fColorType == prInfo.fColorType); | 317 SkASSERT(fInfo.fColorType == prInfo.fColorType); |
| 319 switch (prInfo.fAlphaType) { | 318 switch (prInfo.fAlphaType) { |
| 320 case kIgnore_SkAlphaType: | 319 case kIgnore_SkAlphaType: |
| 321 SkASSERT(fInfo.fAlphaType == kIgnore_SkAlphaType); | 320 SkASSERT(fInfo.fAlphaType == kIgnore_SkAlphaType); |
| 322 break; | 321 break; |
| 323 case kOpaque_SkAlphaType: | 322 case kOpaque_SkAlphaType: |
| 324 case kPremul_SkAlphaType: | 323 case kPremul_SkAlphaType: |
| 325 SkASSERT(info.fAlphaType == kOpaque_SkAlphaType || | 324 SkASSERT(fInfo.fAlphaType == kOpaque_SkAlphaType || |
| 326 info.fAlphaType == kPremul_SkAlphaType); | 325 fInfo.fAlphaType == kPremul_SkAlphaType); |
| 327 break; | 326 break; |
| 328 case kUnpremul_SkAlphaType: | 327 case kUnpremul_SkAlphaType: |
| 329 SkASSERT(info.fAlphaType == kOpaque_SkAlphaType || | 328 SkASSERT(fInfo.fAlphaType == kOpaque_SkAlphaType || |
| 330 info.fAlphaType == kUnpremul_SkAlphaType); | 329 fInfo.fAlphaType == kUnpremul_SkAlphaType); |
| 331 break; | 330 break; |
| 332 } | 331 } |
| 333 } | 332 } |
| 334 } | 333 } |
| 335 #endif | 334 #endif |
| 336 | 335 |
| 337 if (pr) { | 336 if (pr) { |
| 338 const SkImageInfo& info = pr->info(); | 337 const SkImageInfo& info = pr->info(); |
| 339 fPixelRefOrigin.set(SkPin32(dx, 0, info.fWidth), | 338 fPixelRefOrigin.set(SkPin32(dx, 0, info.fWidth), |
| 340 SkPin32(dy, 0, info.fHeight)); | 339 SkPin32(dy, 0, info.fHeight)); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 bool SkBitmap::lockPixelsAreWritable() const { | 378 bool SkBitmap::lockPixelsAreWritable() const { |
| 380 return (fPixelRef) ? fPixelRef->lockPixelsAreWritable() : false; | 379 return (fPixelRef) ? fPixelRef->lockPixelsAreWritable() : false; |
| 381 } | 380 } |
| 382 | 381 |
| 383 void SkBitmap::setPixels(void* p, SkColorTable* ctable) { | 382 void SkBitmap::setPixels(void* p, SkColorTable* ctable) { |
| 384 if (NULL == p) { | 383 if (NULL == p) { |
| 385 this->setPixelRef(NULL); | 384 this->setPixelRef(NULL); |
| 386 return; | 385 return; |
| 387 } | 386 } |
| 388 | 387 |
| 389 SkImageInfo info; | 388 if (kUnknown_SkColorType == fInfo.colorType()) { |
| 390 if (!this->asImageInfo(&info)) { | |
| 391 this->setPixelRef(NULL); | 389 this->setPixelRef(NULL); |
| 392 return; | 390 return; |
| 393 } | 391 } |
| 394 | 392 |
| 395 SkPixelRef* pr = SkMallocPixelRef::NewDirect(info, p, fRowBytes, ctable); | 393 SkPixelRef* pr = SkMallocPixelRef::NewDirect(fInfo, p, fRowBytes, ctable); |
| 396 if (NULL == pr) { | 394 if (NULL == pr) { |
| 397 this->setPixelRef(NULL); | 395 this->setPixelRef(NULL); |
| 398 return; | 396 return; |
| 399 } | 397 } |
| 400 | 398 |
| 401 this->setPixelRef(pr)->unref(); | 399 this->setPixelRef(pr)->unref(); |
| 402 | 400 |
| 403 // since we're already allocated, we lockPixels right away | 401 // since we're already allocated, we lockPixels right away |
| 404 this->lockPixels(); | 402 this->lockPixels(); |
| 405 SkDEBUGCODE(this->validate();) | 403 SkDEBUGCODE(this->validate();) |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 return fPixelRef ? fPixelRef->getTexture() : NULL; | 517 return fPixelRef ? fPixelRef->getTexture() : NULL; |
| 520 } | 518 } |
| 521 | 519 |
| 522 /////////////////////////////////////////////////////////////////////////////// | 520 /////////////////////////////////////////////////////////////////////////////// |
| 523 | 521 |
| 524 /** We explicitly use the same allocator for our pixels that SkMask does, | 522 /** We explicitly use the same allocator for our pixels that SkMask does, |
| 525 so that we can freely assign memory allocated by one class to the other. | 523 so that we can freely assign memory allocated by one class to the other. |
| 526 */ | 524 */ |
| 527 bool SkBitmap::HeapAllocator::allocPixelRef(SkBitmap* dst, | 525 bool SkBitmap::HeapAllocator::allocPixelRef(SkBitmap* dst, |
| 528 SkColorTable* ctable) { | 526 SkColorTable* ctable) { |
| 529 SkImageInfo info; | 527 const SkImageInfo info = dst->info(); |
| 530 if (!dst->asImageInfo(&info)) { | 528 if (kUnknown_SkColorType == info.colorType()) { |
| 531 // SkDebugf("unsupported config for info %d\n", dst->config()); | 529 // SkDebugf("unsupported config for info %d\n", dst->config()); |
| 532 return false; | 530 return false; |
| 533 } | 531 } |
| 534 | 532 |
| 535 SkPixelRef* pr = SkMallocPixelRef::NewAllocate(info, dst->rowBytes(), | 533 SkPixelRef* pr = SkMallocPixelRef::NewAllocate(info, dst->rowBytes(), ctable
); |
| 536 ctable); | |
| 537 if (NULL == pr) { | 534 if (NULL == pr) { |
| 538 return false; | 535 return false; |
| 539 } | 536 } |
| 540 | 537 |
| 541 dst->setPixelRef(pr)->unref(); | 538 dst->setPixelRef(pr)->unref(); |
| 542 // since we're already allocated, we lockPixels right away | 539 // since we're already allocated, we lockPixels right away |
| 543 dst->lockPixels(); | 540 dst->lockPixels(); |
| 544 return true; | 541 return true; |
| 545 } | 542 } |
| 546 | 543 |
| (...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1480 /////////////////////////////////////////////////////////////////////////////// | 1477 /////////////////////////////////////////////////////////////////////////////// |
| 1481 | 1478 |
| 1482 #ifdef SK_DEBUG | 1479 #ifdef SK_DEBUG |
| 1483 void SkImageInfo::validate() const { | 1480 void SkImageInfo::validate() const { |
| 1484 SkASSERT(fWidth >= 0); | 1481 SkASSERT(fWidth >= 0); |
| 1485 SkASSERT(fHeight >= 0); | 1482 SkASSERT(fHeight >= 0); |
| 1486 SkASSERT(SkColorTypeIsValid(fColorType)); | 1483 SkASSERT(SkColorTypeIsValid(fColorType)); |
| 1487 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); | 1484 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); |
| 1488 } | 1485 } |
| 1489 #endif | 1486 #endif |
| OLD | NEW |