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

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

Issue 920513003: Make filters use SkImage instead of SkBitmap Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 9 months 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/effects/SkOffsetImageFilter.cpp ('k') | src/effects/SkRectShaderImageFilter.cpp » ('j') | 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"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 fPicture->flatten(buffer); 83 fPicture->flatten(buffer);
84 } 84 }
85 } 85 }
86 buffer.writeRect(fCropRect); 86 buffer.writeRect(fCropRect);
87 buffer.writeInt(fPictureResolution); 87 buffer.writeInt(fPictureResolution);
88 if (kLocalSpace_PictureResolution == fPictureResolution) { 88 if (kLocalSpace_PictureResolution == fPictureResolution) {
89 buffer.writeInt(fFilterQuality); 89 buffer.writeInt(fFilterQuality);
90 } 90 }
91 } 91 }
92 92
93 bool SkPictureImageFilter::onFilterImage(Proxy* proxy, const SkBitmap&, const Co ntext& ctx, 93 bool SkPictureImageFilter::onFilterImage(Proxy* proxy, const SkImage*, const Con text& ctx,
94 SkBitmap* result, SkIPoint* offset) con st { 94 SkAutoTUnref<const SkImage>& result, Sk IPoint* offset) const {
95 if (!fPicture) { 95 if (!fPicture) {
96 offset->fX = offset->fY = 0; 96 offset->fX = offset->fY = 0;
97 return true; 97 return true;
98 } 98 }
99 99
100 SkRect floatBounds; 100 SkRect floatBounds;
101 ctx.ctm().mapRect(&floatBounds, fCropRect); 101 ctx.ctm().mapRect(&floatBounds, fCropRect);
102 SkIRect bounds = floatBounds.roundOut(); 102 SkIRect bounds = floatBounds.roundOut();
103 if (!bounds.intersect(ctx.clipBounds())) { 103 if (!bounds.intersect(ctx.clipBounds())) {
104 return false; 104 return false;
105 } 105 }
106 106
107 if (bounds.isEmpty()) { 107 if (bounds.isEmpty()) {
108 offset->fX = offset->fY = 0; 108 offset->fX = offset->fY = 0;
109 return true; 109 return true;
110 } 110 }
111 111
112 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds .height())); 112 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds .height()));
113 if (NULL == device.get()) { 113 if (NULL == device.get()) {
114 return false; 114 return false;
115 } 115 }
116 116
117 if (kDeviceSpace_PictureResolution == fPictureResolution || 117 if (kDeviceSpace_PictureResolution == fPictureResolution ||
118 0 == (ctx.ctm().getType() & ~SkMatrix::kTranslate_Mask)) { 118 0 == (ctx.ctm().getType() & ~SkMatrix::kTranslate_Mask)) {
119 drawPictureAtDeviceResolution(proxy, device.get(), bounds, ctx); 119 drawPictureAtDeviceResolution(proxy, device.get(), bounds, ctx);
120 } else { 120 } else {
121 drawPictureAtLocalResolution(proxy, device.get(), bounds, ctx); 121 drawPictureAtLocalResolution(proxy, device.get(), bounds, ctx);
122 } 122 }
123 123
124 *result = device.get()->accessBitmap(false); 124 SkImage* snapshot = device->newImageSnapshot();
125 if (NULL == snapshot) {
126 return false;
127 }
128 result.reset(snapshot);
129
125 offset->fX = bounds.fLeft; 130 offset->fX = bounds.fLeft;
126 offset->fY = bounds.fTop; 131 offset->fY = bounds.fTop;
127 return true; 132 return true;
128 } 133 }
129 134
130 void SkPictureImageFilter::drawPictureAtDeviceResolution(Proxy* proxy, SkBaseDev ice* device, 135 void SkPictureImageFilter::drawPictureAtDeviceResolution(Proxy* proxy, SkBaseDev ice* device,
131 const SkIRect& deviceBo unds, 136 const SkIRect& deviceBo unds,
132 const Context& ctx) con st { 137 const Context& ctx) con st {
133 // Pass explicit surface props, as the simplified canvas constructor discard s device properties. 138 // Pass explicit surface props, as the simplified canvas constructor discard s device properties.
134 // FIXME: switch back to the public constructor (and unfriend) after 139 // FIXME: switch back to the public constructor (and unfriend) after
(...skipping 18 matching lines...) Expand all
153 SkIRect localIBounds = localBounds.roundOut(); 158 SkIRect localIBounds = localBounds.roundOut();
154 SkAutoTUnref<SkBaseDevice> localDevice(proxy->createDevice(localIBounds.widt h(), localIBounds.height())); 159 SkAutoTUnref<SkBaseDevice> localDevice(proxy->createDevice(localIBounds.widt h(), localIBounds.height()));
155 160
156 // Pass explicit surface props, as the simplified canvas constructor discard s device properties. 161 // Pass explicit surface props, as the simplified canvas constructor discard s device properties.
157 // FIXME: switch back to the public constructor (and unfriend) after 162 // FIXME: switch back to the public constructor (and unfriend) after
158 // https://code.google.com/p/skia/issues/detail?id=3142 is fixed. 163 // https://code.google.com/p/skia/issues/detail?id=3142 is fixed.
159 SkCanvas localCanvas(localDevice, proxy->surfaceProps(), SkCanvas::kDefault_ InitFlags); 164 SkCanvas localCanvas(localDevice, proxy->surfaceProps(), SkCanvas::kDefault_ InitFlags);
160 localCanvas.translate(-SkIntToScalar(localIBounds.fLeft), -SkIntToScalar(loc alIBounds.fTop)); 165 localCanvas.translate(-SkIntToScalar(localIBounds.fLeft), -SkIntToScalar(loc alIBounds.fTop));
161 localCanvas.drawPicture(fPicture); 166 localCanvas.drawPicture(fPicture);
162 167
168 SkAutoTUnref<SkImage> image(localDevice->newImageSnapshot());
169 if (NULL == image) {
170 return;
171 }
163 // Pass explicit surface props, as the simplified canvas constructor discard s device properties. 172 // Pass explicit surface props, as the simplified canvas constructor discard s device properties.
164 // FIXME: switch back to the public constructor (and unfriend) after 173 // FIXME: switch back to the public constructor (and unfriend) after
165 // https://code.google.com/p/skia/issues/detail?id=3142 is fixed. 174 // https://code.google.com/p/skia/issues/detail?id=3142 is fixed.
166 SkCanvas canvas(device, proxy->surfaceProps(), SkCanvas::kDefault_InitFlags) ; 175 SkCanvas canvas(device, proxy->surfaceProps(), SkCanvas::kDefault_InitFlags) ;
167 176
168 canvas.translate(-SkIntToScalar(deviceBounds.fLeft), -SkIntToScalar(deviceBo unds.fTop)); 177 canvas.translate(-SkIntToScalar(deviceBounds.fLeft), -SkIntToScalar(deviceBo unds.fTop));
169 canvas.concat(ctx.ctm()); 178 canvas.concat(ctx.ctm());
170 SkPaint paint; 179 SkPaint paint;
171 paint.setFilterQuality(fFilterQuality); 180 paint.setFilterQuality(fFilterQuality);
172 canvas.drawBitmap(localDevice.get()->accessBitmap(false), SkIntToScalar(loca lIBounds.fLeft), 181 canvas.drawImage(image, SkIntToScalar(localIBounds.fLeft),
173 SkIntToScalar(localIBounds.fTop), &paint); 182 SkIntToScalar(localIBounds.fTop), &paint);
174 //canvas.drawPicture(fPicture); 183 //canvas.drawPicture(fPicture);
175 } 184 }
176 185
177 #ifndef SK_IGNORE_TO_STRING 186 #ifndef SK_IGNORE_TO_STRING
178 void SkPictureImageFilter::toString(SkString* str) const { 187 void SkPictureImageFilter::toString(SkString* str) const {
179 str->appendf("SkPictureImageFilter: ("); 188 str->appendf("SkPictureImageFilter: (");
180 str->appendf("crop: (%f,%f,%f,%f) ", 189 str->appendf("crop: (%f,%f,%f,%f) ",
181 fCropRect.fLeft, fCropRect.fTop, fCropRect.fRight, fCropRect.fB ottom); 190 fCropRect.fLeft, fCropRect.fTop, fCropRect.fRight, fCropRect.fB ottom);
182 if (fPicture) { 191 if (fPicture) {
183 str->appendf("picture: (%f,%f,%f,%f)", 192 str->appendf("picture: (%f,%f,%f,%f)",
184 fPicture->cullRect().fLeft, fPicture->cullRect().fTop, 193 fPicture->cullRect().fLeft, fPicture->cullRect().fTop,
185 fPicture->cullRect().fRight, fPicture->cullRect().fBottom); 194 fPicture->cullRect().fRight, fPicture->cullRect().fBottom);
186 } 195 }
187 str->append(")"); 196 str->append(")");
188 } 197 }
189 #endif 198 #endif
OLDNEW
« no previous file with comments | « src/effects/SkOffsetImageFilter.cpp ('k') | src/effects/SkRectShaderImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698