OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
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 "GrPipelineBuilder.h" | 8 #include "GrPipelineBuilder.h" |
9 | 9 |
10 #include "GrBlend.h" | 10 #include "GrBlend.h" |
11 #include "GrPaint.h" | 11 #include "GrPaint.h" |
12 #include "GrPipeline.h" | 12 #include "GrPipeline.h" |
13 #include "GrProcOptInfo.h" | 13 #include "GrProcOptInfo.h" |
14 #include "GrXferProcessor.h" | 14 #include "GrXferProcessor.h" |
15 #include "batches/GrBatch.h" | 15 #include "batches/GrBatch.h" |
16 #include "effects/GrPorterDuffXferProcessor.h" | 16 #include "effects/GrPorterDuffXferProcessor.h" |
17 | 17 |
18 GrPipelineBuilder::GrPipelineBuilder() | 18 GrPipelineBuilder::GrPipelineBuilder() |
19 : fFlags(0x0) | 19 : fFlags(0x0) |
20 , fUserStencilSettings(&GrUserStencilSettings::kUnused) | 20 , fUserStencilSettings(&GrUserStencilSettings::kUnused) |
21 , fDrawFace(kBoth_DrawFace) { | 21 , fDrawFace(kBoth_DrawFace) { |
22 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 22 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
23 } | 23 } |
24 | 24 |
25 GrPipelineBuilder::GrPipelineBuilder(const GrPaint& paint, bool useHWAA) | 25 GrPipelineBuilder::GrPipelineBuilder(const GrPaint& paint, bool useHWAA) |
26 : GrPipelineBuilder() { | 26 : GrPipelineBuilder() { |
27 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 27 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
28 | 28 |
29 for (int i = 0; i < paint.numColorFragmentProcessors(); ++i) { | 29 for (int i = 0; i < paint.numColorFragmentProcessors(); ++i) { |
30 fColorFragmentProcessors.push_back(SkRef(paint.getColorFragmentProcessor
(i))); | 30 fColorFragmentProcessors.emplace_back(SkRef(paint.getColorFragmentProces
sor(i))); |
31 } | 31 } |
32 | 32 |
33 for (int i = 0; i < paint.numCoverageFragmentProcessors(); ++i) { | 33 for (int i = 0; i < paint.numCoverageFragmentProcessors(); ++i) { |
34 fCoverageFragmentProcessors.push_back(SkRef(paint.getCoverageFragmentPro
cessor(i))); | 34 fCoverageFragmentProcessors.emplace_back(SkRef(paint.getCoverageFragment
Processor(i))); |
35 } | 35 } |
36 | 36 |
37 fXPFactory.reset(SkSafeRef(paint.getXPFactory())); | 37 fXPFactory.reset(SkSafeRef(paint.getXPFactory())); |
38 | 38 |
39 this->setState(GrPipelineBuilder::kHWAntialias_Flag, useHWAA); | 39 this->setState(GrPipelineBuilder::kHWAntialias_Flag, useHWAA); |
40 this->setState(GrPipelineBuilder::kDisableOutputConversionToSRGB_Flag, | 40 this->setState(GrPipelineBuilder::kDisableOutputConversionToSRGB_Flag, |
41 paint.getDisableOutputConversionToSRGB()); | 41 paint.getDisableOutputConversionToSRGB()); |
42 this->setState(GrPipelineBuilder::kAllowSRGBInputs_Flag, | 42 this->setState(GrPipelineBuilder::kAllowSRGBInputs_Flag, |
43 paint.getAllowSRGBInputs()); | 43 paint.getAllowSRGBInputs()); |
44 } | 44 } |
45 | 45 |
46 //////////////////////////////////////////////////////////////////////////////s | 46 //////////////////////////////////////////////////////////////////////////////s |
47 | 47 |
48 bool GrPipelineBuilder::willXPNeedDstTexture(const GrCaps& caps, | 48 bool GrPipelineBuilder::willXPNeedDstTexture(const GrCaps& caps, |
49 const GrPipelineOptimizations& opti
mizations) const { | 49 const GrPipelineOptimizations& opti
mizations) const { |
50 if (this->getXPFactory()) { | 50 if (this->getXPFactory()) { |
51 return this->getXPFactory()->willNeedDstTexture(caps, optimizations); | 51 return this->getXPFactory()->willNeedDstTexture(caps, optimizations); |
52 } | 52 } |
53 return GrPorterDuffXPFactory::SrcOverWillNeedDstTexture(caps, optimizations)
; | 53 return GrPorterDuffXPFactory::SrcOverWillNeedDstTexture(caps, optimizations)
; |
54 } | 54 } |
55 | 55 |
56 void GrPipelineBuilder::AutoRestoreFragmentProcessorState::set( | 56 void GrPipelineBuilder::AutoRestoreFragmentProcessorState::set( |
57 const GrPipelineBuilder
* pipelineBuilder) { | 57 const GrPipelineBuilder
* pipelineBuilder) { |
58 if (fPipelineBuilder) { | 58 if (fPipelineBuilder) { |
59 int m = fPipelineBuilder->numColorFragmentProcessors() - fColorEffectCnt
; | 59 int m = fPipelineBuilder->numColorFragmentProcessors() - fColorEffectCnt
; |
60 SkASSERT(m >= 0); | 60 SkASSERT(m >= 0); |
61 for (int i = 0; i < m; ++i) { | |
62 fPipelineBuilder->fColorFragmentProcessors.fromBack(i)->unref(); | |
63 } | |
64 fPipelineBuilder->fColorFragmentProcessors.pop_back_n(m); | 61 fPipelineBuilder->fColorFragmentProcessors.pop_back_n(m); |
65 | 62 |
66 int n = fPipelineBuilder->numCoverageFragmentProcessors() - fCoverageEff
ectCnt; | 63 int n = fPipelineBuilder->numCoverageFragmentProcessors() - fCoverageEff
ectCnt; |
67 SkASSERT(n >= 0); | 64 SkASSERT(n >= 0); |
68 for (int i = 0; i < n; ++i) { | |
69 fPipelineBuilder->fCoverageFragmentProcessors.fromBack(i)->unref(); | |
70 } | |
71 fPipelineBuilder->fCoverageFragmentProcessors.pop_back_n(n); | 65 fPipelineBuilder->fCoverageFragmentProcessors.pop_back_n(n); |
| 66 |
72 SkDEBUGCODE(--fPipelineBuilder->fBlockEffectRemovalCnt;) | 67 SkDEBUGCODE(--fPipelineBuilder->fBlockEffectRemovalCnt;) |
73 } | 68 } |
74 fPipelineBuilder = const_cast<GrPipelineBuilder*>(pipelineBuilder); | 69 fPipelineBuilder = const_cast<GrPipelineBuilder*>(pipelineBuilder); |
75 if (nullptr != pipelineBuilder) { | 70 if (nullptr != pipelineBuilder) { |
76 fColorEffectCnt = pipelineBuilder->numColorFragmentProcessors(); | 71 fColorEffectCnt = pipelineBuilder->numColorFragmentProcessors(); |
77 fCoverageEffectCnt = pipelineBuilder->numCoverageFragmentProcessors(); | 72 fCoverageEffectCnt = pipelineBuilder->numCoverageFragmentProcessors(); |
78 SkDEBUGCODE(++pipelineBuilder->fBlockEffectRemovalCnt;) | 73 SkDEBUGCODE(++pipelineBuilder->fBlockEffectRemovalCnt;) |
79 } | 74 } |
80 } | 75 } |
81 | 76 |
82 //////////////////////////////////////////////////////////////////////////////// | 77 //////////////////////////////////////////////////////////////////////////////// |
83 | 78 |
84 GrPipelineBuilder::~GrPipelineBuilder() { | 79 GrPipelineBuilder::~GrPipelineBuilder() { |
85 SkASSERT(0 == fBlockEffectRemovalCnt); | 80 SkASSERT(0 == fBlockEffectRemovalCnt); |
86 for (int i = 0; i < fColorFragmentProcessors.count(); ++i) { | |
87 fColorFragmentProcessors[i]->unref(); | |
88 } | |
89 for (int i = 0; i < fCoverageFragmentProcessors.count(); ++i) { | |
90 fCoverageFragmentProcessors[i]->unref(); | |
91 } | |
92 } | 81 } |
OLD | NEW |