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

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

Issue 1901513002: Switch SkColorFilterImageFilter over to new onFilterImage interface (again) (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 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/SkColorFilterImageFilter.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 "SkColorFilterImageFilter.h" 8 #include "SkColorFilterImageFilter.h"
9 9
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkColorFilter.h" 11 #include "SkColorFilter.h"
12 #include "SkDevice.h"
13 #include "SkReadBuffer.h" 12 #include "SkReadBuffer.h"
13 #include "SkSpecialImage.h"
14 #include "SkSpecialSurface.h"
14 #include "SkWriteBuffer.h" 15 #include "SkWriteBuffer.h"
15 16
16 sk_sp<SkImageFilter> SkColorFilterImageFilter::Make(sk_sp<SkColorFilter> cf, 17 sk_sp<SkImageFilter> SkColorFilterImageFilter::Make(sk_sp<SkColorFilter> cf,
17 sk_sp<SkImageFilter> input, 18 sk_sp<SkImageFilter> input,
18 const CropRect* cropRect) { 19 const CropRect* cropRect) {
19 if (!cf) { 20 if (!cf) {
20 return nullptr; 21 return nullptr;
21 } 22 }
22 23
23 SkColorFilter* inputCF; 24 SkColorFilter* inputCF;
(...skipping 25 matching lines...) Expand all
49 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); 50 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
50 sk_sp<SkColorFilter> cf(buffer.readColorFilter()); 51 sk_sp<SkColorFilter> cf(buffer.readColorFilter());
51 return Make(std::move(cf), common.getInput(0), &common.cropRect()); 52 return Make(std::move(cf), common.getInput(0), &common.cropRect());
52 } 53 }
53 54
54 void SkColorFilterImageFilter::flatten(SkWriteBuffer& buffer) const { 55 void SkColorFilterImageFilter::flatten(SkWriteBuffer& buffer) const {
55 this->INHERITED::flatten(buffer); 56 this->INHERITED::flatten(buffer);
56 buffer.writeFlattenable(fColorFilter.get()); 57 buffer.writeFlattenable(fColorFilter.get());
57 } 58 }
58 59
59 bool SkColorFilterImageFilter::onFilterImageDeprecated(Proxy* proxy, const SkBit map& source, 60 sk_sp<SkSpecialImage> SkColorFilterImageFilter::onFilterImage(SkSpecialImage* so urce,
60 const Context& ctx, 61 const Context& ctx ,
61 SkBitmap* result, 62 SkIPoint* offset) const {
62 SkIPoint* offset) const { 63 SkIPoint inputOffset = SkIPoint::Make(0, 0);
63 SkBitmap src = source; 64 sk_sp<SkSpecialImage> input(this->filterInput(0, source, ctx, &inputOffset)) ;
64 SkIPoint srcOffset = SkIPoint::Make(0, 0);
65 bool inputResult = this->filterInputDeprecated(0, proxy, source, ctx, &src, &srcOffset);
66 65
67 SkIRect srcBounds; 66 SkIRect inputBounds;
68
69 if (fColorFilter->affectsTransparentBlack()) { 67 if (fColorFilter->affectsTransparentBlack()) {
70 // If the color filter affects transparent black, the bounds are the ent ire clip. 68 // If the color filter affects transparent black, the bounds are the ent ire clip.
71 srcBounds = ctx.clipBounds(); 69 inputBounds = ctx.clipBounds();
72 } else if (!inputResult) { 70 } else if (!input) {
73 return false; 71 return nullptr;
74 } else { 72 } else {
75 srcBounds = src.bounds(); 73 inputBounds = SkIRect::MakeXYWH(inputOffset.x(), inputOffset.y(),
76 srcBounds.offset(srcOffset); 74 input->width(), input->height());
77 } 75 }
78 76
79 SkIRect bounds; 77 SkIRect bounds;
80 if (!this->applyCropRect(ctx, srcBounds, &bounds)) { 78 if (!this->applyCropRect(ctx, inputBounds, &bounds)) {
81 return false; 79 return nullptr;
82 } 80 }
83 81
84 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds .height())); 82 SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(), kPr emul_SkAlphaType);
85 if (nullptr == device.get()) { 83 sk_sp<SkSpecialSurface> surf(source->makeSurface(info));
86 return false; 84 if (!surf) {
85 return nullptr;
87 } 86 }
88 SkCanvas canvas(device.get()); 87
88 SkCanvas* canvas = surf->getCanvas();
89 SkASSERT(canvas);
89 90
90 SkPaint paint; 91 SkPaint paint;
92
91 paint.setXfermodeMode(SkXfermode::kSrc_Mode); 93 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
92 paint.setColorFilter(fColorFilter); 94 paint.setColorFilter(fColorFilter);
93 95
94 // TODO: it may not be necessary to clear or drawPaint inside the input boun ds 96 // TODO: it may not be necessary to clear or drawPaint inside the input boun ds
95 // (see skbug.com/5075) 97 // (see skbug.com/5075)
96 if (fColorFilter->affectsTransparentBlack()) { 98 if (fColorFilter->affectsTransparentBlack()) {
97 // The subsequent drawBitmap call may not fill the entire canvas. For fi lters which 99 // The subsequent input->draw() call may not fill the entire canvas. For filters which
98 // affect transparent black, ensure that the filter is applied everywher e. 100 // affect transparent black, ensure that the filter is applied everywher e.
99 canvas.drawPaint(paint); 101 canvas->drawPaint(paint);
102 } else {
103 canvas->clear(0x0);
100 } 104 }
101 105
102 canvas.drawBitmap(src, SkIntToScalar(srcOffset.fX - bounds.fLeft), 106 if (input) {
103 SkIntToScalar(srcOffset.fY - bounds.fTop), &paint); 107 input->draw(canvas,
104 *result = device.get()->accessBitmap(false); 108 SkIntToScalar(inputOffset.fX - bounds.fLeft),
109 SkIntToScalar(inputOffset.fY - bounds.fTop),
110 &paint);
111 }
112
105 offset->fX = bounds.fLeft; 113 offset->fX = bounds.fLeft;
106 offset->fY = bounds.fTop; 114 offset->fY = bounds.fTop;
107 return true; 115 return surf->makeImageSnapshot();
108 } 116 }
109 117
110 bool SkColorFilterImageFilter::onIsColorFilterNode(SkColorFilter** filter) const { 118 bool SkColorFilterImageFilter::onIsColorFilterNode(SkColorFilter** filter) const {
111 SkASSERT(1 == this->countInputs()); 119 SkASSERT(1 == this->countInputs());
112 if (!this->cropRectIsSet()) { 120 if (!this->cropRectIsSet()) {
113 if (filter) { 121 if (filter) {
114 *filter = SkRef(fColorFilter.get()); 122 *filter = SkRef(fColorFilter.get());
115 } 123 }
116 return true; 124 return true;
117 } 125 }
(...skipping 13 matching lines...) Expand all
131 if (this->getInput(0)) { 139 if (this->getInput(0)) {
132 this->getInput(0)->toString(str); 140 this->getInput(0)->toString(str);
133 } 141 }
134 142
135 str->appendf(") color filter: "); 143 str->appendf(") color filter: ");
136 fColorFilter->toString(str); 144 fColorFilter->toString(str);
137 145
138 str->append(")"); 146 str->append(")");
139 } 147 }
140 #endif 148 #endif
OLDNEW
« no previous file with comments | « include/effects/SkColorFilterImageFilter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698