Picture.h revision 8872b38ef403cc2c44aca07d392f5e9426fd7f54
1/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_GRAPHICS_PICTURE_H
18#define ANDROID_GRAPHICS_PICTURE_H
19
20#include "SkPicture.h"
21#include "SkPictureRecorder.h"
22#include "SkRefCnt.h"
23#include "SkTemplates.h"
24
25class SkStream;
26class SkWStream;
27
28namespace android {
29
30class Canvas;
31
32// Skia's SkPicture class has been split into an SkPictureRecorder
33// and an SkPicture. AndroidPicture recreates the functionality
34// of the old SkPicture interface by flip-flopping between the two
35// new classes.
36class Picture {
37public:
38    explicit Picture(const Picture* src = NULL);
39
40    Canvas* beginRecording(int width, int height);
41
42    void endRecording();
43
44    int width() const;
45
46    int height() const;
47
48    static Picture* CreateFromStream(SkStream* stream);
49
50    void serialize(SkWStream* stream) const;
51
52    void draw(Canvas* canvas);
53
54private:
55    int mWidth;
56    int mHeight;
57    SkAutoTUnref<const SkPicture> mPicture;
58    SkAutoTDelete<SkPictureRecorder> mRecorder;
59
60    // Make a copy of a picture that is in the midst of being recorded. The
61    // resulting picture will have balanced saves and restores.
62    SkPicture* makePartialCopy() const;
63};
64
65}; // namespace android
66#endif // ANDROID_GRAPHICS_PICTURE_H
67