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

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

Issue 1766743003: Switch SkOffsetImageFilter over to new onFilterImage interface (Closed) Base URL: https://skia.googlesource.com/skia.git@if-follow-on
Patch Set: Created 4 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 | « include/effects/SkOffsetImageFilter.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 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
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkDevice.h"
12 #include "SkReadBuffer.h"
13 #include "SkWriteBuffer.h"
14 #include "SkMatrix.h" 11 #include "SkMatrix.h"
15 #include "SkPaint.h" 12 #include "SkPaint.h"
13 #include "SkReadBuffer.h"
14 #include "SkSpecialImage.h"
15 #include "SkSpecialSurface.h"
16 #include "SkWriteBuffer.h"
16 17
17 bool SkOffsetImageFilter::onFilterImageDeprecated(Proxy* proxy, const SkBitmap& source, 18 SkSpecialImage* SkOffsetImageFilter::onFilterImage(SkSpecialImage* srcIn,
18 const Context& ctx, 19 const Context& ctx,
19 SkBitmap* result, 20 SkIPoint* offset) const {
20 SkIPoint* offset) const {
21 SkBitmap src = source;
22 SkIPoint srcOffset = SkIPoint::Make(0, 0); 21 SkIPoint srcOffset = SkIPoint::Make(0, 0);
23 if (!cropRectIsSet()) { 22 SkAutoTUnref<SkSpecialImage> src(this->filterInput(0, srcIn, ctx, &srcOffset ));
24 if (!this->filterInputDeprecated(0, proxy, source, ctx, &src, &srcOffset )) { 23 if (!src) {
25 return false; 24 return nullptr;
26 } 25 }
27 26
28 SkVector vec; 27 SkVector vec;
29 ctx.ctm().mapVectors(&vec, &fOffset, 1); 28 ctx.ctm().mapVectors(&vec, &fOffset, 1);
30 29
30 if (!this->cropRectIsSet()) {
31 offset->fX = srcOffset.fX + SkScalarRoundToInt(vec.fX); 31 offset->fX = srcOffset.fX + SkScalarRoundToInt(vec.fX);
32 offset->fY = srcOffset.fY + SkScalarRoundToInt(vec.fY); 32 offset->fY = srcOffset.fY + SkScalarRoundToInt(vec.fY);
33 *result = src; 33 return src.release();
34 } else { 34 } else {
35 if (!this->filterInputDeprecated(0, proxy, source, ctx, &src, &srcOffset )) {
36 return false;
37 }
38
39 SkIRect bounds; 35 SkIRect bounds;
40 SkIRect srcBounds = src.bounds(); 36 SkIRect srcBounds = SkIRect::MakeWH(srcIn->width(), srcIn->height());
Stephen White 2016/03/07 18:52:04 I don't think this is correct. I think we should b
robertphillips 2016/03/08 14:56:25 Done.
41 srcBounds.offset(srcOffset); 37 srcBounds.offset(srcOffset);
42 if (!this->applyCropRect(ctx, srcBounds, &bounds)) { 38 if (!this->applyCropRect(ctx, srcBounds, &bounds)) {
43 return false; 39 return false;
44 } 40 }
45 41
46 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bo unds.height())); 42 SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(),
47 if (nullptr == device.get()) { 43 kPremul_SkAlphaType);
48 return false; 44 SkAutoTUnref<SkSpecialSurface> surf(src->newSurface(info));
45 if (!surf) {
46 return nullptr;
49 } 47 }
50 SkCanvas canvas(device); 48
49 SkCanvas* canvas = surf->getCanvas();
50 SkASSERT(canvas);
51
52 canvas->clear(0x0);
Stephen White 2016/03/07 18:52:04 It seems surprising to me that we always have to c
robertphillips 2016/03/08 14:56:25 The SkDevice used to do it for us. Hopefully we ca
53
51 SkPaint paint; 54 SkPaint paint;
52 paint.setXfermodeMode(SkXfermode::kSrc_Mode); 55 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
53 canvas.translate(SkIntToScalar(srcOffset.fX - bounds.fLeft), 56 canvas->translate(SkIntToScalar(srcOffset.fX - bounds.fLeft),
54 SkIntToScalar(srcOffset.fY - bounds.fTop)); 57 SkIntToScalar(srcOffset.fY - bounds.fTop));
55 SkVector vec; 58
56 ctx.ctm().mapVectors(&vec, &fOffset, 1); 59 src->draw(canvas, vec.x(), vec.y(), &paint);
57 canvas.drawBitmap(src, vec.x(), vec.y(), &paint); 60
58 *result = device->accessBitmap(false);
59 offset->fX = bounds.fLeft; 61 offset->fX = bounds.fLeft;
60 offset->fY = bounds.fTop; 62 offset->fY = bounds.fTop;
63 return surf->newImageSnapshot();
61 } 64 }
62 return true;
63 } 65 }
64 66
65 void SkOffsetImageFilter::computeFastBounds(const SkRect& src, SkRect* dst) cons t { 67 void SkOffsetImageFilter::computeFastBounds(const SkRect& src, SkRect* dst) cons t {
66 if (getInput(0)) { 68 if (getInput(0)) {
67 getInput(0)->computeFastBounds(src, dst); 69 getInput(0)->computeFastBounds(src, dst);
68 } else { 70 } else {
69 *dst = src; 71 *dst = src;
70 } 72 }
71 dst->offset(fOffset.fX, fOffset.fY); 73 dst->offset(fOffset.fX, fOffset.fY);
72 } 74 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 void SkOffsetImageFilter::toString(SkString* str) const { 107 void SkOffsetImageFilter::toString(SkString* str) const {
106 str->appendf("SkOffsetImageFilter: ("); 108 str->appendf("SkOffsetImageFilter: (");
107 str->appendf("offset: (%f, %f) ", fOffset.fX, fOffset.fY); 109 str->appendf("offset: (%f, %f) ", fOffset.fX, fOffset.fY);
108 str->append("input: ("); 110 str->append("input: (");
109 if (this->getInput(0)) { 111 if (this->getInput(0)) {
110 this->getInput(0)->toString(str); 112 this->getInput(0)->toString(str);
111 } 113 }
112 str->append("))"); 114 str->append("))");
113 } 115 }
114 #endif 116 #endif
OLDNEW
« no previous file with comments | « include/effects/SkOffsetImageFilter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698