| Robert Phillips | b59508f | 2014-04-23 12:31:37 -0400 | [diff] [blame] | 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 |  | 
| Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 17 | #ifndef ANDROID_GRAPHICS_PICTURE_H_ | 
|  | 18 | #define ANDROID_GRAPHICS_PICTURE_H_ | 
| Robert Phillips | b59508f | 2014-04-23 12:31:37 -0400 | [diff] [blame] | 19 |  | 
|  | 20 | #include "SkPicture.h" | 
|  | 21 | #include "SkPictureRecorder.h" | 
|  | 22 | #include "SkRefCnt.h" | 
| Ben Wagner | 60126ef | 2015-08-07 12:13:48 -0400 | [diff] [blame] | 23 |  | 
|  | 24 | #include <memory> | 
| Robert Phillips | b59508f | 2014-04-23 12:31:37 -0400 | [diff] [blame] | 25 |  | 
| Robert Phillips | b59508f | 2014-04-23 12:31:37 -0400 | [diff] [blame] | 26 | class SkStream; | 
|  | 27 | class SkWStream; | 
|  | 28 |  | 
| Derek Sollenberger | 4b0959d | 2014-06-12 12:31:10 -0400 | [diff] [blame] | 29 | namespace android { | 
|  | 30 |  | 
| Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 31 | class Canvas; | 
|  | 32 |  | 
| Robert Phillips | b59508f | 2014-04-23 12:31:37 -0400 | [diff] [blame] | 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. | 
| Derek Sollenberger | 4b0959d | 2014-06-12 12:31:10 -0400 | [diff] [blame] | 37 | class Picture { | 
| Robert Phillips | b59508f | 2014-04-23 12:31:37 -0400 | [diff] [blame] | 38 | public: | 
| Derek Sollenberger | 4b0959d | 2014-06-12 12:31:10 -0400 | [diff] [blame] | 39 | explicit Picture(const Picture* src = NULL); | 
| John Reck | 5cca8f2 | 2018-12-10 17:06:22 -0800 | [diff] [blame] | 40 | explicit Picture(sk_sp<SkPicture>&& src); | 
| John Reck | 7600518 | 2021-06-09 22:43:05 -0400 | [diff] [blame] | 41 | virtual ~Picture() = default; | 
| Robert Phillips | b59508f | 2014-04-23 12:31:37 -0400 | [diff] [blame] | 42 |  | 
| Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 43 | Canvas* beginRecording(int width, int height); | 
| Robert Phillips | b59508f | 2014-04-23 12:31:37 -0400 | [diff] [blame] | 44 |  | 
|  | 45 | void endRecording(); | 
|  | 46 |  | 
|  | 47 | int width() const; | 
|  | 48 |  | 
|  | 49 | int height() const; | 
|  | 50 |  | 
| Derek Sollenberger | 4b0959d | 2014-06-12 12:31:10 -0400 | [diff] [blame] | 51 | static Picture* CreateFromStream(SkStream* stream); | 
| Robert Phillips | b59508f | 2014-04-23 12:31:37 -0400 | [diff] [blame] | 52 |  | 
| John Reck | 7600518 | 2021-06-09 22:43:05 -0400 | [diff] [blame] | 53 | virtual void serialize(SkWStream* stream) const; | 
| Robert Phillips | b59508f | 2014-04-23 12:31:37 -0400 | [diff] [blame] | 54 |  | 
| Derek Sollenberger | 8872b38 | 2014-06-23 14:13:53 -0400 | [diff] [blame] | 55 | void draw(Canvas* canvas); | 
| Robert Phillips | b59508f | 2014-04-23 12:31:37 -0400 | [diff] [blame] | 56 |  | 
|  | 57 | private: | 
|  | 58 | int mWidth; | 
|  | 59 | int mHeight; | 
| Mike Reed | 260ab72 | 2016-10-07 15:59:20 -0400 | [diff] [blame] | 60 | sk_sp<SkPicture> mPicture; | 
| Ben Wagner | 60126ef | 2015-08-07 12:13:48 -0400 | [diff] [blame] | 61 | std::unique_ptr<SkPictureRecorder> mRecorder; | 
| Robert Phillips | b59508f | 2014-04-23 12:31:37 -0400 | [diff] [blame] | 62 |  | 
|  | 63 | // Make a copy of a picture that is in the midst of being recorded. The | 
|  | 64 | // resulting picture will have balanced saves and restores. | 
| Mike Reed | 260ab72 | 2016-10-07 15:59:20 -0400 | [diff] [blame] | 65 | sk_sp<SkPicture> makePartialCopy() const; | 
| Robert Phillips | b59508f | 2014-04-23 12:31:37 -0400 | [diff] [blame] | 66 | }; | 
| Derek Sollenberger | 4b0959d | 2014-06-12 12:31:10 -0400 | [diff] [blame] | 67 |  | 
|  | 68 | }; // namespace android | 
| Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 69 | #endif // ANDROID_GRAPHICS_PICTURE_H_ |