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

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

Issue 112803004: Make SkImageFilter crop rects relative to the primitive origin, instead of relative to their parent (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Updated to ToT Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « src/effects/SkMorphologyImageFilter.cpp ('k') | src/effects/SkPictureImageFilter.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 2012 The Android Open Source Project 2 * Copyright 2012 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 "SkOffsetImageFilter.h" 8 #include "SkOffsetImageFilter.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkDevice.h" 11 #include "SkDevice.h"
12 #include "SkFlattenableBuffers.h" 12 #include "SkFlattenableBuffers.h"
13 #include "SkMatrix.h" 13 #include "SkMatrix.h"
14 #include "SkPaint.h" 14 #include "SkPaint.h"
15 15
16 bool SkOffsetImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& source, 16 bool SkOffsetImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& source,
17 const SkMatrix& matrix, 17 const SkMatrix& matrix,
18 SkBitmap* result, 18 SkBitmap* result,
19 SkIPoint* loc) { 19 SkIPoint* offset) {
20 SkImageFilter* input = getInput(0); 20 SkImageFilter* input = getInput(0);
21 SkBitmap src = source; 21 SkBitmap src = source;
22 SkIPoint srcOffset = SkIPoint::Make(0, 0);
22 #ifdef SK_DISABLE_OFFSETIMAGEFILTER_OPTIMIZATION 23 #ifdef SK_DISABLE_OFFSETIMAGEFILTER_OPTIMIZATION
23 if (false) { 24 if (false) {
24 #else 25 #else
25 if (!cropRectIsSet()) { 26 if (!cropRectIsSet()) {
26 #endif 27 #endif
27 if (input && !input->filterImage(proxy, source, matrix, &src, loc)) { 28 if (input && !input->filterImage(proxy, source, matrix, &src, &srcOffset )) {
28 return false; 29 return false;
29 } 30 }
30 31
31 SkVector vec; 32 SkVector vec;
32 matrix.mapVectors(&vec, &fOffset, 1); 33 matrix.mapVectors(&vec, &fOffset, 1);
33 34
34 loc->fX += SkScalarRoundToInt(vec.fX); 35 offset->fX = srcOffset.fX + SkScalarRoundToInt(vec.fX);
35 loc->fY += SkScalarRoundToInt(vec.fY); 36 offset->fY = srcOffset.fY + SkScalarRoundToInt(vec.fY);
36 *result = src; 37 *result = src;
37 } else { 38 } else {
38 SkIPoint srcOffset = SkIPoint::Make(0, 0);
39 if (input && !input->filterImage(proxy, source, matrix, &src, &srcOffset )) { 39 if (input && !input->filterImage(proxy, source, matrix, &src, &srcOffset )) {
40 return false; 40 return false;
41 } 41 }
42 42
43 SkIRect bounds; 43 SkIRect bounds;
44 src.getBounds(&bounds); 44 src.getBounds(&bounds);
45 bounds.offset(srcOffset);
45 46
46 if (!applyCropRect(&bounds, matrix)) { 47 if (!applyCropRect(&bounds, matrix)) {
47 return false; 48 return false;
48 } 49 }
49 50
50 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bo unds.height())); 51 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bo unds.height()));
51 if (NULL == device.get()) { 52 if (NULL == device.get()) {
52 return false; 53 return false;
53 } 54 }
54 SkCanvas canvas(device); 55 SkCanvas canvas(device);
55 SkPaint paint; 56 SkPaint paint;
56 paint.setXfermodeMode(SkXfermode::kSrc_Mode); 57 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
57 canvas.drawBitmap(src, fOffset.fX - bounds.left(), fOffset.fY - bounds.t op(), &paint); 58 canvas.translate(SkIntToScalar(srcOffset.fX - bounds.fLeft),
59 SkIntToScalar(srcOffset.fY - bounds.fTop));
60 canvas.drawBitmap(src, fOffset.x(), fOffset.y(), &paint);
58 *result = device->accessBitmap(false); 61 *result = device->accessBitmap(false);
59 loc->fX += bounds.left(); 62 offset->fX = bounds.fLeft;
60 loc->fY += bounds.top(); 63 offset->fY = bounds.fTop;
61 } 64 }
62 return true; 65 return true;
63 } 66 }
64 67
65 bool SkOffsetImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm , 68 bool SkOffsetImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm ,
66 SkIRect* dst) { 69 SkIRect* dst) {
67 SkVector vec; 70 SkVector vec;
68 ctm.mapVectors(&vec, &fOffset, 1); 71 ctm.mapVectors(&vec, &fOffset, 1);
69 72
70 *dst = src; 73 *dst = src;
(...skipping 10 matching lines...) Expand all
81 const CropRect* cropRect) : INHERITED(i nput, cropRect) { 84 const CropRect* cropRect) : INHERITED(i nput, cropRect) {
82 fOffset.set(dx, dy); 85 fOffset.set(dx, dy);
83 } 86 }
84 87
85 SkOffsetImageFilter::SkOffsetImageFilter(SkFlattenableReadBuffer& buffer) 88 SkOffsetImageFilter::SkOffsetImageFilter(SkFlattenableReadBuffer& buffer)
86 : INHERITED(1, buffer) { 89 : INHERITED(1, buffer) {
87 buffer.readPoint(&fOffset); 90 buffer.readPoint(&fOffset);
88 buffer.validate(SkScalarIsFinite(fOffset.fX) && 91 buffer.validate(SkScalarIsFinite(fOffset.fX) &&
89 SkScalarIsFinite(fOffset.fY)); 92 SkScalarIsFinite(fOffset.fY));
90 } 93 }
OLDNEW
« no previous file with comments | « src/effects/SkMorphologyImageFilter.cpp ('k') | src/effects/SkPictureImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698