| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 The Android Open Source Project | 2 * Copyright 2012 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 "SkBitmapSource.h" | 8 #include "SkBitmapSource.h" |
| 9 #include "SkDevice.h" | 9 #include "SkDevice.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| 11 #include "SkReadBuffer.h" | 11 #include "SkReadBuffer.h" |
| 12 #include "SkWriteBuffer.h" | 12 #include "SkWriteBuffer.h" |
| 13 #include "SkValidationUtils.h" | 13 #include "SkValidationUtils.h" |
| 14 | 14 |
| 15 SkBitmapSource::SkBitmapSource(const SkBitmap& bitmap) | 15 SkBitmapSource::SkBitmapSource(const SkBitmap& bitmap) |
| 16 : INHERITED(0, 0), | 16 : INHERITED(0, 0), |
| 17 fBitmap(bitmap), | 17 fBitmap(bitmap), |
| 18 fSrcRect(SkRect::MakeWH(SkIntToScalar(bitmap.width()), | 18 fSrcRect(SkRect::MakeWH(SkIntToScalar(bitmap.width()), |
| 19 SkIntToScalar(bitmap.height()))), | 19 SkIntToScalar(bitmap.height()))), |
| 20 fDstRect(fSrcRect) { | 20 fDstRect(fSrcRect) { |
| 21 } | 21 } |
| 22 | 22 |
| 23 SkBitmapSource::SkBitmapSource(const SkBitmap& bitmap, const SkRect& srcRect, co
nst SkRect& dstRect) | 23 SkBitmapSource::SkBitmapSource(const SkBitmap& bitmap, const SkRect& srcRect, co
nst SkRect& dstRect) |
| 24 : INHERITED(0, 0), | 24 : INHERITED(0, 0) |
| 25 fBitmap(bitmap), | 25 , fBitmap(bitmap) |
| 26 fSrcRect(srcRect), | 26 , fSrcRect(srcRect) |
| 27 fDstRect(dstRect) { | 27 , fDstRect(dstRect) {} |
| 28 } | |
| 29 | 28 |
| 30 SkBitmapSource::SkBitmapSource(SkReadBuffer& buffer) | 29 SkBitmapSource::SkBitmapSource(SkReadBuffer& buffer) : INHERITED(0, buffer) { |
| 31 : INHERITED(0, buffer) { | 30 if (buffer.isVersionLT(SkReadBuffer::kNoMoreBitmapFlatten_Version)) { |
| 32 fBitmap.unflatten(buffer); | 31 fBitmap.unflatten(buffer); |
| 32 } else { |
| 33 buffer.readBitmap(&fBitmap); |
| 34 } |
| 33 buffer.readRect(&fSrcRect); | 35 buffer.readRect(&fSrcRect); |
| 34 buffer.readRect(&fDstRect); | 36 buffer.readRect(&fDstRect); |
| 35 buffer.validate(buffer.isValid() && SkIsValidRect(fSrcRect) && SkIsValidRect
(fDstRect)); | 37 buffer.validate(buffer.isValid() && SkIsValidRect(fSrcRect) && SkIsValidRect
(fDstRect)); |
| 36 } | 38 } |
| 37 | 39 |
| 38 void SkBitmapSource::flatten(SkWriteBuffer& buffer) const { | 40 void SkBitmapSource::flatten(SkWriteBuffer& buffer) const { |
| 39 this->INHERITED::flatten(buffer); | 41 this->INHERITED::flatten(buffer); |
| 40 fBitmap.flatten(buffer); | 42 buffer.writeBitmap(fBitmap); |
| 41 buffer.writeRect(fSrcRect); | 43 buffer.writeRect(fSrcRect); |
| 42 buffer.writeRect(fDstRect); | 44 buffer.writeRect(fDstRect); |
| 43 } | 45 } |
| 44 | 46 |
| 45 bool SkBitmapSource::onFilterImage(Proxy* proxy, const SkBitmap&, const Context&
ctx, | 47 bool SkBitmapSource::onFilterImage(Proxy* proxy, const SkBitmap&, const Context&
ctx, |
| 46 SkBitmap* result, SkIPoint* offset) const { | 48 SkBitmap* result, SkIPoint* offset) const { |
| 47 SkRect bounds, dstRect; | 49 SkRect bounds, dstRect; |
| 48 fBitmap.getBounds(&bounds); | 50 fBitmap.getBounds(&bounds); |
| 49 ctx.ctm().mapRect(&dstRect, fDstRect); | 51 ctx.ctm().mapRect(&dstRect, fDstRect); |
| 50 if (fSrcRect == bounds && dstRect == bounds) { | 52 if (fSrcRect == bounds && dstRect == bounds) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 84 |
| 83 void SkBitmapSource::computeFastBounds(const SkRect&, SkRect* dst) const { | 85 void SkBitmapSource::computeFastBounds(const SkRect&, SkRect* dst) const { |
| 84 *dst = fDstRect; | 86 *dst = fDstRect; |
| 85 } | 87 } |
| 86 | 88 |
| 87 bool SkBitmapSource::onFilterBounds(const SkIRect& src, const SkMatrix& ctm, | 89 bool SkBitmapSource::onFilterBounds(const SkIRect& src, const SkMatrix& ctm, |
| 88 SkIRect* dst) const { | 90 SkIRect* dst) const { |
| 89 *dst = src; | 91 *dst = src; |
| 90 return true; | 92 return true; |
| 91 } | 93 } |
| OLD | NEW |