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 "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 tmp.setConfig(SkBitmap::kARGB_8888_Config, bounds.width(), | 691 tmp.setConfig(SkBitmap::kARGB_8888_Config, bounds.width(), |
692 bounds.height()); | 692 bounds.height()); |
693 if (this->readPixels(&tmp, bounds.fLeft, bounds.fTop)) { | 693 if (this->readPixels(&tmp, bounds.fLeft, bounds.fTop)) { |
694 bitmap->swap(tmp); | 694 bitmap->swap(tmp); |
695 return true; | 695 return true; |
696 } else { | 696 } else { |
697 return false; | 697 return false; |
698 } | 698 } |
699 } | 699 } |
700 | 700 |
| 701 #ifdef SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG |
701 void SkCanvas::writePixels(const SkBitmap& bitmap, int x, int y, | 702 void SkCanvas::writePixels(const SkBitmap& bitmap, int x, int y, |
702 Config8888 config8888) { | 703 Config8888 config8888) { |
703 SkBaseDevice* device = this->getDevice(); | 704 SkBaseDevice* device = this->getDevice(); |
704 if (device) { | 705 if (device) { |
705 if (SkIRect::Intersects(SkIRect::MakeSize(this->getDeviceSize()), | 706 if (SkIRect::Intersects(SkIRect::MakeSize(this->getDeviceSize()), |
706 SkIRect::MakeXYWH(x, y, bitmap.width(), bitmap.h
eight()))) { | 707 SkIRect::MakeXYWH(x, y, bitmap.width(), bitmap.h
eight()))) { |
707 device->accessBitmap(true); | 708 device->accessBitmap(true); |
708 device->writePixels(bitmap, x, y, config8888); | 709 device->writePixels(bitmap, x, y, config8888); |
709 } | 710 } |
710 } | 711 } |
711 } | 712 } |
| 713 #endif |
| 714 |
| 715 bool SkCanvas::writePixels(const SkBitmap& bitmap, int x, int y) { |
| 716 if (bitmap.getTexture()) { |
| 717 return false; |
| 718 } |
| 719 SkBitmap bm(bitmap); |
| 720 bm.lockPixels(); |
| 721 if (bm.getPixels()) { |
| 722 return this->writePixels(bm.info(), bm.getPixels(), bm.rowBytes(), x, y)
; |
| 723 } |
| 724 return false; |
| 725 } |
| 726 |
| 727 bool SkCanvas::writePixels(const SkImageInfo& origInfo, const void* pixels, size
_t rowBytes, |
| 728 int x, int y) { |
| 729 switch (origInfo.colorType()) { |
| 730 case kUnknown_SkColorType: |
| 731 case kIndex_8_SkColorType: |
| 732 return false; |
| 733 default: |
| 734 break; |
| 735 } |
| 736 if (NULL == pixels || rowBytes < origInfo.minRowBytes()) { |
| 737 return false; |
| 738 } |
| 739 |
| 740 const SkISize size = this->getBaseLayerSize(); |
| 741 SkIRect target = SkIRect::MakeXYWH(x, y, origInfo.width(), origInfo.height()
); |
| 742 if (!target.intersect(0, 0, size.width(), size.height())) { |
| 743 return false; |
| 744 } |
| 745 |
| 746 SkBaseDevice* device = this->getDevice(); |
| 747 if (!device) { |
| 748 return false; |
| 749 } |
| 750 |
| 751 SkImageInfo info = origInfo; |
| 752 // the intersect may have shrunk info's logical size |
| 753 info.fWidth = target.width(); |
| 754 info.fHeight = target.height(); |
| 755 |
| 756 // if x or y are negative, then we have to adjust pixels |
| 757 if (x > 0) { |
| 758 x = 0; |
| 759 } |
| 760 if (y > 0) { |
| 761 y = 0; |
| 762 } |
| 763 // here x,y are either 0 or negative |
| 764 pixels = ((const char*)pixels - y * rowBytes - x * info.bytesPerPixel()); |
| 765 |
| 766 // The device can assert that the requested area is always contained in its
bounds |
| 767 return device->writePixelsDirect(info, pixels, rowBytes, target.x(), target.
y()); |
| 768 } |
712 | 769 |
713 SkCanvas* SkCanvas::canvasForDrawIter() { | 770 SkCanvas* SkCanvas::canvasForDrawIter() { |
714 return this; | 771 return this; |
715 } | 772 } |
716 | 773 |
717 ////////////////////////////////////////////////////////////////////////////// | 774 ////////////////////////////////////////////////////////////////////////////// |
718 | 775 |
719 void SkCanvas::updateDeviceCMCache() { | 776 void SkCanvas::updateDeviceCMCache() { |
720 if (fDeviceCMDirty) { | 777 if (fDeviceCMDirty) { |
721 const SkMatrix& totalMatrix = this->getTotalMatrix(); | 778 const SkMatrix& totalMatrix = this->getTotalMatrix(); |
(...skipping 1666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2388 if (!bitmap.allocPixels(info)) { | 2445 if (!bitmap.allocPixels(info)) { |
2389 return NULL; | 2446 return NULL; |
2390 } | 2447 } |
2391 | 2448 |
2392 // should this functionality be moved into allocPixels()? | 2449 // should this functionality be moved into allocPixels()? |
2393 if (!bitmap.info().isOpaque()) { | 2450 if (!bitmap.info().isOpaque()) { |
2394 bitmap.eraseColor(0); | 2451 bitmap.eraseColor(0); |
2395 } | 2452 } |
2396 return SkNEW_ARGS(SkCanvas, (bitmap)); | 2453 return SkNEW_ARGS(SkCanvas, (bitmap)); |
2397 } | 2454 } |
OLD | NEW |