Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: src/effects/SkPictureImageFilter.cpp

Issue 753073010: Adding a PictureResolution option to SkPictureImageFilter (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2013 The Android Open Source Project 2 * Copyright 2013 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 "SkPictureImageFilter.h" 8 #include "SkPictureImageFilter.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 "SkSurfaceProps.h" 12 #include "SkSurfaceProps.h"
13 #include "SkWriteBuffer.h" 13 #include "SkWriteBuffer.h"
14 #include "SkValidationUtils.h" 14 #include "SkValidationUtils.h"
15 15
16 SkPictureImageFilter::SkPictureImageFilter(const SkPicture* picture, uint32_t un iqueID) 16 SkPictureImageFilter::SkPictureImageFilter(const SkPicture* picture, uint32_t un iqueID,
17 PictureResolution pictureResolution,
18 SkPaint::FilterLevel filterLevel)
17 : INHERITED(0, 0, NULL, uniqueID) 19 : INHERITED(0, 0, NULL, uniqueID)
18 , fPicture(SkSafeRef(picture)) 20 , fPicture(SkSafeRef(picture))
19 , fCropRect(picture ? picture->cullRect() : SkRect::MakeEmpty()) { 21 , fCropRect(picture ? picture->cullRect() : SkRect::MakeEmpty())
22 , fFilterLevel(filterLevel)
23 , fPictureResolution(pictureResolution) {
20 } 24 }
21 25
22 SkPictureImageFilter::SkPictureImageFilter(const SkPicture* picture, const SkRec t& cropRect, 26 SkPictureImageFilter::SkPictureImageFilter(const SkPicture* picture, const SkRec t& cropRect,
23 uint32_t uniqueID) 27 uint32_t uniqueID, PictureResolution pictureResolution,
28 SkPaint::FilterLevel filterLevel)
24 : INHERITED(0, 0, NULL, uniqueID) 29 : INHERITED(0, 0, NULL, uniqueID)
25 , fPicture(SkSafeRef(picture)) 30 , fPicture(SkSafeRef(picture))
26 , fCropRect(cropRect) { 31 , fCropRect(cropRect)
32 , fFilterLevel(filterLevel)
33 , fPictureResolution(pictureResolution) {
27 } 34 }
28 35
29 SkPictureImageFilter::~SkPictureImageFilter() { 36 SkPictureImageFilter::~SkPictureImageFilter() {
30 SkSafeUnref(fPicture); 37 SkSafeUnref(fPicture);
31 } 38 }
32 39
33 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING 40 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
34 SkPictureImageFilter::SkPictureImageFilter(SkReadBuffer& buffer) 41 SkPictureImageFilter::SkPictureImageFilter(SkReadBuffer& buffer)
35 : INHERITED(0, buffer), 42 : INHERITED(0, buffer),
36 fPicture(NULL) { 43 fPicture(NULL) {
37 if (!buffer.isCrossProcess()) { 44 if (!buffer.isCrossProcess()) {
38 if (buffer.readBool()) { 45 if (buffer.readBool()) {
39 fPicture = SkPicture::CreateFromBuffer(buffer); 46 fPicture = SkPicture::CreateFromBuffer(buffer);
40 } 47 }
41 } else { 48 } else {
42 buffer.validate(!buffer.readBool()); 49 buffer.validate(!buffer.readBool());
43 } 50 }
44 buffer.readRect(&fCropRect); 51 buffer.readRect(&fCropRect);
52 if (buffer.isVersionLT(SkReadBuffer::kPictureImageFilterResolution_Version)) {
53 fFilterLevel = SkPaint::kLow_FilterLevel;
54 fPictureResolution = kDeviceSpace_PictureResolution;
55 } else {
56 fFilterLevel = (SkPaint::FilterLevel)buffer.readInt();
57 fPictureResolution = (PictureResolution)buffer.readInt();
58 }
45 } 59 }
46 #endif 60 #endif
47 61
48 SkFlattenable* SkPictureImageFilter::CreateProc(SkReadBuffer& buffer) { 62 SkFlattenable* SkPictureImageFilter::CreateProc(SkReadBuffer& buffer) {
49 SkAutoTUnref<SkPicture> picture; 63 SkAutoTUnref<SkPicture> picture;
50 SkRect cropRect; 64 SkRect cropRect;
51 65
52 if (!buffer.isCrossProcess()) { 66 if (!buffer.isCrossProcess()) {
53 if (buffer.readBool()) { 67 if (buffer.readBool()) {
54 picture.reset(SkPicture::CreateFromBuffer(buffer)); 68 picture.reset(SkPicture::CreateFromBuffer(buffer));
55 } 69 }
56 } else { 70 } else {
57 buffer.validate(!buffer.readBool()); 71 buffer.validate(!buffer.readBool());
58 } 72 }
59 buffer.readRect(&cropRect); 73 buffer.readRect(&cropRect);
74 SkPaint::FilterLevel filterLevel;
75 PictureResolution pictureResolution;
76 if (buffer.isVersionLT(SkReadBuffer::kPictureImageFilterResolution_Version)) {
77 filterLevel = SkPaint::kLow_FilterLevel;
78 pictureResolution = kDeviceSpace_PictureResolution;
79 } else {
80 filterLevel = (SkPaint::FilterLevel)buffer.readInt();
81 pictureResolution = (PictureResolution)buffer.readInt();
82 }
60 83
61 return Create(picture, cropRect); 84 return Create(picture, cropRect, 0, pictureResolution, filterLevel);
62 } 85 }
63 86
64 void SkPictureImageFilter::flatten(SkWriteBuffer& buffer) const { 87 void SkPictureImageFilter::flatten(SkWriteBuffer& buffer) const {
65 if (!buffer.isCrossProcess()) { 88 if (!buffer.isCrossProcess()) {
66 bool hasPicture = (fPicture != NULL); 89 bool hasPicture = (fPicture != NULL);
67 buffer.writeBool(hasPicture); 90 buffer.writeBool(hasPicture);
68 if (hasPicture) { 91 if (hasPicture) {
69 fPicture->flatten(buffer); 92 fPicture->flatten(buffer);
70 } 93 }
71 } else { 94 } else {
72 buffer.writeBool(false); 95 buffer.writeBool(false);
73 } 96 }
74 buffer.writeRect(fCropRect); 97 buffer.writeRect(fCropRect);
98 buffer.writeInt(fFilterLevel);
99 buffer.writeInt(fPictureResolution);
75 } 100 }
76 101
77 bool SkPictureImageFilter::onFilterImage(Proxy* proxy, const SkBitmap&, const Co ntext& ctx, 102 bool SkPictureImageFilter::onFilterImage(Proxy* proxy, const SkBitmap&, const Co ntext& ctx,
78 SkBitmap* result, SkIPoint* offset) con st { 103 SkBitmap* result, SkIPoint* offset) con st {
79 if (!fPicture) { 104 if (!fPicture) {
80 offset->fX = offset->fY = 0; 105 offset->fX = offset->fY = 0;
81 return true; 106 return true;
82 } 107 }
83 108
84 SkRect floatBounds; 109 SkRect floatBounds;
85 ctx.ctm().mapRect(&floatBounds, fCropRect); 110 ctx.ctm().mapRect(&floatBounds, fCropRect);
86 SkIRect bounds = floatBounds.roundOut(); 111 SkIRect bounds = floatBounds.roundOut();
87 if (!bounds.intersect(ctx.clipBounds())) { 112 if (!bounds.intersect(ctx.clipBounds())) {
88 return false; 113 return false;
89 } 114 }
90 115
91 if (bounds.isEmpty()) { 116 if (bounds.isEmpty()) {
92 offset->fX = offset->fY = 0; 117 offset->fX = offset->fY = 0;
93 return true; 118 return true;
94 } 119 }
95 120
96 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds .height())); 121 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds .height()));
97 if (NULL == device.get()) { 122 if (NULL == device.get()) {
98 return false; 123 return false;
99 } 124 }
100 125
101 // Pass explicit surface props, as the simplified canvas constructor discard s device properties. 126 if (kLocalSpace_PictureResolution == fPictureResolution &&
102 // FIXME: switch back to the public constructor (and unfriend) after 127 (ctx.ctm().getType() & ~SkMatrix::kTranslate_Mask)) {
103 // https://code.google.com/p/skia/issues/detail?id=3142 is fixed. 128 drawPictureAtOriginalResolution(proxy, device.get(), bounds, ctx);
104 SkCanvas canvas(device.get(), proxy->surfaceProps(), SkCanvas::kDefault_Init Flags); 129 } else {
105 130 drawPictureAtNativeResolution(proxy, device.get(), bounds, ctx);
106 canvas.translate(-SkIntToScalar(bounds.fLeft), -SkIntToScalar(bounds.fTop)); 131 }
107 canvas.concat(ctx.ctm());
108 canvas.drawPicture(fPicture);
109 132
110 *result = device.get()->accessBitmap(false); 133 *result = device.get()->accessBitmap(false);
111 offset->fX = bounds.fLeft; 134 offset->fX = bounds.fLeft;
112 offset->fY = bounds.fTop; 135 offset->fY = bounds.fTop;
113 return true; 136 return true;
114 } 137 }
138
139 void SkPictureImageFilter::drawPictureAtNativeResolution(Proxy* proxy, SkBaseDev ice* device,
140 const SkIRect& deviceBou nds,
141 const Context& ctx) cons t {
142 // Pass explicit surface props, as the simplified canvas constructor discard s device properties.
143 // FIXME: switch back to the public constructor (and unfriend) after
144 // https://code.google.com/p/skia/issues/detail?id=3142 is fixed.
145 SkCanvas canvas(device, proxy->surfaceProps(), SkCanvas::kDefault_InitFlags) ;
146
147 canvas.translate(-SkIntToScalar(deviceBounds.fLeft), -SkIntToScalar(deviceBo unds.fTop));
148 canvas.concat(ctx.ctm());
149 canvas.drawPicture(fPicture);
150 }
151
152 void SkPictureImageFilter::drawPictureAtOriginalResolution(Proxy* proxy, SkBaseD evice* device,
153 const SkIRect& device Bounds,
154 const Context& ctx) c onst {
155 SkMatrix inverseCtm;
156 if (!ctx.ctm().invert(&inverseCtm))
157 return;
158 SkRect localBounds = SkRect::Make(ctx.clipBounds());
159 inverseCtm.mapRect(&localBounds);
160 if (!localBounds.intersect(fCropRect))
161 return;
162 SkIRect localIBounds = localBounds.roundOut();
163 SkAutoTUnref<SkBaseDevice> localDevice(proxy->createDevice(localIBounds.widt h(), localIBounds.height()));
164
165 // Pass explicit surface props, as the simplified canvas constructor discard s device properties.
166 // FIXME: switch back to the public constructor (and unfriend) after
167 // https://code.google.com/p/skia/issues/detail?id=3142 is fixed.
168 SkCanvas localCanvas(localDevice, proxy->surfaceProps(), SkCanvas::kDefault_ InitFlags);
169 localCanvas.translate(-SkIntToScalar(localIBounds.fLeft), -SkIntToScalar(loc alIBounds.fTop));
170 localCanvas.drawPicture(fPicture);
171
172 // Pass explicit surface props, as the simplified canvas constructor discard s device properties.
173 // FIXME: switch back to the public constructor (and unfriend) after
174 // https://code.google.com/p/skia/issues/detail?id=3142 is fixed.
175 SkCanvas canvas(device, proxy->surfaceProps(), SkCanvas::kDefault_InitFlags) ;
176
177 canvas.translate(-SkIntToScalar(deviceBounds.fLeft), -SkIntToScalar(deviceBo unds.fTop));
178 canvas.concat(ctx.ctm());
179 SkPaint paint;
180 paint.setFilterLevel(fFilterLevel);
181 canvas.drawBitmap(localDevice.get()->accessBitmap(false), SkIntToScalar(loca lIBounds.fLeft), SkIntToScalar(localIBounds.fTop), &paint);
182 //canvas.drawPicture(fPicture);
183 }
OLDNEW
« include/effects/SkPictureImageFilter.h ('K') | « src/core/SkReadBuffer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698