OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2013 The Android Open Source Project | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #include "SkPictureImageFilter.h" | |
9 #include "SkDevice.h" | |
10 #include "SkCanvas.h" | |
11 #include "SkFlattenableBuffers.h" | |
12 #include "SkValidationUtils.h" | |
13 | |
14 SkPictureImageFilter::SkPictureImageFilter(SkPicture* picture) | |
15 : INHERITED(0, 0), | |
16 fPicture(picture), | |
17 fRect(SkRect::MakeWH(picture ? SkIntToScalar(picture->width()) : 0, | |
18 picture ? SkIntToScalar(picture->height()) : 0)) { | |
19 SkSafeRef(fPicture); | |
20 } | |
21 | |
22 SkPictureImageFilter::SkPictureImageFilter(SkPicture* picture, const SkRect& rec t) | |
23 : INHERITED(0, 0), | |
24 fPicture(picture), | |
25 fRect(rect) { | |
26 SkSafeRef(fPicture); | |
27 } | |
28 | |
29 SkPictureImageFilter::~SkPictureImageFilter() { | |
30 SkSafeUnref(fPicture); | |
31 } | |
32 | |
33 SkPictureImageFilter::SkPictureImageFilter(SkFlattenableReadBuffer& buffer) | |
34 : INHERITED(0, buffer) { | |
35 // FIXME: unflatten picture here. | |
reed1
2013/12/12 21:28:39
Can this be used in chrome w/o the flattening impl
Stephen White
2013/12/12 21:46:56
It works as long as there is no serialization requ
| |
36 buffer.readRect(&fRect); | |
37 } | |
38 | |
39 void SkPictureImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { | |
40 this->INHERITED::flatten(buffer); | |
41 // FIXME: flatten picture here. | |
42 buffer.writeRect(fRect); | |
43 } | |
44 | |
45 bool SkPictureImageFilter::onFilterImage(Proxy* proxy, const SkBitmap&, const Sk Matrix& matrix, | |
46 SkBitmap* result, SkIPoint* offset) { | |
47 if (!fPicture) { | |
48 return true; | |
49 } | |
50 | |
51 SkRect floatBounds; | |
52 SkIRect bounds; | |
53 matrix.mapRect(&floatBounds, fRect); | |
54 floatBounds.roundOut(&bounds); | |
55 | |
56 if (bounds.isEmpty()) { | |
57 return true; | |
58 } | |
59 | |
60 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds .height())); | |
61 if (NULL == device.get()) { | |
62 return false; | |
63 } | |
64 | |
65 SkCanvas canvas(device.get()); | |
66 SkPaint paint; | |
67 | |
68 canvas.translate(-SkIntToScalar(bounds.fLeft), -SkIntToScalar(bounds.fTop)); | |
69 canvas.concat(matrix); | |
70 canvas.drawPicture(*fPicture); | |
71 | |
72 *result = device.get()->accessBitmap(false); | |
73 offset->fX += bounds.fLeft; | |
74 offset->fY += bounds.fTop; | |
75 return true; | |
76 } | |
OLD | NEW |