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

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: rebased again 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
« no previous file with comments | « src/core/SkReadBuffer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 SkFlattenable* SkPictureImageFilter::CreateProc(SkReadBuffer& buffer) { 35 SkFlattenable* SkPictureImageFilter::CreateProc(SkReadBuffer& buffer) {
34 SkAutoTUnref<SkPicture> picture; 36 SkAutoTUnref<SkPicture> picture;
35 SkRect cropRect; 37 SkRect cropRect;
36 38
37 if (!buffer.isCrossProcess()) { 39 if (!buffer.isCrossProcess()) {
38 if (buffer.readBool()) { 40 if (buffer.readBool()) {
39 picture.reset(SkPicture::CreateFromBuffer(buffer)); 41 picture.reset(SkPicture::CreateFromBuffer(buffer));
40 } 42 }
41 } else { 43 } else {
42 buffer.validate(!buffer.readBool()); 44 buffer.validate(!buffer.readBool());
43 } 45 }
44 buffer.readRect(&cropRect); 46 buffer.readRect(&cropRect);
47 PictureResolution pictureResolution;
48 if (buffer.isVersionLT(SkReadBuffer::kPictureImageFilterResolution_Version)) {
49 pictureResolution = kDeviceSpace_PictureResolution;
50 } else {
51 pictureResolution = (PictureResolution)buffer.readInt();
52 }
45 53
54 if (pictureResolution == kLocalSpace_PictureResolution) {
55 return CreateForLocalSpace(picture, cropRect);
56 }
46 return Create(picture, cropRect); 57 return Create(picture, cropRect);
47 } 58 }
48 59
49 void SkPictureImageFilter::flatten(SkWriteBuffer& buffer) const { 60 void SkPictureImageFilter::flatten(SkWriteBuffer& buffer) const {
50 if (!buffer.isCrossProcess()) { 61 if (!buffer.isCrossProcess()) {
51 bool hasPicture = (fPicture != NULL); 62 bool hasPicture = (fPicture != NULL);
52 buffer.writeBool(hasPicture); 63 buffer.writeBool(hasPicture);
53 if (hasPicture) { 64 if (hasPicture) {
54 fPicture->flatten(buffer); 65 fPicture->flatten(buffer);
55 } 66 }
56 } else { 67 } else {
57 buffer.writeBool(false); 68 buffer.writeBool(false);
58 } 69 }
59 buffer.writeRect(fCropRect); 70 buffer.writeRect(fCropRect);
71 buffer.writeInt(fPictureResolution);
60 } 72 }
61 73
62 bool SkPictureImageFilter::onFilterImage(Proxy* proxy, const SkBitmap&, const Co ntext& ctx, 74 bool SkPictureImageFilter::onFilterImage(Proxy* proxy, const SkBitmap&, const Co ntext& ctx,
63 SkBitmap* result, SkIPoint* offset) con st { 75 SkBitmap* result, SkIPoint* offset) con st {
64 if (!fPicture) { 76 if (!fPicture) {
65 offset->fX = offset->fY = 0; 77 offset->fX = offset->fY = 0;
66 return true; 78 return true;
67 } 79 }
68 80
69 SkRect floatBounds; 81 SkRect floatBounds;
70 ctx.ctm().mapRect(&floatBounds, fCropRect); 82 ctx.ctm().mapRect(&floatBounds, fCropRect);
71 SkIRect bounds = floatBounds.roundOut(); 83 SkIRect bounds = floatBounds.roundOut();
72 if (!bounds.intersect(ctx.clipBounds())) { 84 if (!bounds.intersect(ctx.clipBounds())) {
73 return false; 85 return false;
74 } 86 }
75 87
76 if (bounds.isEmpty()) { 88 if (bounds.isEmpty()) {
77 offset->fX = offset->fY = 0; 89 offset->fX = offset->fY = 0;
78 return true; 90 return true;
79 } 91 }
80 92
81 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds .height())); 93 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds .height()));
82 if (NULL == device.get()) { 94 if (NULL == device.get()) {
83 return false; 95 return false;
84 } 96 }
85 97
86 // Pass explicit surface props, as the simplified canvas constructor discard s device properties. 98 if (kLocalSpace_PictureResolution == fPictureResolution &&
87 // FIXME: switch back to the public constructor (and unfriend) after 99 (ctx.ctm().getType() & ~SkMatrix::kTranslate_Mask)) {
88 // https://code.google.com/p/skia/issues/detail?id=3142 is fixed. 100 drawPictureAtLocalResolution(proxy, device.get(), bounds, ctx);
89 SkCanvas canvas(device.get(), proxy->surfaceProps(), SkCanvas::kDefault_Init Flags); 101 } else {
90 102 drawPictureAtDeviceResolution(proxy, device.get(), bounds, ctx);
91 canvas.translate(-SkIntToScalar(bounds.fLeft), -SkIntToScalar(bounds.fTop)); 103 }
92 canvas.concat(ctx.ctm());
93 canvas.drawPicture(fPicture);
94 104
95 *result = device.get()->accessBitmap(false); 105 *result = device.get()->accessBitmap(false);
96 offset->fX = bounds.fLeft; 106 offset->fX = bounds.fLeft;
97 offset->fY = bounds.fTop; 107 offset->fY = bounds.fTop;
98 return true; 108 return true;
99 } 109 }
110
111 void SkPictureImageFilter::drawPictureAtDeviceResolution(Proxy* proxy, SkBaseDev ice* device,
112 const SkIRect& deviceBo unds,
113 const Context& ctx) con st {
114 // Pass explicit surface props, as the simplified canvas constructor discard s device properties.
115 // FIXME: switch back to the public constructor (and unfriend) after
116 // https://code.google.com/p/skia/issues/detail?id=3142 is fixed.
117 SkCanvas canvas(device, proxy->surfaceProps(), SkCanvas::kDefault_InitFlags) ;
118
119 canvas.translate(-SkIntToScalar(deviceBounds.fLeft), -SkIntToScalar(deviceBo unds.fTop));
120 canvas.concat(ctx.ctm());
121 canvas.drawPicture(fPicture);
122 }
123
124 void SkPictureImageFilter::drawPictureAtLocalResolution(Proxy* proxy, SkBaseDevi ce* device,
125 const SkIRect& deviceBou nds,
126 const Context& ctx) cons t {
127 SkMatrix inverseCtm;
128 if (!ctx.ctm().invert(&inverseCtm))
129 return;
130 SkRect localBounds = SkRect::Make(ctx.clipBounds());
131 inverseCtm.mapRect(&localBounds);
132 if (!localBounds.intersect(fCropRect))
133 return;
134 SkIRect localIBounds = localBounds.roundOut();
135 SkAutoTUnref<SkBaseDevice> localDevice(proxy->createDevice(localIBounds.widt h(), localIBounds.height()));
136
137 // Pass explicit surface props, as the simplified canvas constructor discard s device properties.
138 // FIXME: switch back to the public constructor (and unfriend) after
139 // https://code.google.com/p/skia/issues/detail?id=3142 is fixed.
140 SkCanvas localCanvas(localDevice, proxy->surfaceProps(), SkCanvas::kDefault_ InitFlags);
141 localCanvas.translate(-SkIntToScalar(localIBounds.fLeft), -SkIntToScalar(loc alIBounds.fTop));
142 localCanvas.drawPicture(fPicture);
143
144 // Pass explicit surface props, as the simplified canvas constructor discard s device properties.
145 // FIXME: switch back to the public constructor (and unfriend) after
146 // https://code.google.com/p/skia/issues/detail?id=3142 is fixed.
147 SkCanvas canvas(device, proxy->surfaceProps(), SkCanvas::kDefault_InitFlags) ;
148
149 canvas.translate(-SkIntToScalar(deviceBounds.fLeft), -SkIntToScalar(deviceBo unds.fTop));
150 canvas.concat(ctx.ctm());
151 SkPaint paint;
152 paint.setFilterLevel(SkPaint::kLow_FilterLevel);
153 canvas.drawBitmap(localDevice.get()->accessBitmap(false), SkIntToScalar(loca lIBounds.fLeft), SkIntToScalar(localIBounds.fTop), &paint);
154 //canvas.drawPicture(fPicture);
155 }
OLDNEW
« no previous file with comments | « src/core/SkReadBuffer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698