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

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: response to review comments 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 : INHERITED(0, 0, NULL, uniqueID) 17 : INHERITED(0, 0, NULL, uniqueID)
18 , fPicture(SkSafeRef(picture)) 18 , fPicture(SkSafeRef(picture))
19 , fCropRect(picture ? picture->cullRect() : SkRect::MakeEmpty()) { 19 , fCropRect(picture ? picture->cullRect() : SkRect::MakeEmpty())
20 , fPictureResolution(kDeviceSpace_PictureResolution) {
20 } 21 }
21 22
22 SkPictureImageFilter::SkPictureImageFilter(const SkPicture* picture, const SkRec t& cropRect, 23 SkPictureImageFilter::SkPictureImageFilter(const SkPicture* picture, const SkRec t& cropRect,
23 uint32_t uniqueID) 24 uint32_t uniqueID, PictureResolution pictureResolution)
24 : INHERITED(0, 0, NULL, uniqueID) 25 : INHERITED(0, 0, NULL, uniqueID)
25 , fPicture(SkSafeRef(picture)) 26 , fPicture(SkSafeRef(picture))
26 , fCropRect(cropRect) { 27 , fCropRect(cropRect)
28 , fPictureResolution(pictureResolution) {
27 } 29 }
28 30
29 SkPictureImageFilter::~SkPictureImageFilter() { 31 SkPictureImageFilter::~SkPictureImageFilter() {
30 SkSafeUnref(fPicture); 32 SkSafeUnref(fPicture);
31 } 33 }
32 34
33 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING 35 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
34 SkPictureImageFilter::SkPictureImageFilter(SkReadBuffer& buffer) 36 SkPictureImageFilter::SkPictureImageFilter(SkReadBuffer& buffer)
35 : INHERITED(0, buffer), 37 : INHERITED(0, buffer),
36 fPicture(NULL) { 38 fPicture(NULL) {
37 if (!buffer.isCrossProcess()) { 39 if (!buffer.isCrossProcess()) {
38 if (buffer.readBool()) { 40 if (buffer.readBool()) {
39 fPicture = SkPicture::CreateFromBuffer(buffer); 41 fPicture = SkPicture::CreateFromBuffer(buffer);
40 } 42 }
41 } else { 43 } else {
42 buffer.validate(!buffer.readBool()); 44 buffer.validate(!buffer.readBool());
43 } 45 }
44 buffer.readRect(&fCropRect); 46 buffer.readRect(&fCropRect);
47 if (buffer.isVersionLT(SkReadBuffer::kPictureImageFilterResolution_Version)) {
48 fPictureResolution = kDeviceSpace_PictureResolution;
49 } else {
50 fPictureResolution = (PictureResolution)buffer.readInt();
51 }
45 } 52 }
46 #endif 53 #endif
47 54
48 SkFlattenable* SkPictureImageFilter::CreateProc(SkReadBuffer& buffer) { 55 SkFlattenable* SkPictureImageFilter::CreateProc(SkReadBuffer& buffer) {
49 SkAutoTUnref<SkPicture> picture; 56 SkAutoTUnref<SkPicture> picture;
50 SkRect cropRect; 57 SkRect cropRect;
51 58
52 if (!buffer.isCrossProcess()) { 59 if (!buffer.isCrossProcess()) {
53 if (buffer.readBool()) { 60 if (buffer.readBool()) {
54 picture.reset(SkPicture::CreateFromBuffer(buffer)); 61 picture.reset(SkPicture::CreateFromBuffer(buffer));
55 } 62 }
56 } else { 63 } else {
57 buffer.validate(!buffer.readBool()); 64 buffer.validate(!buffer.readBool());
58 } 65 }
59 buffer.readRect(&cropRect); 66 buffer.readRect(&cropRect);
67 PictureResolution pictureResolution;
68 if (buffer.isVersionLT(SkReadBuffer::kPictureImageFilterResolution_Version)) {
69 pictureResolution = kDeviceSpace_PictureResolution;
70 } else {
71 pictureResolution = (PictureResolution)buffer.readInt();
72 }
60 73
74 if (pictureResolution == kLocalSpace_PictureResolution) {
75 return CreateForLocalSpace(picture, cropRect);
76 }
61 return Create(picture, cropRect); 77 return Create(picture, cropRect);
62 } 78 }
63 79
64 void SkPictureImageFilter::flatten(SkWriteBuffer& buffer) const { 80 void SkPictureImageFilter::flatten(SkWriteBuffer& buffer) const {
65 if (!buffer.isCrossProcess()) { 81 if (!buffer.isCrossProcess()) {
66 bool hasPicture = (fPicture != NULL); 82 bool hasPicture = (fPicture != NULL);
67 buffer.writeBool(hasPicture); 83 buffer.writeBool(hasPicture);
68 if (hasPicture) { 84 if (hasPicture) {
69 fPicture->flatten(buffer); 85 fPicture->flatten(buffer);
70 } 86 }
71 } else { 87 } else {
72 buffer.writeBool(false); 88 buffer.writeBool(false);
73 } 89 }
74 buffer.writeRect(fCropRect); 90 buffer.writeRect(fCropRect);
91 buffer.writeInt(fPictureResolution);
75 } 92 }
76 93
77 bool SkPictureImageFilter::onFilterImage(Proxy* proxy, const SkBitmap&, const Co ntext& ctx, 94 bool SkPictureImageFilter::onFilterImage(Proxy* proxy, const SkBitmap&, const Co ntext& ctx,
78 SkBitmap* result, SkIPoint* offset) con st { 95 SkBitmap* result, SkIPoint* offset) con st {
79 if (!fPicture) { 96 if (!fPicture) {
80 offset->fX = offset->fY = 0; 97 offset->fX = offset->fY = 0;
81 return true; 98 return true;
82 } 99 }
83 100
84 SkRect floatBounds; 101 SkRect floatBounds;
85 ctx.ctm().mapRect(&floatBounds, fCropRect); 102 ctx.ctm().mapRect(&floatBounds, fCropRect);
86 SkIRect bounds = floatBounds.roundOut(); 103 SkIRect bounds = floatBounds.roundOut();
87 if (!bounds.intersect(ctx.clipBounds())) { 104 if (!bounds.intersect(ctx.clipBounds())) {
88 return false; 105 return false;
89 } 106 }
90 107
91 if (bounds.isEmpty()) { 108 if (bounds.isEmpty()) {
92 offset->fX = offset->fY = 0; 109 offset->fX = offset->fY = 0;
93 return true; 110 return true;
94 } 111 }
95 112
96 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds .height())); 113 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds .height()));
97 if (NULL == device.get()) { 114 if (NULL == device.get()) {
98 return false; 115 return false;
99 } 116 }
100 117
101 // Pass explicit surface props, as the simplified canvas constructor discard s device properties. 118 if (kLocalSpace_PictureResolution == fPictureResolution &&
102 // FIXME: switch back to the public constructor (and unfriend) after 119 (ctx.ctm().getType() & ~SkMatrix::kTranslate_Mask)) {
103 // https://code.google.com/p/skia/issues/detail?id=3142 is fixed. 120 drawPictureAtOriginalResolution(proxy, device.get(), bounds, ctx);
104 SkCanvas canvas(device.get(), proxy->surfaceProps(), SkCanvas::kDefault_Init Flags); 121 } else {
105 122 drawPictureAtNativeResolution(proxy, device.get(), bounds, ctx);
106 canvas.translate(-SkIntToScalar(bounds.fLeft), -SkIntToScalar(bounds.fTop)); 123 }
107 canvas.concat(ctx.ctm());
108 canvas.drawPicture(fPicture);
109 124
110 *result = device.get()->accessBitmap(false); 125 *result = device.get()->accessBitmap(false);
111 offset->fX = bounds.fLeft; 126 offset->fX = bounds.fLeft;
112 offset->fY = bounds.fTop; 127 offset->fY = bounds.fTop;
113 return true; 128 return true;
114 } 129 }
130
131 void SkPictureImageFilter::drawPictureAtNativeResolution(Proxy* proxy, SkBaseDev ice* device,
132 const SkIRect& deviceBou nds,
133 const Context& ctx) cons t {
134 // Pass explicit surface props, as the simplified canvas constructor discard s device properties.
135 // FIXME: switch back to the public constructor (and unfriend) after
136 // https://code.google.com/p/skia/issues/detail?id=3142 is fixed.
137 SkCanvas canvas(device, proxy->surfaceProps(), SkCanvas::kDefault_InitFlags) ;
138
139 canvas.translate(-SkIntToScalar(deviceBounds.fLeft), -SkIntToScalar(deviceBo unds.fTop));
140 canvas.concat(ctx.ctm());
141 canvas.drawPicture(fPicture);
142 }
143
144 void SkPictureImageFilter::drawPictureAtOriginalResolution(Proxy* proxy, SkBaseD evice* device,
145 const SkIRect& device Bounds,
146 const Context& ctx) c onst {
147 SkMatrix inverseCtm;
148 if (!ctx.ctm().invert(&inverseCtm))
149 return;
150 SkRect localBounds = SkRect::Make(ctx.clipBounds());
151 inverseCtm.mapRect(&localBounds);
152 if (!localBounds.intersect(fCropRect))
153 return;
154 SkIRect localIBounds = localBounds.roundOut();
155 SkAutoTUnref<SkBaseDevice> localDevice(proxy->createDevice(localIBounds.widt h(), localIBounds.height()));
156
157 // Pass explicit surface props, as the simplified canvas constructor discard s device properties.
158 // FIXME: switch back to the public constructor (and unfriend) after
159 // https://code.google.com/p/skia/issues/detail?id=3142 is fixed.
160 SkCanvas localCanvas(localDevice, proxy->surfaceProps(), SkCanvas::kDefault_ InitFlags);
161 localCanvas.translate(-SkIntToScalar(localIBounds.fLeft), -SkIntToScalar(loc alIBounds.fTop));
162 localCanvas.drawPicture(fPicture);
163
164 // Pass explicit surface props, as the simplified canvas constructor discard s device properties.
165 // FIXME: switch back to the public constructor (and unfriend) after
166 // https://code.google.com/p/skia/issues/detail?id=3142 is fixed.
167 SkCanvas canvas(device, proxy->surfaceProps(), SkCanvas::kDefault_InitFlags) ;
168
169 canvas.translate(-SkIntToScalar(deviceBounds.fLeft), -SkIntToScalar(deviceBo unds.fTop));
170 canvas.concat(ctx.ctm());
171 SkPaint paint;
172 paint.setFilterLevel(SkPaint::kLow_FilterLevel);
173 canvas.drawBitmap(localDevice.get()->accessBitmap(false), SkIntToScalar(loca lIBounds.fLeft), SkIntToScalar(localIBounds.fTop), &paint);
174 //canvas.drawPicture(fPicture);
Stephen White 2014/12/01 16:02:12 Commented-out code; please remove.
175 }
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