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 , fFilterQuality(kHigh_SkFilterQuality) { |
| 22 } |
22 | 23 |
23 SkBitmapSource::SkBitmapSource(const SkBitmap& bitmap, const SkRect& srcRect, co
nst SkRect& dstRect) | 24 SkBitmapSource::SkBitmapSource(const SkBitmap& bitmap, |
| 25 const SkRect& srcRect, const SkRect& dstRect, |
| 26 SkFilterQuality filterQuality) |
24 : INHERITED(0, 0) | 27 : INHERITED(0, 0) |
25 , fBitmap(bitmap) | 28 , fBitmap(bitmap) |
26 , fSrcRect(srcRect) | 29 , fSrcRect(srcRect) |
27 , fDstRect(dstRect) {} | 30 , fDstRect(dstRect) |
| 31 , fFilterQuality(filterQuality) { |
| 32 } |
28 | 33 |
29 SkFlattenable* SkBitmapSource::CreateProc(SkReadBuffer& buffer) { | 34 SkFlattenable* SkBitmapSource::CreateProc(SkReadBuffer& buffer) { |
30 SkRect src, dst; | 35 SkRect src, dst; |
31 buffer.readRect(&src); | 36 buffer.readRect(&src); |
32 buffer.readRect(&dst); | 37 buffer.readRect(&dst); |
33 SkBitmap bitmap; | 38 SkBitmap bitmap; |
34 if (!buffer.readBitmap(&bitmap)) { | 39 if (!buffer.readBitmap(&bitmap)) { |
35 return NULL; | 40 return NULL; |
36 } | 41 } |
37 return SkBitmapSource::Create(bitmap, src, dst); | 42 return SkBitmapSource::Create(bitmap, src, dst); |
(...skipping 26 matching lines...) Expand all Loading... |
64 SkCanvas canvas(device.get()); | 69 SkCanvas canvas(device.get()); |
65 SkPaint paint; | 70 SkPaint paint; |
66 | 71 |
67 // Subtract off the integer component of the translation (will be applied in
loc, below). | 72 // Subtract off the integer component of the translation (will be applied in
loc, below). |
68 dstRect.offset(-SkIntToScalar(dstIRect.fLeft), -SkIntToScalar(dstIRect.fTop)
); | 73 dstRect.offset(-SkIntToScalar(dstIRect.fLeft), -SkIntToScalar(dstIRect.fTop)
); |
69 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 74 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
70 // FIXME: this probably shouldn't be necessary, but drawBitmapRectToRect ass
erts | 75 // FIXME: this probably shouldn't be necessary, but drawBitmapRectToRect ass
erts |
71 // None filtering when it's translate-only | 76 // None filtering when it's translate-only |
72 paint.setFilterQuality( | 77 paint.setFilterQuality( |
73 fSrcRect.width() == dstRect.width() && fSrcRect.height() == dstRect.heig
ht() ? | 78 fSrcRect.width() == dstRect.width() && fSrcRect.height() == dstRect.heig
ht() ? |
74 kNone_SkFilterQuality : kHigh_SkFilterQuality); | 79 kNone_SkFilterQuality : fFilterQuality); |
75 canvas.drawBitmapRectToRect(fBitmap, &fSrcRect, dstRect, &paint); | 80 canvas.drawBitmapRectToRect(fBitmap, &fSrcRect, dstRect, &paint); |
76 | 81 |
77 *result = device.get()->accessBitmap(false); | 82 *result = device.get()->accessBitmap(false); |
78 offset->fX = dstIRect.fLeft; | 83 offset->fX = dstIRect.fLeft; |
79 offset->fY = dstIRect.fTop; | 84 offset->fY = dstIRect.fTop; |
| 85 |
80 return true; | 86 return true; |
81 } | 87 } |
82 | 88 |
83 void SkBitmapSource::computeFastBounds(const SkRect&, SkRect* dst) const { | 89 void SkBitmapSource::computeFastBounds(const SkRect&, SkRect* dst) const { |
84 *dst = fDstRect; | 90 *dst = fDstRect; |
85 } | 91 } |
86 | 92 |
87 #ifndef SK_IGNORE_TO_STRING | 93 #ifndef SK_IGNORE_TO_STRING |
88 void SkBitmapSource::toString(SkString* str) const { | 94 void SkBitmapSource::toString(SkString* str) const { |
89 str->appendf("SkBitmapSource: ("); | 95 str->appendf("SkBitmapSource: ("); |
90 str->appendf("src: (%f,%f,%f,%f) dst: (%f,%f,%f,%f) ", | 96 str->appendf("src: (%f,%f,%f,%f) dst: (%f,%f,%f,%f) ", |
91 fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight, fSrcRect.fBotto
m, | 97 fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight, fSrcRect.fBotto
m, |
92 fDstRect.fLeft, fDstRect.fTop, fDstRect.fRight, fDstRect.fBotto
m); | 98 fDstRect.fLeft, fDstRect.fTop, fDstRect.fRight, fDstRect.fBotto
m); |
93 str->appendf("bitmap: (%d,%d)", | 99 str->appendf("bitmap: (%d,%d)", |
94 fBitmap.width(), fBitmap.height()); | 100 fBitmap.width(), fBitmap.height()); |
95 str->append(")"); | 101 str->append(")"); |
96 } | 102 } |
97 #endif | 103 #endif |
OLD | NEW |