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

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

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

Powered by Google App Engine
This is Rietveld 408576698