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

          Line data    Source code
       1             : /*
       2             :  * Copyright 2014 The Android Open Source Project
       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 "SkMatrixImageFilter.h"
       9             : 
      10             : #include "SkCanvas.h"
      11             : #include "SkReadBuffer.h"
      12             : #include "SkSpecialImage.h"
      13             : #include "SkSpecialSurface.h"
      14             : #include "SkWriteBuffer.h"
      15             : #include "SkRect.h"
      16             : 
      17           0 : SkMatrixImageFilter::SkMatrixImageFilter(const SkMatrix& transform,
      18             :                                          SkFilterQuality filterQuality,
      19           0 :                                          sk_sp<SkImageFilter> input)
      20             :     : INHERITED(&input, 1, nullptr)
      21             :     , fTransform(transform)
      22           0 :     , fFilterQuality(filterQuality) {
      23           0 : }
      24             : 
      25           0 : sk_sp<SkImageFilter> SkMatrixImageFilter::Make(const SkMatrix& transform,
      26             :                                                SkFilterQuality filterQuality,
      27             :                                                sk_sp<SkImageFilter> input) {
      28             :     return sk_sp<SkImageFilter>(new SkMatrixImageFilter(transform,
      29             :                                                         filterQuality,
      30           0 :                                                         std::move(input)));
      31             : }
      32             : 
      33           0 : sk_sp<SkFlattenable> SkMatrixImageFilter::CreateProc(SkReadBuffer& buffer) {
      34           0 :     SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
      35             :     SkMatrix matrix;
      36           0 :     buffer.readMatrix(&matrix);
      37           0 :     SkFilterQuality quality = static_cast<SkFilterQuality>(buffer.readInt());
      38           0 :     return Make(matrix, quality, common.getInput(0));
      39             : }
      40             : 
      41           0 : void SkMatrixImageFilter::flatten(SkWriteBuffer& buffer) const {
      42           0 :     this->INHERITED::flatten(buffer);
      43           0 :     buffer.writeMatrix(fTransform);
      44           0 :     buffer.writeInt(fFilterQuality);
      45           0 : }
      46             : 
      47           0 : sk_sp<SkSpecialImage> SkMatrixImageFilter::onFilterImage(SkSpecialImage* source,
      48             :                                                          const Context& ctx,
      49             :                                                          SkIPoint* offset) const {
      50             : 
      51           0 :     SkIPoint inputOffset = SkIPoint::Make(0, 0);
      52           0 :     sk_sp<SkSpecialImage> input(this->filterInput(0, source, ctx, &inputOffset));
      53           0 :     if (!input) {
      54           0 :         return nullptr;
      55             :     }
      56             : 
      57             :     SkMatrix matrix;
      58           0 :     if (!ctx.ctm().invert(&matrix)) {
      59           0 :         return nullptr;
      60             :     }
      61           0 :     matrix.postConcat(fTransform);
      62           0 :     matrix.postConcat(ctx.ctm());
      63             : 
      64             :     const SkIRect srcBounds = SkIRect::MakeXYWH(inputOffset.x(), inputOffset.y(),
      65           0 :                                                 input->width(), input->height());
      66           0 :     const SkRect srcRect = SkRect::Make(srcBounds);
      67             : 
      68             :     SkRect dstRect;
      69           0 :     matrix.mapRect(&dstRect, srcRect);
      70             :     SkIRect dstBounds;
      71           0 :     dstRect.roundOut(&dstBounds);
      72             : 
      73           0 :     sk_sp<SkSpecialSurface> surf(input->makeSurface(ctx.outputProperties(), dstBounds.size()));
      74           0 :     if (!surf) {
      75           0 :         return nullptr;
      76             :     }
      77             : 
      78           0 :     SkCanvas* canvas = surf->getCanvas();
      79           0 :     SkASSERT(canvas);
      80             : 
      81           0 :     canvas->clear(0x0);
      82             : 
      83           0 :     canvas->translate(-SkIntToScalar(dstBounds.x()), -SkIntToScalar(dstBounds.y()));
      84           0 :     canvas->concat(matrix);
      85             : 
      86           0 :     SkPaint paint;
      87           0 :     paint.setAntiAlias(true);
      88           0 :     paint.setBlendMode(SkBlendMode::kSrc);
      89           0 :     paint.setFilterQuality(fFilterQuality);
      90             : 
      91           0 :     input->draw(canvas, srcRect.x(), srcRect.y(), &paint);
      92             : 
      93           0 :     offset->fX = dstBounds.fLeft;
      94           0 :     offset->fY = dstBounds.fTop;
      95           0 :     return surf->makeImageSnapshot();
      96             : }
      97             : 
      98           0 : SkRect SkMatrixImageFilter::computeFastBounds(const SkRect& src) const {
      99           0 :     SkRect bounds = this->getInput(0) ? this->getInput(0)->computeFastBounds(src) : src;
     100             :     SkRect dst;
     101           0 :     fTransform.mapRect(&dst, bounds);
     102           0 :     return dst;
     103             : }
     104             : 
     105           0 : SkIRect SkMatrixImageFilter::onFilterNodeBounds(const SkIRect& src, const SkMatrix& ctm,
     106             :                                                 MapDirection direction) const {
     107             :     SkMatrix matrix;
     108           0 :     if (!ctm.invert(&matrix)) {
     109           0 :         return src;
     110             :     }
     111           0 :     if (kForward_MapDirection == direction) {
     112           0 :         matrix.postConcat(fTransform);
     113             :     } else {
     114             :         SkMatrix transformInverse;
     115           0 :         if (!fTransform.invert(&transformInverse)) {
     116           0 :             return src;
     117             :         }
     118           0 :         matrix.postConcat(transformInverse);
     119             :     }
     120           0 :     matrix.postConcat(ctm);
     121             :     SkRect floatBounds;
     122           0 :     matrix.mapRect(&floatBounds, SkRect::Make(src));
     123           0 :     return floatBounds.roundOut();
     124             : }
     125             : 
     126             : #ifndef SK_IGNORE_TO_STRING
     127           0 : void SkMatrixImageFilter::toString(SkString* str) const {
     128           0 :     str->appendf("SkMatrixImageFilter: (");
     129             : 
     130           0 :     str->appendf("transform: (%f %f %f %f %f %f %f %f %f)",
     131           0 :                  fTransform[SkMatrix::kMScaleX],
     132           0 :                  fTransform[SkMatrix::kMSkewX],
     133           0 :                  fTransform[SkMatrix::kMTransX],
     134           0 :                  fTransform[SkMatrix::kMSkewY],
     135           0 :                  fTransform[SkMatrix::kMScaleY],
     136           0 :                  fTransform[SkMatrix::kMTransY],
     137           0 :                  fTransform[SkMatrix::kMPersp0],
     138           0 :                  fTransform[SkMatrix::kMPersp1],
     139           0 :                  fTransform[SkMatrix::kMPersp2]);
     140             : 
     141           0 :     str->append("<dt>FilterLevel:</dt><dd>");
     142             :     static const char* gFilterLevelStrings[] = { "None", "Low", "Medium", "High" };
     143           0 :     str->append(gFilterLevelStrings[fFilterQuality]);
     144           0 :     str->append("</dd>");
     145             : 
     146           0 :     str->appendf(")");
     147           0 : }
     148             : #endif

Generated by: LCOV version 1.13