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

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

Issue 1763223002: Switch SkMergeImageFilter over to new onFilterImage interface (Closed) Base URL: https://skia.googlesource.com/skia.git@if-follow-on
Patch Set: Address code review comments 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/SkMergeImageFilter.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 "SkMergeImageFilter.h" 8 #include "SkMergeImageFilter.h"
9
9 #include "SkCanvas.h" 10 #include "SkCanvas.h"
10 #include "SkDevice.h"
11 #include "SkReadBuffer.h" 11 #include "SkReadBuffer.h"
12 #include "SkSpecialImage.h"
13 #include "SkSpecialSurface.h"
12 #include "SkWriteBuffer.h" 14 #include "SkWriteBuffer.h"
13 #include "SkValidationUtils.h" 15 #include "SkValidationUtils.h"
14 16
15 /////////////////////////////////////////////////////////////////////////////// 17 ///////////////////////////////////////////////////////////////////////////////
16 18
17 void SkMergeImageFilter::initAllocModes() { 19 void SkMergeImageFilter::initAllocModes() {
18 int inputCount = this->countInputs(); 20 int inputCount = this->countInputs();
19 if (inputCount) { 21 if (inputCount) {
20 size_t size = sizeof(uint8_t) * inputCount; 22 size_t size = sizeof(uint8_t) * inputCount;
21 if (size <= sizeof(fStorage)) { 23 if (size <= sizeof(fStorage)) {
(...skipping 26 matching lines...) Expand all
48 this->initModes(modes); 50 this->initModes(modes);
49 } 51 }
50 52
51 SkMergeImageFilter::~SkMergeImageFilter() { 53 SkMergeImageFilter::~SkMergeImageFilter() {
52 54
53 if (fModes != SkTCast<uint8_t*>(fStorage)) { 55 if (fModes != SkTCast<uint8_t*>(fStorage)) {
54 sk_free(fModes); 56 sk_free(fModes);
55 } 57 }
56 } 58 }
57 59
58 bool SkMergeImageFilter::onFilterImageDeprecated(Proxy* proxy, const SkBitmap& s rc, 60 SkSpecialImage* SkMergeImageFilter::onFilterImage(SkSpecialImage* source, const Context& ctx,
59 const Context& ctx, 61 SkIPoint* offset) const {
60 SkBitmap* result, SkIPoint* off set) const {
61 int inputCount = this->countInputs(); 62 int inputCount = this->countInputs();
62 if (inputCount < 1) { 63 if (inputCount < 1) {
63 return false; 64 return nullptr;
64 } 65 }
65 66
66 SkIRect bounds; 67 SkIRect bounds;
68 bounds.setEmpty();
67 69
68 SkAutoTDeleteArray<SkBitmap> inputs(new SkBitmap[inputCount]); 70 SkAutoTDeleteArray<SkAutoTUnref<SkSpecialImage>> inputs(
71 new SkAutoTUnref<SkSpecialIm age>[inputCount]);
Stephen White 2016/03/08 16:04:03 Nit: spacing is slightly weird here.
69 SkAutoTDeleteArray<SkIPoint> offsets(new SkIPoint[inputCount]); 72 SkAutoTDeleteArray<SkIPoint> offsets(new SkIPoint[inputCount]);
70 bool didProduceResult = false;
71 73
72 // Filter all of the inputs. 74 // Filter all of the inputs.
73 for (int i = 0; i < inputCount; ++i) { 75 for (int i = 0; i < inputCount; ++i) {
74 inputs[i] = src;
75 offsets[i].setZero(); 76 offsets[i].setZero();
76 if (!this->filterInputDeprecated(i, proxy, src, ctx, &inputs[i], &offset s[i])) { 77 inputs[i].reset(this->filterInput(i, source, ctx, &offsets[i]));
77 inputs[i].reset(); 78 if (!inputs[i]) {
78 continue; 79 continue;
79 } 80 }
80 SkIRect srcBounds; 81 const SkIRect inputBounds = SkIRect::MakeXYWH(offsets[i].fX, offsets[i]. fY,
81 inputs[i].getBounds(&srcBounds); 82 inputs[i]->width(), inputs [i]->height());
82 srcBounds.offset(offsets[i]); 83 bounds.join(inputBounds);
83 if (!didProduceResult) {
84 bounds = srcBounds;
85 didProduceResult = true;
86 } else {
87 bounds.join(srcBounds);
88 }
89 } 84 }
90 if (!didProduceResult) { 85 if (bounds.isEmpty()) {
91 return false; 86 return nullptr;
92 } 87 }
93 88
94 // Apply the crop rect to the union of the inputs' bounds. 89 // Apply the crop rect to the union of the inputs' bounds.
95 this->getCropRect().applyTo(bounds, ctx.ctm(), &bounds); 90 this->getCropRect().applyTo(bounds, ctx.ctm(), &bounds);
96 if (!bounds.intersect(ctx.clipBounds())) { 91 if (!bounds.intersect(ctx.clipBounds())) {
97 return false; 92 return nullptr;
98 } 93 }
99 94
100 const int x0 = bounds.left(); 95 const int x0 = bounds.left();
101 const int y0 = bounds.top(); 96 const int y0 = bounds.top();
102 97
103 // Allocate the destination buffer. 98 SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(),
104 SkAutoTUnref<SkBaseDevice> dst(proxy->createDevice(bounds.width(), bounds.he ight())); 99 kPremul_SkAlphaType);
105 if (nullptr == dst) { 100
106 return false; 101 SkAutoTUnref<SkSpecialSurface> surf(source->newSurface(info));
102 if (!surf) {
103 return nullptr;
107 } 104 }
108 SkCanvas canvas(dst); 105
106 SkCanvas* canvas = surf->getCanvas();
107 SkASSERT(canvas);
108
109 canvas->clear(0x0);
109 110
110 // Composite all of the filter inputs. 111 // Composite all of the filter inputs.
111 for (int i = 0; i < inputCount; ++i) { 112 for (int i = 0; i < inputCount; ++i) {
113 if (!inputs[i]) {
114 continue;
115 }
116
112 SkPaint paint; 117 SkPaint paint;
113 if (fModes) { 118 if (fModes) {
114 paint.setXfermodeMode((SkXfermode::Mode)fModes[i]); 119 paint.setXfermodeMode((SkXfermode::Mode)fModes[i]);
115 } 120 }
116 canvas.drawBitmap(inputs[i], SkIntToScalar(offsets[i].x() - x0), 121
117 SkIntToScalar(offsets[i].y() - y0), &paint) ; 122 inputs[i]->draw(canvas,
123 SkIntToScalar(offsets[i].x() - x0), SkIntToScalar(offset s[i].y() - y0),
124 &paint);
118 } 125 }
119 126
120 offset->fX = bounds.left(); 127 offset->fX = bounds.left();
121 offset->fY = bounds.top(); 128 offset->fY = bounds.top();
122 *result = dst->accessBitmap(false); 129 return surf->newImageSnapshot();
123 return true;
124 } 130 }
125 131
126 SkFlattenable* SkMergeImageFilter::CreateProc(SkReadBuffer& buffer) { 132 SkFlattenable* SkMergeImageFilter::CreateProc(SkReadBuffer& buffer) {
127 Common common; 133 Common common;
128 if (!common.unflatten(buffer, -1)) { 134 if (!common.unflatten(buffer, -1)) {
129 return nullptr; 135 return nullptr;
130 } 136 }
131 137
132 const int count = common.inputCount(); 138 const int count = common.inputCount();
133 bool hasModes = buffer.readBool(); 139 bool hasModes = buffer.readBool();
(...skipping 30 matching lines...) Expand all
164 for (int i = 0; i < this->countInputs(); ++i) { 170 for (int i = 0; i < this->countInputs(); ++i) {
165 SkImageFilter* filter = this->getInput(i); 171 SkImageFilter* filter = this->getInput(i);
166 str->appendf("%d: (", i); 172 str->appendf("%d: (", i);
167 filter->toString(str); 173 filter->toString(str);
168 str->appendf(")"); 174 str->appendf(")");
169 } 175 }
170 176
171 str->append(")"); 177 str->append(")");
172 } 178 }
173 #endif 179 #endif
OLDNEW
« no previous file with comments | « include/effects/SkMergeImageFilter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698