Home | History | Annotate | Download | only in core
      1 /*
      2  * Copyright 2017 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 #ifndef SkAutoBlitterChoose_DEFINED
      9 #define SkAutoBlitterChoose_DEFINED
     10 
     11 #include "SkArenaAlloc.h"
     12 #include "SkBlitter.h"
     13 #include "SkDraw.h"
     14 #include "SkMacros.h"
     15 
     16 class SkMatrix;
     17 class SkPaint;
     18 class SkPixmap;
     19 
     20 class SkAutoBlitterChoose : SkNoncopyable {
     21 public:
     22     SkAutoBlitterChoose() {}
     23     SkAutoBlitterChoose(const SkDraw& draw, const SkMatrix* matrix, const SkPaint& paint,
     24                         bool drawCoverage = false) {
     25         this->choose(draw, matrix, paint, drawCoverage);
     26     }
     27 
     28     SkBlitter*  operator->() { return fBlitter; }
     29     SkBlitter*  get() const { return fBlitter; }
     30 
     31     SkBlitter* choose(const SkDraw& draw, const SkMatrix* matrix, const SkPaint& paint,
     32                       bool drawCoverage = false) {
     33         SkASSERT(!fBlitter);
     34         if (!matrix) {
     35             matrix = draw.fMatrix;
     36         }
     37         fBlitter = SkBlitter::Choose(draw.fDst, *matrix, paint, &fAlloc, drawCoverage);
     38 
     39         if (draw.fCoverage) {
     40             // hmm, why can't choose ignore the paint if drawCoverage is true?
     41             SkBlitter* coverageBlitter = SkBlitter::Choose(*draw.fCoverage, *matrix, SkPaint(),
     42                                                            &fAlloc, true);
     43             fBlitter = fAlloc.make<SkPairBlitter>(fBlitter, coverageBlitter);
     44         }
     45         return fBlitter;
     46     }
     47 
     48 private:
     49     // Owned by fAlloc, which will handle the delete.
     50     SkBlitter* fBlitter = nullptr;
     51 
     52     SkSTArenaAlloc<kSkBlitterContextSize> fAlloc;
     53 };
     54 #define SkAutoBlitterChoose(...) SK_REQUIRE_LOCAL_VAR(SkAutoBlitterChoose)
     55 
     56 #endif
     57