Picture.h revision 4b0959d8db20c08ab1fed37f397b303af229162b
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 SkCanvas;
26class SkPicture;
27class SkPictureRecorder;
28class SkStream;
29class SkWStream;
30
31namespace android {
32
33// Skia's SkPicture class has been split into an SkPictureRecorder
34// and an SkPicture. AndroidPicture recreates the functionality
35// of the old SkPicture interface by flip-flopping between the two
36// new classes.
37class Picture {
38public:
39    explicit Picture(const Picture* src = NULL);
40
41    SkCanvas* beginRecording(int width, int height);
42
43    void endRecording();
44
45    int width() const;
46
47    int height() const;
48
49    static Picture* CreateFromStream(SkStream* stream);
50
51    void serialize(SkWStream* stream) const;
52
53    void draw(SkCanvas* canvas);
54
55private:
56    int mWidth;
57    int mHeight;
58    SkAutoTUnref<const SkPicture> mPicture;
59    SkAutoTDelete<SkPictureRecorder> mRecorder;
60
61    // Make a copy of a picture that is in the midst of being recorded. The
62    // resulting picture will have balanced saves and restores.
63    SkPicture* makePartialCopy() const;
64};
65
66}; // namespace android
67#endif // ANDROID_GRAPHICS_PICTURE_H
68