blob: 26a4f6a3e6a66b0fec0ded895d7ce8dba2b0b48a [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"
Ben Wagner60126ef2015-08-07 12:13:48 -040023
24#include <memory>
Robert Phillipsb59508f2014-04-23 12:31:37 -040025
Robert Phillipsb59508f2014-04-23 12:31:37 -040026class SkStream;
27class SkWStream;
28
Derek Sollenberger4b0959d2014-06-12 12:31:10 -040029namespace android {
30
Derek Sollenberger8872b382014-06-23 14:13:53 -040031class Canvas;
32
Robert Phillipsb59508f2014-04-23 12:31:37 -040033// 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.
Derek Sollenberger4b0959d2014-06-12 12:31:10 -040037class Picture {
Robert Phillipsb59508f2014-04-23 12:31:37 -040038public:
Derek Sollenberger4b0959d2014-06-12 12:31:10 -040039 explicit Picture(const Picture* src = NULL);
Robert Phillipsb59508f2014-04-23 12:31:37 -040040
Derek Sollenberger8872b382014-06-23 14:13:53 -040041 Canvas* beginRecording(int width, int height);
Robert Phillipsb59508f2014-04-23 12:31:37 -040042
43 void endRecording();
44
45 int width() const;
46
47 int height() const;
48
Derek Sollenberger4b0959d2014-06-12 12:31:10 -040049 static Picture* CreateFromStream(SkStream* stream);
Robert Phillipsb59508f2014-04-23 12:31:37 -040050
51 void serialize(SkWStream* stream) const;
52
Derek Sollenberger8872b382014-06-23 14:13:53 -040053 void draw(Canvas* canvas);
Robert Phillipsb59508f2014-04-23 12:31:37 -040054
55private:
56 int mWidth;
57 int mHeight;
58 SkAutoTUnref<const SkPicture> mPicture;
Ben Wagner60126ef2015-08-07 12:13:48 -040059 std::unique_ptr<SkPictureRecorder> mRecorder;
Robert Phillipsb59508f2014-04-23 12:31:37 -040060
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;
Mike Reed71487eb2014-11-19 16:13:20 -050064
65 void validate() const;
Robert Phillipsb59508f2014-04-23 12:31:37 -040066};
Derek Sollenberger4b0959d2014-06-12 12:31:10 -040067
68}; // namespace android
Andreas Gampeed6b9df2014-11-20 22:02:20 -080069#endif // ANDROID_GRAPHICS_PICTURE_H_