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

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

Issue 1829993003: Revert of Switch SkColorFilterImageFilter over to new onFilterImage interface (Closed) Base URL: https://skia.googlesource.com/skia.git@master
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/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 #include "SkBitmap.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkColorMatrixFilter.h"
12 #include "SkDevice.h"
11 #include "SkColorFilter.h" 13 #include "SkColorFilter.h"
12 #include "SkReadBuffer.h" 14 #include "SkReadBuffer.h"
13 #include "SkSpecialImage.h" 15 #include "SkTableColorFilter.h"
14 #include "SkSpecialSurface.h"
15 #include "SkWriteBuffer.h" 16 #include "SkWriteBuffer.h"
16 17
17 SkImageFilter* SkColorFilterImageFilter::Create(SkColorFilter* cf, SkImageFilter * input, 18 SkImageFilter* SkColorFilterImageFilter::Create(SkColorFilter* cf, SkImageFilter * input,
18 const CropRect* cropRect) { 19 const CropRect* cropRect) {
19 if (!cf) { 20 if (nullptr == cf) {
20 return nullptr; 21 return nullptr;
21 } 22 }
22 23
23 SkColorFilter* inputCF; 24 SkColorFilter* inputCF;
24 if (input && input->isColorFilterNode(&inputCF)) { 25 if (input && input->isColorFilterNode(&inputCF)) {
25 // This is an optimization, as it collapses the hierarchy by just combin ing the two 26 // This is an optimization, as it collapses the hierarchy by just combin ing the two
26 // colorfilters into a single one, which the new imagefilter will wrap. 27 // colorfilters into a single one, which the new imagefilter will wrap.
27 sk_sp<SkColorFilter> newCF(SkColorFilter::MakeComposeFilter(sk_ref_sp(cf ), 28 sk_sp<SkColorFilter> newCF(SkColorFilter::MakeComposeFilter(sk_ref_sp(cf ),
28 sk_sp<SkColo rFilter>(inputCF))); 29 sk_sp<SkColo rFilter>(inputCF)));
29 if (newCF) { 30 if (newCF) {
30 return new SkColorFilterImageFilter(newCF.get(), input->getInput(0), cropRect); 31 return new SkColorFilterImageFilter(newCF.get(), input->getInput(0), cropRect);
31 } 32 }
32 } 33 }
33 34
34 return new SkColorFilterImageFilter(cf, input, cropRect); 35 return new SkColorFilterImageFilter(cf, input, cropRect);
35 } 36 }
36 37
37 SkColorFilterImageFilter::SkColorFilterImageFilter(SkColorFilter* cf, 38 SkColorFilterImageFilter::SkColorFilterImageFilter(SkColorFilter* cf,
38 SkImageFilter* input, 39 SkImageFilter* input, const CropRect* cropRect)
39 const CropRect* cropRect) 40 : INHERITED(1, &input, cropRect), fColorFilter(SkRef(cf)) {
40 : INHERITED(1, &input, cropRect)
41 , fColorFilter(SkRef(cf)) {
42 } 41 }
43 42
44 SkFlattenable* SkColorFilterImageFilter::CreateProc(SkReadBuffer& buffer) { 43 SkFlattenable* SkColorFilterImageFilter::CreateProc(SkReadBuffer& buffer) {
45 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); 44 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
46 sk_sp<SkColorFilter> cf(buffer.readColorFilter()); 45 sk_sp<SkColorFilter> cf(buffer.readColorFilter());
47 return Create(cf.get(), common.getInput(0), &common.cropRect()); 46 return Create(cf.get(), common.getInput(0), &common.cropRect());
48 } 47 }
49 48
50 void SkColorFilterImageFilter::flatten(SkWriteBuffer& buffer) const { 49 void SkColorFilterImageFilter::flatten(SkWriteBuffer& buffer) const {
51 this->INHERITED::flatten(buffer); 50 this->INHERITED::flatten(buffer);
52 buffer.writeFlattenable(fColorFilter.get()); 51 buffer.writeFlattenable(fColorFilter.get());
53 } 52 }
54 53
55 SkSpecialImage* SkColorFilterImageFilter::onFilterImage(SkSpecialImage* source, const Context& ctx, 54 bool SkColorFilterImageFilter::onFilterImageDeprecated(Proxy* proxy, const SkBit map& source,
56 SkIPoint* offset) const { 55 const Context& ctx,
57 SkIPoint inputOffset = SkIPoint::Make(0, 0); 56 SkBitmap* result,
58 SkAutoTUnref<SkSpecialImage> input(this->filterInput(0, source, ctx, &inputO ffset)); 57 SkIPoint* offset) const {
59 if (!input) { 58 SkBitmap src = source;
60 return nullptr; 59 SkIPoint srcOffset = SkIPoint::Make(0, 0);
60 if (!this->filterInputDeprecated(0, proxy, source, ctx, &src, &srcOffset)) {
61 return false;
61 } 62 }
62 63
63 SkIRect bounds; 64 SkIRect bounds;
64 const SkIRect inputBounds = SkIRect::MakeXYWH(inputOffset.fX, inputOffset.fY , 65 SkIRect srcBounds = src.bounds();
65 input->width(), input->height( )); 66 srcBounds.offset(srcOffset);
66 if (!this->applyCropRect(ctx, inputBounds, &bounds)) { 67 if (!this->applyCropRect(ctx, srcBounds, &bounds)) {
67 return nullptr; 68 return false;
68 } 69 }
69 70
70 SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(), kPr emul_SkAlphaType); 71 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds .height()));
71 sk_sp<SkSpecialSurface> surf(source->makeSurface(info)); 72 if (nullptr == device.get()) {
72 if (!surf) { 73 return false;
73 return nullptr;
74 } 74 }
75 75 SkCanvas canvas(device.get());
76 SkCanvas* canvas = surf->getCanvas();
77 SkASSERT(canvas);
78
79 // TODO: it seems like this clear shouldn't be necessary (see skbug.com/5075 )
80 canvas->clear(0x0);
81
82 SkPaint paint; 76 SkPaint paint;
83 77
84 paint.setXfermodeMode(SkXfermode::kSrc_Mode); 78 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
85 paint.setColorFilter(fColorFilter); 79 paint.setColorFilter(fColorFilter);
80 canvas.drawBitmap(src, SkIntToScalar(srcOffset.fX - bounds.fLeft),
81 SkIntToScalar(srcOffset.fY - bounds.fTop), &paint);
86 82
87 input->draw(canvas, 83 *result = device.get()->accessBitmap(false);
88 SkIntToScalar(inputOffset.fX - bounds.fLeft),
89 SkIntToScalar(inputOffset.fY - bounds.fTop),
90 &paint);
91
92 offset->fX = bounds.fLeft; 84 offset->fX = bounds.fLeft;
93 offset->fY = bounds.fTop; 85 offset->fY = bounds.fTop;
94 return surf->makeImageSnapshot().release(); 86 return true;
95 } 87 }
96 88
97 bool SkColorFilterImageFilter::onIsColorFilterNode(SkColorFilter** filter) const { 89 bool SkColorFilterImageFilter::onIsColorFilterNode(SkColorFilter** filter) const {
98 SkASSERT(1 == this->countInputs()); 90 SkASSERT(1 == this->countInputs());
99 if (!this->cropRectIsSet()) { 91 if (!this->cropRectIsSet()) {
100 if (filter) { 92 if (filter) {
101 *filter = SkRef(fColorFilter.get()); 93 *filter = SkRef(fColorFilter.get());
102 } 94 }
103 return true; 95 return true;
104 } 96 }
(...skipping 16 matching lines...) Expand all
121 if (this->getInput(0)) { 113 if (this->getInput(0)) {
122 this->getInput(0)->toString(str); 114 this->getInput(0)->toString(str);
123 } 115 }
124 116
125 str->appendf(") color filter: "); 117 str->appendf(") color filter: ");
126 fColorFilter->toString(str); 118 fColorFilter->toString(str);
127 119
128 str->append(")"); 120 str->append(")");
129 } 121 }
130 #endif 122 #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