00001 /* 00002 * Copyright (C) 2007 The Android Open Source Project 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef SkPicture_DEFINED 00018 #define SkPicture_DEFINED 00019 00020 #include "SkRefCnt.h" 00021 00022 class SkCanvas; 00023 class SkPicturePlayback; 00024 class SkPictureRecord; 00025 class SkStream; 00026 class SkWStream; 00027 00033 class SkPicture : public SkRefCnt { 00034 public: 00039 SkPicture(); 00043 SkPicture(const SkPicture& src); 00044 explicit SkPicture(SkStream*); 00045 virtual ~SkPicture(); 00046 00050 void swap(SkPicture& other); 00051 00052 enum RecordingFlags { 00053 /* This flag specifies that when clipPath() is called, the path will 00054 be faithfully recorded, but the recording canvas' current clip will 00055 only see the path's bounds. This speeds up the recording process 00056 without compromising the fidelity of the playback. The only side- 00057 effect for recording is that calling getTotalClip() or related 00058 clip-query calls will reflect the path's bounds, not the actual 00059 path. 00060 */ 00061 kUsePathBoundsForClip_RecordingFlag = 0x01 00062 }; 00063 00072 SkCanvas* beginRecording(int width, int height, uint32_t recordFlags = 0); 00073 00077 SkCanvas* getRecordingCanvas() const; 00083 void endRecording(); 00084 00089 void draw(SkCanvas* surface); 00090 00096 int width() const { return fWidth; } 00097 00103 int height() const { return fHeight; } 00104 00105 void serialize(SkWStream*) const; 00106 00111 void abortPlayback(); 00112 00113 private: 00114 int fWidth, fHeight; 00115 SkPictureRecord* fRecord; 00116 SkPicturePlayback* fPlayback; 00117 00118 friend class SkFlatPicture; 00119 friend class SkPicturePlayback; 00120 }; 00121 00122 class SkAutoPictureRecord : SkNoncopyable { 00123 public: 00124 SkAutoPictureRecord(SkPicture* pict, int width, int height, 00125 uint32_t recordingFlags = 0) { 00126 fPicture = pict; 00127 fCanvas = pict->beginRecording(width, height, recordingFlags); 00128 } 00129 ~SkAutoPictureRecord() { 00130 fPicture->endRecording(); 00131 } 00132 00135 SkCanvas* getRecordingCanvas() const { return fCanvas; } 00136 00137 private: 00138 SkPicture* fPicture; 00139 SkCanvas* fCanvas; 00140 }; 00141 00142 00143 #endif