| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2008 The Android Open Source Project | 2 * Copyright 2008 The Android Open Source Project |
| 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 "SkCanvas.h" | 8 #include "SkCanvas.h" |
| 9 #include "SkCanvasDrawable.h" | 9 #include "SkCanvasDrawable.h" |
| 10 #include "SkCanvasPriv.h" | 10 #include "SkCanvasPriv.h" |
| 11 #include "SkBitmapDevice.h" | 11 #include "SkBitmapDevice.h" |
| 12 #include "SkDeviceImageFilterProxy.h" | 12 #include "SkDeviceImageFilterProxy.h" |
| 13 #include "SkDraw.h" | 13 #include "SkDraw.h" |
| 14 #include "SkDrawFilter.h" | 14 #include "SkDrawFilter.h" |
| 15 #include "SkDrawLooper.h" | 15 #include "SkDrawLooper.h" |
| 16 #include "SkImage.h" | 16 #include "SkImage.h" |
| 17 #include "SkMetaData.h" | 17 #include "SkMetaData.h" |
| 18 #include "SkPathOps.h" | 18 #include "SkPathOps.h" |
| 19 #include "SkPatchUtils.h" | 19 #include "SkPatchUtils.h" |
| 20 #include "SkPicture.h" | 20 #include "SkPicture.h" |
| 21 #include "SkRasterClip.h" | 21 #include "SkRasterClip.h" |
| 22 #include "SkReadPixelsRec.h" |
| 22 #include "SkRRect.h" | 23 #include "SkRRect.h" |
| 23 #include "SkSmallAllocator.h" | 24 #include "SkSmallAllocator.h" |
| 24 #include "SkSurface_Base.h" | 25 #include "SkSurface_Base.h" |
| 25 #include "SkTemplates.h" | 26 #include "SkTemplates.h" |
| 26 #include "SkTextBlob.h" | 27 #include "SkTextBlob.h" |
| 27 #include "SkTextFormatParams.h" | 28 #include "SkTextFormatParams.h" |
| 28 #include "SkTLazy.h" | 29 #include "SkTLazy.h" |
| 29 #include "SkTraceEvent.h" | 30 #include "SkTraceEvent.h" |
| 30 #include "SkUtils.h" | 31 #include "SkUtils.h" |
| 31 | 32 |
| (...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 // bitmap will already be reset. | 680 // bitmap will already be reset. |
| 680 return false; | 681 return false; |
| 681 } | 682 } |
| 682 if (!this->readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowBytes(
), r.x(), r.y())) { | 683 if (!this->readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowBytes(
), r.x(), r.y())) { |
| 683 bitmap->reset(); | 684 bitmap->reset(); |
| 684 return false; | 685 return false; |
| 685 } | 686 } |
| 686 return true; | 687 return true; |
| 687 } | 688 } |
| 688 | 689 |
| 689 bool SkCanvas::readPixels(const SkImageInfo& origInfo, void* dstP, size_t rowByt
es, int x, int y) { | 690 bool SkCanvas::readPixels(const SkImageInfo& dstInfo, void* dstP, size_t rowByte
s, int x, int y) { |
| 690 switch (origInfo.colorType()) { | |
| 691 case kUnknown_SkColorType: | |
| 692 case kIndex_8_SkColorType: | |
| 693 return false; | |
| 694 default: | |
| 695 break; | |
| 696 } | |
| 697 if (NULL == dstP || rowBytes < origInfo.minRowBytes()) { | |
| 698 return false; | |
| 699 } | |
| 700 if (0 == origInfo.width() || 0 == origInfo.height()) { | |
| 701 return false; | |
| 702 } | |
| 703 | |
| 704 SkBaseDevice* device = this->getDevice(); | 691 SkBaseDevice* device = this->getDevice(); |
| 705 if (!device) { | 692 if (!device) { |
| 706 return false; | 693 return false; |
| 707 } | 694 } |
| 708 | |
| 709 const SkISize size = this->getBaseLayerSize(); | 695 const SkISize size = this->getBaseLayerSize(); |
| 710 SkIRect srcR = SkIRect::MakeXYWH(x, y, origInfo.width(), origInfo.height()); | 696 |
| 711 if (!srcR.intersect(0, 0, size.width(), size.height())) { | 697 SkReadPixelsRec rec(dstInfo, dstP, rowBytes, x, y); |
| 698 if (!rec.trim(size.width(), size.height())) { |
| 712 return false; | 699 return false; |
| 713 } | 700 } |
| 714 | 701 |
| 715 // the intersect may have shrunk info's logical size | |
| 716 const SkImageInfo info = origInfo.makeWH(srcR.width(), srcR.height()); | |
| 717 | |
| 718 // if x or y are negative, then we have to adjust pixels | |
| 719 if (x > 0) { | |
| 720 x = 0; | |
| 721 } | |
| 722 if (y > 0) { | |
| 723 y = 0; | |
| 724 } | |
| 725 // here x,y are either 0 or negative | |
| 726 dstP = ((char*)dstP - y * rowBytes - x * info.bytesPerPixel()); | |
| 727 | |
| 728 // The device can assert that the requested area is always contained in its
bounds | 702 // The device can assert that the requested area is always contained in its
bounds |
| 729 return device->readPixels(info, dstP, rowBytes, srcR.x(), srcR.y()); | 703 return device->readPixels(rec.fInfo, rec.fPixels, rec.fRowBytes, rec.fX, rec
.fY); |
| 730 } | 704 } |
| 731 | 705 |
| 732 bool SkCanvas::writePixels(const SkBitmap& bitmap, int x, int y) { | 706 bool SkCanvas::writePixels(const SkBitmap& bitmap, int x, int y) { |
| 733 if (bitmap.getTexture()) { | 707 if (bitmap.getTexture()) { |
| 734 return false; | 708 return false; |
| 735 } | 709 } |
| 736 SkBitmap bm(bitmap); | 710 SkBitmap bm(bitmap); |
| 737 bm.lockPixels(); | 711 bm.lockPixels(); |
| 738 if (bm.getPixels()) { | 712 if (bm.getPixels()) { |
| 739 return this->writePixels(bm.info(), bm.getPixels(), bm.rowBytes(), x, y)
; | 713 return this->writePixels(bm.info(), bm.getPixels(), bm.rowBytes(), x, y)
; |
| (...skipping 1836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2576 } | 2550 } |
| 2577 | 2551 |
| 2578 if (matrix) { | 2552 if (matrix) { |
| 2579 canvas->concat(*matrix); | 2553 canvas->concat(*matrix); |
| 2580 } | 2554 } |
| 2581 } | 2555 } |
| 2582 | 2556 |
| 2583 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { | 2557 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
| 2584 fCanvas->restoreToCount(fSaveCount); | 2558 fCanvas->restoreToCount(fSaveCount); |
| 2585 } | 2559 } |
| OLD | NEW |