1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2014 Google Inc. 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci 8cb93a386Sopenharmony_ci#include "src/gpu/GrCaps.h" 9cb93a386Sopenharmony_ci#include "src/gpu/GrFragmentProcessor.h" 10cb93a386Sopenharmony_ci#include "src/gpu/GrGeometryProcessor.h" 11cb93a386Sopenharmony_ci#include "src/gpu/GrProcessorAnalysis.h" 12cb93a386Sopenharmony_ci 13cb93a386Sopenharmony_ciGrColorFragmentProcessorAnalysis::GrColorFragmentProcessorAnalysis( 14cb93a386Sopenharmony_ci const GrProcessorAnalysisColor& input, 15cb93a386Sopenharmony_ci std::unique_ptr<GrFragmentProcessor> const fps[], 16cb93a386Sopenharmony_ci int count) { 17cb93a386Sopenharmony_ci fCompatibleWithCoverageAsAlpha = true; 18cb93a386Sopenharmony_ci fIsOpaque = input.isOpaque(); 19cb93a386Sopenharmony_ci fUsesLocalCoords = false; 20cb93a386Sopenharmony_ci fWillReadDstColor = false; 21cb93a386Sopenharmony_ci fProcessorsToEliminate = 0; 22cb93a386Sopenharmony_ci fOutputColorKnown = input.isConstant(&fLastKnownOutputColor); 23cb93a386Sopenharmony_ci for (int i = 0; i < count; ++i) { 24cb93a386Sopenharmony_ci const GrFragmentProcessor* fp = fps[i].get(); 25cb93a386Sopenharmony_ci if (fOutputColorKnown && fp->hasConstantOutputForConstantInput(fLastKnownOutputColor, 26cb93a386Sopenharmony_ci &fLastKnownOutputColor)) { 27cb93a386Sopenharmony_ci ++fProcessorsToEliminate; 28cb93a386Sopenharmony_ci fIsOpaque = fLastKnownOutputColor.isOpaque(); 29cb93a386Sopenharmony_ci // We reset these flags since the earlier fragment processors are being eliminated. 30cb93a386Sopenharmony_ci fCompatibleWithCoverageAsAlpha = true; 31cb93a386Sopenharmony_ci fUsesLocalCoords = false; 32cb93a386Sopenharmony_ci fWillReadDstColor = false; 33cb93a386Sopenharmony_ci continue; 34cb93a386Sopenharmony_ci } 35cb93a386Sopenharmony_ci 36cb93a386Sopenharmony_ci fOutputColorKnown = false; 37cb93a386Sopenharmony_ci if (fIsOpaque && !fp->preservesOpaqueInput()) { 38cb93a386Sopenharmony_ci fIsOpaque = false; 39cb93a386Sopenharmony_ci } 40cb93a386Sopenharmony_ci if (fCompatibleWithCoverageAsAlpha && !fp->compatibleWithCoverageAsAlpha()) { 41cb93a386Sopenharmony_ci fCompatibleWithCoverageAsAlpha = false; 42cb93a386Sopenharmony_ci } 43cb93a386Sopenharmony_ci if (fp->usesSampleCoords()) { 44cb93a386Sopenharmony_ci fUsesLocalCoords = true; 45cb93a386Sopenharmony_ci } 46cb93a386Sopenharmony_ci if (fp->willReadDstColor()) { 47cb93a386Sopenharmony_ci fWillReadDstColor = true; 48cb93a386Sopenharmony_ci } 49cb93a386Sopenharmony_ci } 50cb93a386Sopenharmony_ci} 51cb93a386Sopenharmony_ci 52cb93a386Sopenharmony_cibool GrColorFragmentProcessorAnalysis::requiresDstTexture(const GrCaps& caps) const { 53cb93a386Sopenharmony_ci return this->willReadDstColor() && !caps.shaderCaps()->dstReadInShaderSupport(); 54cb93a386Sopenharmony_ci} 55