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