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

Side by Side Diff: src/gpu/GrFragmentProcessor.cpp

Issue 1368423003: Use child processors to implement compose color filter. (Closed) Base URL: https://skia.googlesource.com/skia.git@upm
Patch Set: Address comments Created 5 years, 2 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/effects/SkTableColorFilter.cpp ('k') | src/gpu/GrProcOptInfo.h » ('j') | 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 /* 2 /*
3 * Copyright 2015 Google Inc. 3 * Copyright 2015 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "GrFragmentProcessor.h" 9 #include "GrFragmentProcessor.h"
10 #include "GrCoordTransform.h" 10 #include "GrCoordTransform.h"
11 #include "gl/GrGLFragmentProcessor.h" 11 #include "gl/GrGLFragmentProcessor.h"
12 #include "gl/builders/GrGLProgramBuilder.h" 12 #include "gl/builders/GrGLProgramBuilder.h"
13 #include "effects/GrConstColorProcessor.h"
13 #include "effects/GrXfermodeFragmentProcessor.h" 14 #include "effects/GrXfermodeFragmentProcessor.h"
14 15
15 GrFragmentProcessor::~GrFragmentProcessor() { 16 GrFragmentProcessor::~GrFragmentProcessor() {
16 // If we got here then our ref count must have reached zero, so we will have converted refs 17 // If we got here then our ref count must have reached zero, so we will have converted refs
17 // to pending executions for all children. 18 // to pending executions for all children.
18 for (int i = 0; i < fChildProcessors.count(); ++i) { 19 for (int i = 0; i < fChildProcessors.count(); ++i) {
19 fChildProcessors[i]->completedExecution(); 20 fChildProcessors[i]->completedExecution();
20 } 21 }
21 } 22 }
22 23
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 }; 273 };
273 274
274 GrInvariantOutput childOut(0x0, kNone_GrColorComponentFlags, false); 275 GrInvariantOutput childOut(0x0, kNone_GrColorComponentFlags, false);
275 fp->computeInvariantOutput(&childOut); 276 fp->computeInvariantOutput(&childOut);
276 if (childOut.willUseInputColor()) { 277 if (childOut.willUseInputColor()) {
277 return new ReplaceInputFragmentProcessor(fp, color); 278 return new ReplaceInputFragmentProcessor(fp, color);
278 } else { 279 } else {
279 return SkRef(fp); 280 return SkRef(fp);
280 } 281 }
281 } 282 }
283
284 const GrFragmentProcessor* GrFragmentProcessor::RunInSeries(const GrFragmentProc essor* series[],
285 int cnt) {
286 class SeriesFragmentProcessor : public GrFragmentProcessor {
287 public:
288 SeriesFragmentProcessor(const GrFragmentProcessor* children[], int cnt){
289 SkASSERT(cnt > 1);
290 this->initClassID<SeriesFragmentProcessor>();
291 for (int i = 0; i < cnt; ++i) {
292 this->registerChildProcessor(children[i]);
293 }
294 }
295
296 const char* name() const override { return "Series"; }
297
298 GrGLFragmentProcessor* onCreateGLInstance() const override {
299 class GLFP : public GrGLFragmentProcessor {
300 public:
301 GLFP() {}
302 void emitCode(EmitArgs& args) override {
303 SkString input(args.fInputColor);
304 for (int i = 0; i < this->numChildProcessors() - 1; ++i) {
305 SkString temp;
306 temp.printf("out%d", i);
307 this->emitChild(i, input.c_str(), &temp, args);
308 input = temp;
309 }
310 // Last guy writes to our output variable.
311 this->emitChild(this->numChildProcessors() - 1, input.c_str( ), args);
312 }
313 };
314 return new GLFP;
315 }
316
317 private:
318 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) cons t override {}
319
320 bool onIsEqual(const GrFragmentProcessor&) const override { return true; }
321
322 void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
323 GrProcOptInfo info;
324 SkTDArray<const GrFragmentProcessor*> children;
325 children.setCount(this->numChildProcessors());
326 for (int i = 0; i < children.count(); ++i) {
327 children[i] = &this->childProcessor(i);
328 }
329 info.calcWithInitialValues(children.begin(), children.count(), inout ->color(),
330 inout->validFlags(), false, false);
331 for (int i = 0; i < this->numChildProcessors(); ++i) {
332 this->childProcessor(i).computeInvariantOutput(inout);
333 }
334 }
335 };
336
337 if (!cnt) {
338 return nullptr;
339 }
340
341 // Run the through the series, do the invariant output processing, and look for eliminations.
342 SkTDArray<const GrFragmentProcessor*> replacementSeries;
343 SkAutoTUnref<const GrFragmentProcessor> colorFP;
344 GrProcOptInfo info;
345
346 info.calcWithInitialValues(series, cnt, 0x0, kNone_GrColorComponentFlags, fa lse, false);
347 if (kRGBA_GrColorComponentFlags == info.validFlags()) {
348 return GrConstColorProcessor::Create(info.color(),
349 GrConstColorProcessor::kIgnore_Inpu tMode);
350 } else {
351 int firstIdx = info.firstEffectiveProcessorIndex();
352 cnt -= firstIdx;
353 if (firstIdx > 0 && info.inputColorIsUsed()) {
354 colorFP.reset(GrConstColorProcessor::Create(info.inputColorToFirstEf fectiveProccesor(),
355 GrConstColorProcessor::k Ignore_InputMode));
356 cnt += 1;
357 replacementSeries.setCount(cnt);
358 replacementSeries[0] = colorFP;
359 for (int i = 0; i < cnt - 1; ++i) {
360 replacementSeries[i + 1] = series[firstIdx + i];
361 }
362 series = replacementSeries.begin();
363 } else {
364 series += firstIdx;
365 cnt -= firstIdx;
366 }
367 }
368
369 if (1 == cnt) {
370 return SkRef(series[0]);
371 } else {
372 return new SeriesFragmentProcessor(series, cnt);
373 }
374 }
375
OLDNEW
« no previous file with comments | « src/effects/SkTableColorFilter.cpp ('k') | src/gpu/GrProcOptInfo.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698