aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core/SkAnnotation.h
blob: e1ecf6caf17bd9386bdea84eccef0908a0b50bc4 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
 * Copyright 2012 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef SkAnnotation_DEFINED
#define SkAnnotation_DEFINED

#include "SkFlattenable.h"

class SkData;
class SkDataSet;
class SkStream;
class SkWStream;

/**
 *  Experimental class for annotating draws. Do not use directly yet.
 *  Use helper functions at the bottom of this file for now.
 */
class SkAnnotation : public SkFlattenable {
public:
    enum Flags {
        // If set, the associated drawing primitive should not be drawn
        kNoDraw_Flag  = 1 << 0,
    };

    SkAnnotation(SkDataSet*, uint32_t flags);
    virtual ~SkAnnotation();

    uint32_t getFlags() const { return fFlags; }
    SkDataSet* getDataSet() const { return fDataSet; }

    bool isNoDraw() const { return SkToBool(fFlags & kNoDraw_Flag); }

    /**
     *  Helper for search the annotation's dataset.
     */
    SkData* find(const char name[]) const;

    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkAnnotation)

protected:
    SkAnnotation(SkFlattenableReadBuffer&);
    virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;

private:
    SkDataSet*  fDataSet;
    uint32_t    fFlags;

    void writeToStream(SkWStream*) const;
    void readFromStream(SkStream*);

    typedef SkFlattenable INHERITED;
};

/**
 *  Experimental collection of predefined Keys into the Annotation dictionary
 */
class SkAnnotationKeys {
public:
    /**
     *  Returns the canonical key whose payload is a URL
     */
    static const char* URL_Key();
};

///////////////////////////////////////////////////////////////////////////////
//
// Experimental helper functions to use Annotations
//

struct SkRect;
class SkCanvas;

/**
 *  Experimental!
 *
 *  Annotate the canvas by associating the specified URL with the
 *  specified rectangle (in local coordinates, just like drawRect). If the
 *  backend of this canvas does not support annotations, this call is
 *  safely ignored.
 *
 *  The caller is responsible for managing its ownership of the SkData.
 */
SK_API void SkAnnotateRectWithURL(SkCanvas*, const SkRect&, SkData*);

#endif