LCOV - code coverage report
Current view: top level - gfx/skia/skia/src/core - SkColorFilterShader.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 65 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 11 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright 2013 Google Inc.
       3             :  *
       4             :  * Use of this source code is governed by a BSD-style license that can be
       5             :  * found in the LICENSE file.
       6             :  */
       7             : 
       8             : #include "SkArenaAlloc.h"
       9             : #include "SkColorFilterShader.h"
      10             : #include "SkReadBuffer.h"
      11             : #include "SkWriteBuffer.h"
      12             : #include "SkShader.h"
      13             : #include "SkString.h"
      14             : 
      15             : #if SK_SUPPORT_GPU
      16             : #include "GrFragmentProcessor.h"
      17             : #endif
      18             : 
      19           0 : SkColorFilterShader::SkColorFilterShader(sk_sp<SkShader> shader, sk_sp<SkColorFilter> filter)
      20           0 :     : fShader(std::move(shader))
      21           0 :     , fFilter(std::move(filter))
      22             : {
      23           0 :     SkASSERT(fShader);
      24           0 :     SkASSERT(fFilter);
      25           0 : }
      26             : 
      27           0 : sk_sp<SkFlattenable> SkColorFilterShader::CreateProc(SkReadBuffer& buffer) {
      28           0 :     auto shader = buffer.readShader();
      29           0 :     auto filter = buffer.readColorFilter();
      30           0 :     if (!shader || !filter) {
      31           0 :         return nullptr;
      32             :     }
      33           0 :     return sk_make_sp<SkColorFilterShader>(shader, filter);
      34             : }
      35             : 
      36           0 : void SkColorFilterShader::flatten(SkWriteBuffer& buffer) const {
      37           0 :     buffer.writeFlattenable(fShader.get());
      38           0 :     buffer.writeFlattenable(fFilter.get());
      39           0 : }
      40             : 
      41           0 : uint32_t SkColorFilterShader::FilterShaderContext::getFlags() const {
      42           0 :     const SkColorFilterShader& filterShader = static_cast<const SkColorFilterShader&>(fShader);
      43             : 
      44           0 :     uint32_t shaderF = fShaderContext->getFlags();
      45           0 :     uint32_t filterF = filterShader.fFilter->getFlags();
      46             : 
      47             :     // If the filter does not support a given feature, but sure to clear the corresponding flag
      48             :     // in the shader flags.
      49             :     //
      50           0 :     if (!(filterF & SkColorFilter::kAlphaUnchanged_Flag)) {
      51           0 :         shaderF &= ~SkShader::kOpaqueAlpha_Flag;
      52             :     }
      53           0 :     return shaderF;
      54             : }
      55             : 
      56           0 : SkShader::Context* SkColorFilterShader::onMakeContext(const ContextRec& rec,
      57             :                                                       SkArenaAlloc* alloc) const {
      58           0 :     SkShader::Context* shaderContext = fShader->makeContext(rec, alloc);
      59           0 :     if (nullptr == shaderContext) {
      60           0 :         return nullptr;
      61             :     }
      62           0 :     return alloc->make<FilterShaderContext>(*this, shaderContext, rec);
      63             : }
      64             : 
      65             : 
      66           0 : SkColorFilterShader::FilterShaderContext::FilterShaderContext(
      67             :                                                          const SkColorFilterShader& filterShader,
      68             :                                                          SkShader::Context* shaderContext,
      69           0 :                                                          const ContextRec& rec)
      70             :     : INHERITED(filterShader, rec)
      71           0 :     , fShaderContext(shaderContext)
      72           0 : {}
      73             : 
      74           0 : void SkColorFilterShader::FilterShaderContext::shadeSpan(int x, int y, SkPMColor result[],
      75             :                                                          int count) {
      76           0 :     const SkColorFilterShader& filterShader = static_cast<const SkColorFilterShader&>(fShader);
      77             : 
      78           0 :     fShaderContext->shadeSpan(x, y, result, count);
      79           0 :     filterShader.fFilter->filterSpan(result, count, result);
      80           0 : }
      81             : 
      82           0 : void SkColorFilterShader::FilterShaderContext::shadeSpan4f(int x, int y, SkPM4f result[],
      83             :                                                           int count) {
      84           0 :     const SkColorFilterShader& filterShader = static_cast<const SkColorFilterShader&>(fShader);
      85             : 
      86           0 :     fShaderContext->shadeSpan4f(x, y, result, count);
      87           0 :     filterShader.fFilter->filterSpan4f(result, count, result);
      88           0 : }
      89             : 
      90             : #if SK_SUPPORT_GPU
      91             : /////////////////////////////////////////////////////////////////////
      92             : 
      93           0 : sk_sp<GrFragmentProcessor> SkColorFilterShader::asFragmentProcessor(const AsFPArgs& args) const {
      94             : 
      95           0 :     sk_sp<GrFragmentProcessor> fp1(fShader->asFragmentProcessor(args));
      96           0 :     if (!fp1) {
      97           0 :         return nullptr;
      98             :     }
      99             : 
     100           0 :     sk_sp<GrFragmentProcessor> fp2(fFilter->asFragmentProcessor(args.fContext,
     101           0 :                                                                 args.fDstColorSpace));
     102           0 :     if (!fp2) {
     103           0 :         return fp1;
     104             :     }
     105             : 
     106           0 :     sk_sp<GrFragmentProcessor> fpSeries[] = { std::move(fp1), std::move(fp2) };
     107           0 :     return GrFragmentProcessor::RunInSeries(fpSeries, 2);
     108             : }
     109             : #endif
     110             : 
     111             : #ifndef SK_IGNORE_TO_STRING
     112           0 : void SkColorFilterShader::toString(SkString* str) const {
     113           0 :     str->append("SkColorFilterShader: (");
     114             : 
     115           0 :     str->append("Shader: ");
     116           0 :     fShader->toString(str);
     117           0 :     str->append(" Filter: ");
     118             :     // TODO: add "fFilter->toString(str);" once SkColorFilter::toString is added
     119             : 
     120           0 :     this->INHERITED::toString(str);
     121             : 
     122           0 :     str->append(")");
     123           0 : }
     124             : #endif
     125             : 
     126             : ///////////////////////////////////////////////////////////////////////////////////////////////////
     127             : 
     128           0 : sk_sp<SkShader> SkShader::makeWithColorFilter(sk_sp<SkColorFilter> filter) const {
     129           0 :     SkShader* base = const_cast<SkShader*>(this);
     130           0 :     if (!filter) {
     131           0 :         return sk_ref_sp(base);
     132             :     }
     133           0 :     return sk_make_sp<SkColorFilterShader>(sk_ref_sp(base), filter);
     134             : }

Generated by: LCOV version 1.13