blob: a9db6487cb04023e7ec727ef7318f4173c9b0a78 [file] [log] [blame]
Robert Phillipsb59508f2014-04-23 12:31:37 -04001/*
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
Andreas Gampeed6b9df2014-11-20 22:02:20 -080017#ifndef ANDROID_GRAPHICS_PICTURE_H_
18#define ANDROID_GRAPHICS_PICTURE_H_
Robert Phillipsb59508f2014-04-23 12:31:37 -040019
20#include "SkPicture.h"
21#include "SkPictureRecorder.h"
22#include "SkRefCnt.h"
23#include "SkTemplates.h"
24
Robert Phillipsb59508f2014-04-23 12:31:37 -040025class SkStream;
26class SkWStream;
27
Derek Sollenberger4b0959d2014-06-12 12:31:10 -040028namespace android {
29
Derek Sollenberger8872b382014-06-23 14:13:53 -040030class Canvas;
31
Robert Phillipsb59508f2014-04-23 12:31:37 -040032// 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.
Derek Sollenberger4b0959d2014-06-12 12:31:10 -040036class Picture {
Robert Phillipsb59508f2014-04-23 12:31:37 -040037public:
Derek Sollenberger4b0959d2014-06-12 12:31:10 -040038 explicit Picture(const Picture* src = NULL);
Robert Phillipsb59508f2014-04-23 12:31:37 -040039
Derek Sollenberger8872b382014-06-23 14:13:53 -040040 Canvas* beginRecording(int width, int height);
Robert Phillipsb59508f2014-04-23 12:31:37 -040041
42 void endRecording();
43
44 int width() const;
45
46 int height() const;
47
Derek Sollenberger4b0959d2014-06-12 12:31:10 -040048 static Picture* CreateFromStream(SkStream* stream);
Robert Phillipsb59508f2014-04-23 12:31:37 -040049
50 void serialize(SkWStream* stream) const;
51
Derek Sollenberger8872b382014-06-23 14:13:53 -040052 void draw(Canvas* canvas);
Robert Phillipsb59508f2014-04-23 12:31:37 -040053
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;
Mike Reed71487eb2014-11-19 16:13:20 -050063
64 void validate() const;
Robert Phillipsb59508f2014-04-23 12:31:37 -040065};
Derek Sollenberger4b0959d2014-06-12 12:31:10 -040066
67}; // namespace android
Andreas Gampeed6b9df2014-11-20 22:02:20 -080068#endif // ANDROID_GRAPHICS_PICTURE_H_