aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrRecordReplaceDraw.h
blob: 4900e0d2417ec7d34d3faf58866814b2a1929b27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 * Copyright 2014 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef GrRecordReplaceDraw_DEFINED
#define GrRecordReplaceDraw_DEFINED

#include "SkDrawPictureCallback.h"
#include "SkRect.h"
#include "SkTDArray.h"

class SkBBoxHierarchy;
class SkBitmap;
class SkCanvas;
class SkImage;
class SkMatrix;
class SkPaint;
class SkPicture;
class SkRecord;

// GrReplacements collects op ranges that can be replaced with
// a single drawBitmap call (using a precomputed bitmap).
class GrReplacements {
public:
    // All the operations between fStart and fStop (inclusive) will be replaced with
    // a single drawBitmap call using fPos, fBM and fPaint.
    struct ReplacementInfo {
        unsigned        fStart;
        unsigned        fStop;
        SkIPoint        fPos;
        SkImage*        fImage;  // Owns a ref
        const SkPaint*  fPaint;  // Owned by this object

        SkIRect         fSrcRect;
    };

    ~GrReplacements() { this->freeAll(); }

    // Add a new replacement range. The replacement ranges should be
    // sorted in increasing order and non-overlapping (esp. no nested
    // saveLayers).
    ReplacementInfo* push();

    // look up a replacement range by its start offset.
    // lastLookedUp is an in/out parameter that is used to speed up the search.
    // It should be initialized to 0 on the first call and then passed back in
    // unmodified on subsequent calls.
    const ReplacementInfo* lookupByStart(size_t start, int* lastLookedUp) const;

private:
    SkTDArray<ReplacementInfo> fReplacements;

    void freeAll();

#ifdef SK_DEBUG
    void validate() const;
#endif
};

// Draw an SkPicture into an SkCanvas replacing saveLayer/restore blocks with
// drawBitmap calls.  A convenience wrapper around SkRecords::Draw.
void GrRecordReplaceDraw(const SkPicture*,
                         SkCanvas*,
                         const GrReplacements*,
                         const SkMatrix&,
                         SkDrawPictureCallback*);

#endif // GrRecordReplaceDraw_DEFINED