aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkPipe.h
blob: 027edfba7ab0a8e839be323aca3e1a99e89c23da (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
 * Copyright 2016 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef SkPipe_DEFINED
#define SkPipe_DEFINED

#include "SkData.h"
#include "SkImage.h"
#include "SkPicture.h"

class SkCanvas;
class SkImageDeserializer;
class SkImageSerializer;
class SkTypeface;
class SkTypefaceDeserializer;
class SkTypefaceSerializer;
class SkWStream;

struct SkRect;

class SkPipeSerializer {
public:
    SkPipeSerializer();
    ~SkPipeSerializer();

    // Ownership is not transferred, so caller must ceep the serializer alive
    void setTypefaceSerializer(SkTypefaceSerializer*);
    void setImageSerializer(SkImageSerializer*);

    void resetCache();

    sk_sp<SkData> writeImage(SkImage*);
    sk_sp<SkData> writePicture(SkPicture*);

    void writeImage(SkImage*, SkWStream*);
    void writePicture(SkPicture*, SkWStream*);

    SkCanvas* beginWrite(const SkRect& cullBounds, SkWStream*);
    void endWrite();

private:
    class Impl;
    std::unique_ptr<Impl> fImpl;
};

class SkPipeDeserializer {
public:
    SkPipeDeserializer();
    ~SkPipeDeserializer();

    // Ownership is not transferred, so caller must ceep the deserializer alive
    void setTypefaceDeserializer(SkTypefaceDeserializer*);
    void setImageDeserializer(SkImageDeserializer*);

    sk_sp<SkImage> readImage(const SkData* data) {
        if (!data) {
            return nullptr;
        }
        return this->readImage(data->data(), data->size());
    }

    sk_sp<SkPicture> readPicture(const SkData* data) {
        if (!data) {
            return nullptr;
        }
        return this->readPicture(data->data(), data->size());
    }

    sk_sp<SkImage> readImage(const void*, size_t);
    sk_sp<SkPicture> readPicture(const void*, size_t);

    bool playback(const void*, size_t, SkCanvas*);

private:
    class Impl;
    std::unique_ptr<Impl> fImpl;
};

//////////////////////////////////////////////////////////////////////////////////////////////////

class SkTypefaceSerializer {
public:
    virtual ~SkTypefaceSerializer() {}

    virtual sk_sp<SkData> serialize(SkTypeface*) = 0;
};

class SkImageSerializer {
public:
    virtual ~SkImageSerializer() {}

    virtual sk_sp<SkData> serialize(SkImage*) = 0;
};


class SkTypefaceDeserializer {
public:
    virtual ~SkTypefaceDeserializer() {}

    virtual sk_sp<SkTypeface> deserialize(const void* data, size_t size) = 0;
};

#endif