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 25 matching lines...) Expand all Loading... |
36 if (buffer.isVersionLT(SkReadBuffer::kBitmapSourceFilterQuality_Version)) { | 36 if (buffer.isVersionLT(SkReadBuffer::kBitmapSourceFilterQuality_Version)) { |
37 filterQuality = kHigh_SkFilterQuality; | 37 filterQuality = kHigh_SkFilterQuality; |
38 } else { | 38 } else { |
39 filterQuality = (SkFilterQuality)buffer.readInt(); | 39 filterQuality = (SkFilterQuality)buffer.readInt(); |
40 } | 40 } |
41 SkRect src, dst; | 41 SkRect src, dst; |
42 buffer.readRect(&src); | 42 buffer.readRect(&src); |
43 buffer.readRect(&dst); | 43 buffer.readRect(&dst); |
44 SkBitmap bitmap; | 44 SkBitmap bitmap; |
45 if (!buffer.readBitmap(&bitmap)) { | 45 if (!buffer.readBitmap(&bitmap)) { |
46 return NULL; | 46 return nullptr; |
47 } | 47 } |
48 return SkBitmapSource::Create(bitmap, src, dst, filterQuality); | 48 return SkBitmapSource::Create(bitmap, src, dst, filterQuality); |
49 } | 49 } |
50 | 50 |
51 void SkBitmapSource::flatten(SkWriteBuffer& buffer) const { | 51 void SkBitmapSource::flatten(SkWriteBuffer& buffer) const { |
52 buffer.writeInt(fFilterQuality); | 52 buffer.writeInt(fFilterQuality); |
53 buffer.writeRect(fSrcRect); | 53 buffer.writeRect(fSrcRect); |
54 buffer.writeRect(fDstRect); | 54 buffer.writeRect(fDstRect); |
55 buffer.writeBitmap(fBitmap); | 55 buffer.writeBitmap(fBitmap); |
56 } | 56 } |
57 | 57 |
58 bool SkBitmapSource::onFilterImage(Proxy* proxy, const SkBitmap&, const Context&
ctx, | 58 bool SkBitmapSource::onFilterImage(Proxy* proxy, const SkBitmap&, const Context&
ctx, |
59 SkBitmap* result, SkIPoint* offset) const { | 59 SkBitmap* result, SkIPoint* offset) const { |
60 SkRect bounds, dstRect; | 60 SkRect bounds, dstRect; |
61 fBitmap.getBounds(&bounds); | 61 fBitmap.getBounds(&bounds); |
62 ctx.ctm().mapRect(&dstRect, fDstRect); | 62 ctx.ctm().mapRect(&dstRect, fDstRect); |
63 if (fSrcRect == bounds && dstRect == bounds) { | 63 if (fSrcRect == bounds && dstRect == bounds) { |
64 // No regions cropped out or resized; return entire bitmap. | 64 // No regions cropped out or resized; return entire bitmap. |
65 *result = fBitmap; | 65 *result = fBitmap; |
66 offset->fX = offset->fY = 0; | 66 offset->fX = offset->fY = 0; |
67 return true; | 67 return true; |
68 } | 68 } |
69 | 69 |
70 const SkIRect dstIRect = dstRect.roundOut(); | 70 const SkIRect dstIRect = dstRect.roundOut(); |
71 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(dstIRect.width(), dstI
Rect.height())); | 71 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(dstIRect.width(), dstI
Rect.height())); |
72 if (NULL == device.get()) { | 72 if (nullptr == device.get()) { |
73 return false; | 73 return false; |
74 } | 74 } |
75 | 75 |
76 SkCanvas canvas(device.get()); | 76 SkCanvas canvas(device.get()); |
77 SkPaint paint; | 77 SkPaint paint; |
78 | 78 |
79 // Subtract off the integer component of the translation (will be applied in
loc, below). | 79 // Subtract off the integer component of the translation (will be applied in
loc, below). |
80 dstRect.offset(-SkIntToScalar(dstIRect.fLeft), -SkIntToScalar(dstIRect.fTop)
); | 80 dstRect.offset(-SkIntToScalar(dstIRect.fLeft), -SkIntToScalar(dstIRect.fTop)
); |
81 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 81 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
82 // FIXME: this probably shouldn't be necessary, but drawBitmapRect asserts | 82 // FIXME: this probably shouldn't be necessary, but drawBitmapRect asserts |
(...skipping 18 matching lines...) Expand all Loading... |
101 void SkBitmapSource::toString(SkString* str) const { | 101 void SkBitmapSource::toString(SkString* str) const { |
102 str->appendf("SkBitmapSource: ("); | 102 str->appendf("SkBitmapSource: ("); |
103 str->appendf("src: (%f,%f,%f,%f) dst: (%f,%f,%f,%f) ", | 103 str->appendf("src: (%f,%f,%f,%f) dst: (%f,%f,%f,%f) ", |
104 fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight, fSrcRect.fBotto
m, | 104 fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.fRight, fSrcRect.fBotto
m, |
105 fDstRect.fLeft, fDstRect.fTop, fDstRect.fRight, fDstRect.fBotto
m); | 105 fDstRect.fLeft, fDstRect.fTop, fDstRect.fRight, fDstRect.fBotto
m); |
106 str->appendf("bitmap: (%d,%d)", | 106 str->appendf("bitmap: (%d,%d)", |
107 fBitmap.width(), fBitmap.height()); | 107 fBitmap.width(), fBitmap.height()); |
108 str->append(")"); | 108 str->append(")"); |
109 } | 109 } |
110 #endif | 110 #endif |
OLD | NEW |