| 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 "GrPipeline.h" | 8 #include "GrPipeline.h" |
| 9 | 9 |
| 10 #include "GrCaps.h" | 10 #include "GrCaps.h" |
| 11 #include "GrRenderTargetContext.h" | 11 #include "GrRenderTargetContext.h" |
| 12 #include "GrGpu.h" | 12 #include "GrGpu.h" |
| 13 #include "GrPipelineBuilder.h" | 13 #include "GrPipelineBuilder.h" |
| 14 #include "GrProcOptInfo.h" | 14 #include "GrProcOptInfo.h" |
| 15 #include "GrRenderTargetOpList.h" | 15 #include "GrRenderTargetOpList.h" |
| 16 #include "GrRenderTargetPriv.h" | 16 #include "GrRenderTargetPriv.h" |
| 17 #include "GrXferProcessor.h" | 17 #include "GrXferProcessor.h" |
| 18 | 18 |
| 19 #include "batches/GrBatch.h" | 19 #include "batches/GrBatch.h" |
| 20 | 20 |
| 21 GrPipeline* GrPipeline::CreateAt(void* memory, const CreateArgs& args, | 21 GrPipeline* GrPipeline::CreateAt(void* memory, const CreateArgs& args, |
| 22 GrXPOverridesForBatch* overrides) { | 22 GrXPOverridesForBatch* overrides) { |
| 23 const GrPipelineBuilder& builder = *args.fPipelineBuilder; | 23 const GrPipelineBuilder& builder = *args.fPipelineBuilder; |
| 24 const GrUserStencilSettings* userStencil = builder.getUserStencil(); |
| 25 GrRenderTarget* rt = args.fRenderTargetContext->accessRenderTarget(); |
| 24 | 26 |
| 25 GrPipeline* pipeline = new (memory) GrPipeline; | 27 GrPipeline* pipeline = new (memory) GrPipeline; |
| 26 GrRenderTarget* rt = args.fRenderTargetContext->accessRenderTarget(); | |
| 27 pipeline->fRenderTarget.reset(rt); | 28 pipeline->fRenderTarget.reset(rt); |
| 28 SkASSERT(pipeline->fRenderTarget); | 29 SkASSERT(pipeline->fRenderTarget); |
| 29 pipeline->fScissorState = *args.fScissor; | 30 pipeline->fScissorState = *args.fScissor; |
| 30 pipeline->fWindowRectsState = *args.fWindowRectsState; | 31 pipeline->fWindowRectsState = *args.fWindowRectsState; |
| 31 if (builder.hasUserStencilSettings() || args.fHasStencilClip) { | 32 pipeline->fUserStencilSettings = userStencil; |
| 32 const GrRenderTargetPriv& rtPriv = rt->renderTargetPriv(); | |
| 33 pipeline->fStencilSettings.reset(*builder.getUserStencil(), args.fHasSte
ncilClip, | |
| 34 rtPriv.numStencilBits()); | |
| 35 SkASSERT(!pipeline->fStencilSettings.usesWrapOp() || args.fCaps->stencil
WrapOpsSupport()); | |
| 36 } | |
| 37 pipeline->fDrawFace = builder.getDrawFace(); | 33 pipeline->fDrawFace = builder.getDrawFace(); |
| 38 | 34 |
| 39 pipeline->fFlags = 0; | 35 pipeline->fFlags = 0; |
| 40 if (builder.isHWAntialias()) { | 36 if (builder.isHWAntialias()) { |
| 41 pipeline->fFlags |= kHWAA_Flag; | 37 pipeline->fFlags |= kHWAA_Flag; |
| 42 } | 38 } |
| 43 if (builder.snapVerticesToPixelCenters()) { | 39 if (builder.snapVerticesToPixelCenters()) { |
| 44 pipeline->fFlags |= kSnapVertices_Flag; | 40 pipeline->fFlags |= kSnapVertices_Flag; |
| 45 } | 41 } |
| 46 if (builder.getDisableOutputConversionToSRGB()) { | 42 if (builder.getDisableOutputConversionToSRGB()) { |
| 47 pipeline->fFlags |= kDisableOutputConversionToSRGB_Flag; | 43 pipeline->fFlags |= kDisableOutputConversionToSRGB_Flag; |
| 48 } | 44 } |
| 49 if (builder.getAllowSRGBInputs()) { | 45 if (builder.getAllowSRGBInputs()) { |
| 50 pipeline->fFlags |= kAllowSRGBInputs_Flag; | 46 pipeline->fFlags |= kAllowSRGBInputs_Flag; |
| 51 } | 47 } |
| 52 if (builder.getUsesDistanceVectorField()) { | 48 if (builder.getUsesDistanceVectorField()) { |
| 53 pipeline->fFlags |= kUsesDistanceVectorField_Flag; | 49 pipeline->fFlags |= kUsesDistanceVectorField_Flag; |
| 54 } | 50 } |
| 55 if (args.fHasStencilClip) { | 51 if (args.fHasStencilClip) { |
| 56 pipeline->fFlags |= kHasStencilClip_Flag; | 52 pipeline->fFlags |= kHasStencilClip_Flag; |
| 57 } | 53 } |
| 54 if (!userStencil->isDisabled(args.fHasStencilClip)) { |
| 55 pipeline->fFlags |= kStencilEnabled_Flag; |
| 56 } |
| 58 | 57 |
| 59 // Create XferProcessor from DS's XPFactory | 58 // Create XferProcessor from DS's XPFactory |
| 60 bool hasMixedSamples = args.fRenderTargetContext->hasMixedSamples() && | 59 bool hasMixedSamples = args.fRenderTargetContext->hasMixedSamples() && |
| 61 (builder.isHWAntialias() || !pipeline->fStencilSettin
gs.isDisabled()); | 60 (builder.isHWAntialias() || pipeline->isStencilEnable
d()); |
| 62 const GrXPFactory* xpFactory = builder.getXPFactory(); | 61 const GrXPFactory* xpFactory = builder.getXPFactory(); |
| 63 SkAutoTUnref<GrXferProcessor> xferProcessor; | 62 SkAutoTUnref<GrXferProcessor> xferProcessor; |
| 64 if (xpFactory) { | 63 if (xpFactory) { |
| 65 xferProcessor.reset(xpFactory->createXferProcessor(args.fOpts, | 64 xferProcessor.reset(xpFactory->createXferProcessor(args.fOpts, |
| 66 hasMixedSamples, | 65 hasMixedSamples, |
| 67 &args.fDstTexture, | 66 &args.fDstTexture, |
| 68 *args.fCaps)); | 67 *args.fCaps)); |
| 69 if (!xferProcessor) { | 68 if (!xferProcessor) { |
| 70 pipeline->~GrPipeline(); | 69 pipeline->~GrPipeline(); |
| 71 return nullptr; | 70 return nullptr; |
| 72 } | 71 } |
| 73 } else { | 72 } else { |
| 74 // This may return nullptr in the common case of src-over implemented us
ing hw blending. | 73 // This may return nullptr in the common case of src-over implemented us
ing hw blending. |
| 75 xferProcessor.reset(GrPorterDuffXPFactory::CreateSrcOverXferProcessor( | 74 xferProcessor.reset(GrPorterDuffXPFactory::CreateSrcOverXferProcessor( |
| 76 *args.fC
aps, | 75 *args.fC
aps, |
| 77 args.fOp
ts, | 76 args.fOp
ts, |
| 78 hasMixed
Samples, | 77 hasMixed
Samples, |
| 79 &args.fD
stTexture)); | 78 &args.fD
stTexture)); |
| 80 } | 79 } |
| 81 GrColor overrideColor = GrColor_ILLEGAL; | 80 GrColor overrideColor = GrColor_ILLEGAL; |
| 82 if (args.fOpts.fColorPOI.firstEffectiveProcessorIndex() != 0) { | 81 if (args.fOpts.fColorPOI.firstEffectiveProcessorIndex() != 0) { |
| 83 overrideColor = args.fOpts.fColorPOI.inputColorToFirstEffectiveProccesor
(); | 82 overrideColor = args.fOpts.fColorPOI.inputColorToFirstEffectiveProccesor
(); |
| 84 } | 83 } |
| 85 | 84 |
| 86 GrXferProcessor::OptFlags optFlags = GrXferProcessor::kNone_OptFlags; | 85 GrXferProcessor::OptFlags optFlags = GrXferProcessor::kNone_OptFlags; |
| 87 | 86 |
| 88 const GrXferProcessor* xpForOpts = xferProcessor ? xferProcessor.get() : | 87 const GrXferProcessor* xpForOpts = xferProcessor ? xferProcessor.get() : |
| 89 &GrPorterDuffXPFactory::S
impleSrcOverXP(); | 88 &GrPorterDuffXPFactory::S
impleSrcOverXP(); |
| 90 optFlags = xpForOpts->getOptimizations(args.fOpts, | 89 optFlags = xpForOpts->getOptimizations(args.fOpts, |
| 91 pipeline->fStencilSettings.doesWrite(
), | 90 userStencil->doesWrite(args.fHasStenc
ilClip), |
| 92 &overrideColor, | 91 &overrideColor, |
| 93 *args.fCaps); | 92 *args.fCaps); |
| 94 | 93 |
| 95 // When path rendering the stencil settings are not always set on the GrPipe
lineBuilder | 94 // When path rendering the stencil settings are not always set on the GrPipe
lineBuilder |
| 96 // so we must check the draw type. In cases where we will skip drawing we si
mply return a | 95 // so we must check the draw type. In cases where we will skip drawing we si
mply return a |
| 97 // null GrPipeline. | 96 // null GrPipeline. |
| 98 if (GrXferProcessor::kSkipDraw_OptFlag & optFlags) { | 97 if (GrXferProcessor::kSkipDraw_OptFlag & optFlags) { |
| 99 pipeline->~GrPipeline(); | 98 pipeline->~GrPipeline(); |
| 100 return nullptr; | 99 return nullptr; |
| 101 } | 100 } |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 | 218 |
| 220 bool GrPipeline::AreEqual(const GrPipeline& a, const GrPipeline& b) { | 219 bool GrPipeline::AreEqual(const GrPipeline& a, const GrPipeline& b) { |
| 221 SkASSERT(&a != &b); | 220 SkASSERT(&a != &b); |
| 222 | 221 |
| 223 if (a.getRenderTarget() != b.getRenderTarget() || | 222 if (a.getRenderTarget() != b.getRenderTarget() || |
| 224 a.fFragmentProcessors.count() != b.fFragmentProcessors.count() || | 223 a.fFragmentProcessors.count() != b.fFragmentProcessors.count() || |
| 225 a.fNumColorProcessors != b.fNumColorProcessors || | 224 a.fNumColorProcessors != b.fNumColorProcessors || |
| 226 a.fScissorState != b.fScissorState || | 225 a.fScissorState != b.fScissorState || |
| 227 !a.fWindowRectsState.cheapEqualTo(b.fWindowRectsState) || | 226 !a.fWindowRectsState.cheapEqualTo(b.fWindowRectsState) || |
| 228 a.fFlags != b.fFlags || | 227 a.fFlags != b.fFlags || |
| 229 a.fStencilSettings != b.fStencilSettings || | 228 a.fUserStencilSettings != b.fUserStencilSettings || |
| 230 a.fDrawFace != b.fDrawFace || | 229 a.fDrawFace != b.fDrawFace || |
| 231 a.fIgnoresCoverage != b.fIgnoresCoverage) { | 230 a.fIgnoresCoverage != b.fIgnoresCoverage) { |
| 232 return false; | 231 return false; |
| 233 } | 232 } |
| 234 | 233 |
| 235 // Most of the time both are nullptr | 234 // Most of the time both are nullptr |
| 236 if (a.fXferProcessor.get() || b.fXferProcessor.get()) { | 235 if (a.fXferProcessor.get() || b.fXferProcessor.get()) { |
| 237 if (!a.getXferProcessor().isEqual(b.getXferProcessor())) { | 236 if (!a.getXferProcessor().isEqual(b.getXferProcessor())) { |
| 238 return false; | 237 return false; |
| 239 } | 238 } |
| 240 } | 239 } |
| 241 | 240 |
| 242 for (int i = 0; i < a.numFragmentProcessors(); i++) { | 241 for (int i = 0; i < a.numFragmentProcessors(); i++) { |
| 243 if (!a.getFragmentProcessor(i).isEqual(b.getFragmentProcessor(i))) { | 242 if (!a.getFragmentProcessor(i).isEqual(b.getFragmentProcessor(i))) { |
| 244 return false; | 243 return false; |
| 245 } | 244 } |
| 246 } | 245 } |
| 247 return true; | 246 return true; |
| 248 } | 247 } |
| OLD | NEW |