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" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 SkBitmap* result, SkIPoint* offset) const { | 60 SkBitmap* result, SkIPoint* offset) const { |
61 SkRect bounds, dstRect; | 61 SkRect bounds, dstRect; |
62 fBitmap.getBounds(&bounds); | 62 fBitmap.getBounds(&bounds); |
63 ctx.ctm().mapRect(&dstRect, fDstRect); | 63 ctx.ctm().mapRect(&dstRect, fDstRect); |
64 if (fSrcRect == bounds && dstRect == bounds) { | 64 if (fSrcRect == bounds && dstRect == bounds) { |
65 // No regions cropped out or resized; return entire bitmap. | 65 // No regions cropped out or resized; return entire bitmap. |
66 *result = fBitmap; | 66 *result = fBitmap; |
67 offset->fX = offset->fY = 0; | 67 offset->fX = offset->fY = 0; |
68 return true; | 68 return true; |
69 } | 69 } |
70 SkIRect dstIRect; | |
71 dstRect.roundOut(&dstIRect); | |
72 | 70 |
| 71 const SkIRect dstIRect = dstRect.roundOut(); |
73 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(dstIRect.width(), dstI
Rect.height())); | 72 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(dstIRect.width(), dstI
Rect.height())); |
74 if (NULL == device.get()) { | 73 if (NULL == device.get()) { |
75 return false; | 74 return false; |
76 } | 75 } |
77 | 76 |
78 SkCanvas canvas(device.get()); | 77 SkCanvas canvas(device.get()); |
79 SkPaint paint; | 78 SkPaint paint; |
80 | 79 |
81 // Subtract off the integer component of the translation (will be applied in
loc, below). | 80 // Subtract off the integer component of the translation (will be applied in
loc, below). |
82 dstRect.offset(-SkIntToScalar(dstIRect.fLeft), -SkIntToScalar(dstIRect.fTop)
); | 81 dstRect.offset(-SkIntToScalar(dstIRect.fLeft), -SkIntToScalar(dstIRect.fTop)
); |
83 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 82 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
84 // FIXME: this probably shouldn't be necessary, but drawBitmapRectToRect ass
erts | 83 // FIXME: this probably shouldn't be necessary, but drawBitmapRectToRect ass
erts |
85 // None filtering when it's translate-only | 84 // None filtering when it's translate-only |
86 paint.setFilterLevel( | 85 paint.setFilterLevel( |
87 fSrcRect.width() == dstRect.width() && fSrcRect.height() == dstRect.heig
ht() ? | 86 fSrcRect.width() == dstRect.width() && fSrcRect.height() == dstRect.heig
ht() ? |
88 SkPaint::kNone_FilterLevel : SkPaint::kHigh_FilterLevel); | 87 SkPaint::kNone_FilterLevel : SkPaint::kHigh_FilterLevel); |
89 canvas.drawBitmapRectToRect(fBitmap, &fSrcRect, dstRect, &paint); | 88 canvas.drawBitmapRectToRect(fBitmap, &fSrcRect, dstRect, &paint); |
90 | 89 |
91 *result = device.get()->accessBitmap(false); | 90 *result = device.get()->accessBitmap(false); |
92 offset->fX = dstIRect.fLeft; | 91 offset->fX = dstIRect.fLeft; |
93 offset->fY = dstIRect.fTop; | 92 offset->fY = dstIRect.fTop; |
94 return true; | 93 return true; |
95 } | 94 } |
96 | 95 |
97 void SkBitmapSource::computeFastBounds(const SkRect&, SkRect* dst) const { | 96 void SkBitmapSource::computeFastBounds(const SkRect&, SkRect* dst) const { |
98 *dst = fDstRect; | 97 *dst = fDstRect; |
99 } | 98 } |
OLD | NEW |