Home | History | Annotate | Download | only in graphics
      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 
     24 #include <memory>
     25 
     26 class SkStream;
     27 class SkWStream;
     28 
     29 namespace android {
     30 
     31 class Canvas;
     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.
     37 class Picture {
     38 public:
     39     explicit Picture(const Picture* src = NULL);
     40     explicit Picture(sk_sp<SkPicture>&& src);
     41 
     42     Canvas* beginRecording(int width, int height);
     43 
     44     void endRecording();
     45 
     46     int width() const;
     47 
     48     int height() const;
     49 
     50     static Picture* CreateFromStream(SkStream* stream);
     51 
     52     void serialize(SkWStream* stream) const;
     53 
     54     void draw(Canvas* canvas);
     55 
     56 private:
     57     int mWidth;
     58     int mHeight;
     59     sk_sp<SkPicture> mPicture;
     60     std::unique_ptr<SkPictureRecorder> mRecorder;
     61 
     62     // Make a copy of a picture that is in the midst of being recorded. The
     63     // resulting picture will have balanced saves and restores.
     64     sk_sp<SkPicture> makePartialCopy() const;
     65 };
     66 
     67 }; // namespace android
     68 #endif // ANDROID_GRAPHICS_PICTURE_H_
     69