Chromium Code Reviews| 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 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 660 } | 660 } |
| 661 // now jam our 1st clip to be bounds, and intersect the rest with that | 661 // now jam our 1st clip to be bounds, and intersect the rest with that |
| 662 rec->fRasterClip->setRect(bounds); | 662 rec->fRasterClip->setRect(bounds); |
| 663 while ((rec = (MCRec*)iter.next()) != NULL) { | 663 while ((rec = (MCRec*)iter.next()) != NULL) { |
| 664 (void)rec->fRasterClip->op(bounds, SkRegion::kIntersect_Op); | 664 (void)rec->fRasterClip->op(bounds, SkRegion::kIntersect_Op); |
| 665 } | 665 } |
| 666 | 666 |
| 667 return device; | 667 return device; |
| 668 } | 668 } |
| 669 | 669 |
| 670 #ifdef SK_SUPPORT_LEGACY_READPIXELSCONFIG | |
| 670 bool SkCanvas::readPixels(SkBitmap* bitmap, | 671 bool SkCanvas::readPixels(SkBitmap* bitmap, |
| 671 int x, int y, | 672 int x, int y, |
| 672 Config8888 config8888) { | 673 Config8888 config8888) { |
| 673 SkBaseDevice* device = this->getDevice(); | 674 SkBaseDevice* device = this->getDevice(); |
| 674 if (!device) { | 675 if (!device) { |
| 675 return false; | 676 return false; |
| 676 } | 677 } |
| 677 return device->readPixels(bitmap, x, y, config8888); | 678 return device->readPixels(bitmap, x, y, config8888); |
| 678 } | 679 } |
| 680 #endif | |
| 681 | |
| 682 bool SkCanvas::readPixels(SkBitmap* bitmap, int x, int y) { | |
| 683 if (kUnknown_SkColorType == bitmap->colorType() || bitmap->getTexture()) { | |
| 684 return false; | |
| 685 } | |
| 686 | |
| 687 bool weAllocated = false; | |
| 688 if (NULL == bitmap->pixelRef()) { | |
| 689 if (!bitmap->allocPixels()) { | |
| 690 return false; | |
| 691 } | |
| 692 weAllocated = true; | |
| 693 } | |
| 694 | |
| 695 SkBitmap bm(*bitmap); | |
| 696 bm.lockPixels(); | |
| 697 if (bm.getPixels() && this->readPixels(bm.info(), bm.getPixels(), bm.rowByte s(), x, y)) { | |
| 698 return true; | |
| 699 } | |
| 700 | |
| 701 if (weAllocated) { | |
| 702 bitmap->setPixelRef(NULL); | |
| 703 } | |
| 704 return false; | |
| 705 } | |
| 679 | 706 |
| 680 bool SkCanvas::readPixels(const SkIRect& srcRect, SkBitmap* bitmap) { | 707 bool SkCanvas::readPixels(const SkIRect& srcRect, SkBitmap* bitmap) { |
| 708 SkIRect r = srcRect; | |
| 709 const SkISize size = this->getBaseLayerSize(); | |
| 710 if (!r.intersect(0, 0, size.width(), size.height())) { | |
| 711 bitmap->reset(); | |
| 712 return false; | |
| 713 } | |
| 714 | |
| 715 if (!bitmap->allocN32Pixels(r.width(), r.height())) { | |
| 716 // bitmap will already be reset. | |
| 717 return false; | |
| 718 } | |
| 719 if (!this->readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowBytes( ), r.x(), r.y())) { | |
| 720 bitmap->reset(); | |
| 721 return false; | |
| 722 } | |
| 723 return true; | |
| 724 } | |
| 725 | |
| 726 bool SkCanvas::readPixels(const SkImageInfo& origInfo, void* dstP, size_t rowByt es, int x, int y) { | |
| 727 switch (origInfo.colorType()) { | |
| 728 case kUnknown_SkColorType: | |
| 729 case kIndex_8_SkColorType: | |
| 730 return false; | |
| 731 default: | |
| 732 break; | |
| 733 } | |
| 734 if (NULL == dstP || rowBytes < origInfo.minRowBytes()) { | |
| 735 return false; | |
| 736 } | |
| 737 if (0 == origInfo.width() || 0 == origInfo.height()) { | |
| 738 return false; | |
| 739 } | |
| 740 | |
| 681 SkBaseDevice* device = this->getDevice(); | 741 SkBaseDevice* device = this->getDevice(); |
| 682 if (!device) { | 742 if (!device) { |
| 683 return false; | 743 return false; |
| 684 } | 744 } |
| 685 | 745 |
| 686 SkIRect bounds; | 746 const SkISize size = this->getBaseLayerSize(); |
| 687 bounds.set(0, 0, device->width(), device->height()); | 747 SkIRect srcR = SkIRect::MakeXYWH(x, y, origInfo.width(), origInfo.height()); |
| 688 if (!bounds.intersect(srcRect)) { | 748 if (!srcR.intersect(0, 0, size.width(), size.height())) { |
| 689 return false; | 749 return false; |
| 690 } | 750 } |
| 691 | 751 |
| 692 SkBitmap tmp; | 752 SkImageInfo info = origInfo; |
| 693 tmp.setConfig(SkBitmap::kARGB_8888_Config, bounds.width(), | 753 // the intersect may have shrunk info's logical size |
| 694 bounds.height()); | 754 info.fWidth = srcR.width(); |
| 695 if (this->readPixels(&tmp, bounds.fLeft, bounds.fTop)) { | 755 info.fHeight = srcR.height(); |
| 696 bitmap->swap(tmp); | 756 |
| 697 return true; | 757 // if x or y are negative, then we have to adjust pixels |
| 698 } else { | 758 if (x > 0) { |
| 699 return false; | 759 x = 0; |
| 700 } | 760 } |
| 761 if (y > 0) { | |
| 762 y = 0; | |
| 763 } | |
| 764 // here x,y are either 0 or negative | |
|
scroggo
2014/03/24 15:31:36
What's the use case for calling this function with
reed1
2014/03/24 15:53:05
We definitely support (in the public canvas versio
| |
| 765 dstP = ((char*)dstP - y * rowBytes - x * info.bytesPerPixel()); | |
| 766 | |
| 767 // The device can assert that the requested area is always contained in its bounds | |
| 768 return device->readPixels(info, dstP, rowBytes, srcR.x(), srcR.y()); | |
| 701 } | 769 } |
| 702 | 770 |
| 703 bool SkCanvas::writePixels(const SkBitmap& bitmap, int x, int y) { | 771 bool SkCanvas::writePixels(const SkBitmap& bitmap, int x, int y) { |
| 704 if (bitmap.getTexture()) { | 772 if (bitmap.getTexture()) { |
| 705 return false; | 773 return false; |
| 706 } | 774 } |
| 707 SkBitmap bm(bitmap); | 775 SkBitmap bm(bitmap); |
| 708 bm.lockPixels(); | 776 bm.lockPixels(); |
| 709 if (bm.getPixels()) { | 777 if (bm.getPixels()) { |
| 710 return this->writePixels(bm.info(), bm.getPixels(), bm.rowBytes(), x, y) ; | 778 return this->writePixels(bm.info(), bm.getPixels(), bm.rowBytes(), x, y) ; |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1056 | 1124 |
| 1057 void* SkCanvas::onAccessTopLayerPixels(SkImageInfo* info, size_t* rowBytes) { | 1125 void* SkCanvas::onAccessTopLayerPixels(SkImageInfo* info, size_t* rowBytes) { |
| 1058 SkBaseDevice* dev = this->getTopDevice(); | 1126 SkBaseDevice* dev = this->getTopDevice(); |
| 1059 return dev ? dev->accessPixels(info, rowBytes) : NULL; | 1127 return dev ? dev->accessPixels(info, rowBytes) : NULL; |
| 1060 } | 1128 } |
| 1061 | 1129 |
| 1062 SkAutoROCanvasPixels::SkAutoROCanvasPixels(SkCanvas* canvas) { | 1130 SkAutoROCanvasPixels::SkAutoROCanvasPixels(SkCanvas* canvas) { |
| 1063 fAddr = canvas->peekPixels(&fInfo, &fRowBytes); | 1131 fAddr = canvas->peekPixels(&fInfo, &fRowBytes); |
| 1064 if (NULL == fAddr) { | 1132 if (NULL == fAddr) { |
| 1065 fInfo = canvas->imageInfo(); | 1133 fInfo = canvas->imageInfo(); |
| 1066 if (kUnknown_SkColorType == fInfo.colorType() || | 1134 if (kUnknown_SkColorType == fInfo.colorType() || !fBitmap.allocPixels(fI nfo)) { |
| 1067 !fBitmap.allocPixels(fInfo)) | |
| 1068 { | |
| 1069 return; // failure, fAddr is NULL | 1135 return; // failure, fAddr is NULL |
| 1070 } | 1136 } |
| 1071 fBitmap.lockPixels(); | |
| 1072 if (!canvas->readPixels(&fBitmap, 0, 0)) { | 1137 if (!canvas->readPixels(&fBitmap, 0, 0)) { |
| 1073 return; // failure, fAddr is NULL | 1138 return; // failure, fAddr is NULL |
| 1074 } | 1139 } |
| 1075 fAddr = fBitmap.getPixels(); | 1140 fAddr = fBitmap.getPixels(); |
| 1076 fRowBytes = fBitmap.rowBytes(); | 1141 fRowBytes = fBitmap.rowBytes(); |
| 1077 } | 1142 } |
| 1078 SkASSERT(fAddr); // success | 1143 SkASSERT(fAddr); // success |
| 1079 } | 1144 } |
| 1080 | 1145 |
| 1081 bool SkAutoROCanvasPixels::asROBitmap(SkBitmap* bitmap) const { | 1146 bool SkAutoROCanvasPixels::asROBitmap(SkBitmap* bitmap) const { |
| (...skipping 1478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2560 if (!bitmap.installPixels(info, pixels, rowBytes)) { | 2625 if (!bitmap.installPixels(info, pixels, rowBytes)) { |
| 2561 return NULL; | 2626 return NULL; |
| 2562 } | 2627 } |
| 2563 | 2628 |
| 2564 // should this functionality be moved into allocPixels()? | 2629 // should this functionality be moved into allocPixels()? |
| 2565 if (!bitmap.info().isOpaque()) { | 2630 if (!bitmap.info().isOpaque()) { |
| 2566 bitmap.eraseColor(0); | 2631 bitmap.eraseColor(0); |
| 2567 } | 2632 } |
| 2568 return SkNEW_ARGS(SkCanvas, (bitmap)); | 2633 return SkNEW_ARGS(SkCanvas, (bitmap)); |
| 2569 } | 2634 } |
| OLD | NEW |