blob: f1d5c26168c8eceec4e6fbdbf3e39736d8da35a7 [file] [log] [blame]
bsalomon@google.comaf84e742012-10-05 13:23:24 +00001/*
egdaniel8dd688b2015-01-22 10:16:09 -08002 * Copyright 2015 Google Inc.
bsalomon@google.comaf84e742012-10-05 13:23:24 +00003 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
egdaniel8dd688b2015-01-22 10:16:09 -08008#include "GrPipelineBuilder.h"
egdaniel3658f382014-09-15 07:01:59 -07009
egdanielb1cff032014-11-13 06:19:25 -080010#include "GrBlend.h"
egdaniel3658f382014-09-15 07:01:59 -070011#include "GrPaint.h"
egdaniel8dd688b2015-01-22 10:16:09 -080012#include "GrPipeline.h"
egdanielb6cbc382014-11-13 11:00:34 -080013#include "GrProcOptInfo.h"
egdaniel378092f2014-12-03 10:40:13 -080014#include "GrXferProcessor.h"
joshualitt74417822015-08-07 11:42:16 -070015#include "batches/GrBatch.h"
egdaniel378092f2014-12-03 10:40:13 -080016#include "effects/GrPorterDuffXferProcessor.h"
egdaniel3658f382014-09-15 07:01:59 -070017
egdaniel8dd688b2015-01-22 10:16:09 -080018GrPipelineBuilder::GrPipelineBuilder()
joshualittaf2533a2015-09-09 10:00:12 -070019 : fFlags(0x0), fDrawFace(kBoth_DrawFace) {
joshualitt2fdeda02015-01-22 07:11:44 -080020 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
egdaniel89af44a2014-09-26 06:15:04 -070021}
22
joshualitt7b670db2015-07-09 13:25:02 -070023GrPipelineBuilder::GrPipelineBuilder(const GrPaint& paint, GrRenderTarget* rt, const GrClip& clip) {
24 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
bsalomon@google.comeb6879f2013-06-13 19:34:18 +000025
bsalomonac856c92015-08-27 06:30:17 -070026 for (int i = 0; i < paint.numColorFragmentProcessors(); ++i) {
27 fColorFragmentProcessors.push_back(SkRef(paint.getColorFragmentProcessor(i)));
bsalomon@google.comaf84e742012-10-05 13:23:24 +000028 }
29
bsalomonac856c92015-08-27 06:30:17 -070030 for (int i = 0; i < paint.numCoverageFragmentProcessors(); ++i) {
31 fCoverageFragmentProcessors.push_back(SkRef(paint.getCoverageFragmentProcessor(i)));
bsalomon@google.comaf84e742012-10-05 13:23:24 +000032 }
33
egdanielc4b72722015-11-23 13:20:41 -080034 fXPFactory.reset(SkSafeRef(paint.getXPFactory()));
egdaniel378092f2014-12-03 10:40:13 -080035
commit-bot@chromium.orgbb6a3172013-05-28 17:25:49 +000036 this->setRenderTarget(rt);
bsalomon@google.comaf84e742012-10-05 13:23:24 +000037
commit-bot@chromium.orgbb6a3172013-05-28 17:25:49 +000038 // These have no equivalent in GrPaint, set them to defaults
bsalomon2ed5ef82014-07-07 08:44:05 -070039 fDrawFace = kBoth_DrawFace;
40 fStencilSettings.setDisabled();
bsalomond79c5492015-04-27 10:07:04 -070041 fFlags = 0;
commit-bot@chromium.orgbb6a3172013-05-28 17:25:49 +000042
joshualitt570d2f82015-02-25 13:19:48 -080043 fClip = clip;
bsalomon@google.com21c10c52013-06-13 17:44:07 +000044
bsalomond79c5492015-04-27 10:07:04 -070045 this->setState(GrPipelineBuilder::kHWAntialias_Flag,
vbuzinovdded6962015-06-12 08:59:45 -070046 rt->isUnifiedMultisampled() && paint.isAntiAlias());
bsalomon@google.comaf84e742012-10-05 13:23:24 +000047}
bsalomon@google.com5b3e8902012-10-05 20:13:28 +000048
egdaniel21aed572014-08-26 12:24:06 -070049//////////////////////////////////////////////////////////////////////////////s
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000050
bsalomon6a44c6a2015-05-26 09:49:05 -070051bool GrPipelineBuilder::willXPNeedDstTexture(const GrCaps& caps,
ethannicholasde4166a2015-11-30 08:57:38 -080052 const GrPipelineOptimizations& optimizations) const {
egdanielc4b72722015-11-23 13:20:41 -080053 if (this->getXPFactory()) {
ethannicholasde4166a2015-11-30 08:57:38 -080054 return this->getXPFactory()->willNeedDstTexture(caps, optimizations,
egdanielc4b72722015-11-23 13:20:41 -080055 this->hasMixedSamples());
56 }
ethannicholasde4166a2015-11-30 08:57:38 -080057 return GrPorterDuffXPFactory::SrcOverWillNeedDstTexture(caps, optimizations,
egdanielc4b72722015-11-23 13:20:41 -080058 this->hasMixedSamples());
egdaniel89af44a2014-09-26 06:15:04 -070059}
60
joshualitt4421a4c2015-07-13 09:36:41 -070061void GrPipelineBuilder::AutoRestoreFragmentProcessorState::set(
joshualitt5e6ba212015-07-13 07:35:05 -070062 const GrPipelineBuilder* pipelineBuilder) {
egdaniel8dd688b2015-01-22 10:16:09 -080063 if (fPipelineBuilder) {
bsalomonac856c92015-08-27 06:30:17 -070064 int m = fPipelineBuilder->numColorFragmentProcessors() - fColorEffectCnt;
egdaniel21aed572014-08-26 12:24:06 -070065 SkASSERT(m >= 0);
bsalomonac856c92015-08-27 06:30:17 -070066 for (int i = 0; i < m; ++i) {
67 fPipelineBuilder->fColorFragmentProcessors.fromBack(i)->unref();
68 }
69 fPipelineBuilder->fColorFragmentProcessors.pop_back_n(m);
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000070
bsalomonac856c92015-08-27 06:30:17 -070071 int n = fPipelineBuilder->numCoverageFragmentProcessors() - fCoverageEffectCnt;
egdaniel21aed572014-08-26 12:24:06 -070072 SkASSERT(n >= 0);
bsalomonac856c92015-08-27 06:30:17 -070073 for (int i = 0; i < n; ++i) {
74 fPipelineBuilder->fCoverageFragmentProcessors.fromBack(i)->unref();
75 }
76 fPipelineBuilder->fCoverageFragmentProcessors.pop_back_n(n);
egdaniel8dd688b2015-01-22 10:16:09 -080077 SkDEBUGCODE(--fPipelineBuilder->fBlockEffectRemovalCnt;)
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000078 }
joshualitt5e6ba212015-07-13 07:35:05 -070079 fPipelineBuilder = const_cast<GrPipelineBuilder*>(pipelineBuilder);
halcanary96fcdcc2015-08-27 07:41:13 -070080 if (nullptr != pipelineBuilder) {
bsalomonac856c92015-08-27 06:30:17 -070081 fColorEffectCnt = pipelineBuilder->numColorFragmentProcessors();
82 fCoverageEffectCnt = pipelineBuilder->numCoverageFragmentProcessors();
egdaniel8dd688b2015-01-22 10:16:09 -080083 SkDEBUGCODE(++pipelineBuilder->fBlockEffectRemovalCnt;)
egdaniel21aed572014-08-26 12:24:06 -070084 }
bsalomon@google.comd62e88e2013-02-01 14:19:27 +000085}
86
jvanverth@google.comcc782382013-01-28 20:39:48 +000087////////////////////////////////////////////////////////////////////////////////
88
egdaniel8dd688b2015-01-22 10:16:09 -080089GrPipelineBuilder::~GrPipelineBuilder() {
egdaniel170f90b2014-09-16 12:54:40 -070090 SkASSERT(0 == fBlockEffectRemovalCnt);
bsalomonac856c92015-08-27 06:30:17 -070091 for (int i = 0; i < fColorFragmentProcessors.count(); ++i) {
92 fColorFragmentProcessors[i]->unref();
93 }
94 for (int i = 0; i < fCoverageFragmentProcessors.count(); ++i) {
95 fCoverageFragmentProcessors[i]->unref();
96 }
egdaniel170f90b2014-09-16 12:54:40 -070097}