2 * Copyright 2008, The Android Open Source Project
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #define PICTURE_SET_DUMP 0
30 #define PICTURE_SET_DEBUG 0
31 #define PICTURE_SET_VALIDATE 0
34 #define DBG_SET_LOG(message) LOGD("%s %s", __FUNCTION__, message)
35 #define DBG_SET_LOGD(format, ...) LOGD("%s " format, __FUNCTION__, __VA_ARGS__)
36 #define DEBUG_SET_UI_LOGD(...) LOGD(__VA_ARGS__)
38 #define DBG_SET_LOG(message) ((void)0)
39 #define DBG_SET_LOGD(format, ...) ((void)0)
40 #define DEBUG_SET_UI_LOGD(...) ((void)0)
45 #include <wtf/Vector.h>
46 #include <wtf/HashMap.h>
48 // #define FAST_PICTURESET // use a hierarchy of pictures
56 #ifdef FAST_PICTURESET
57 struct BucketPicture {
64 typedef std::pair<int, int> BucketPosition;
65 typedef WTF::Vector<BucketPicture> Bucket;
66 typedef WTF::HashMap<BucketPosition , Bucket* > BucketMap;
72 PictureSet(const PictureSet& src) { set(src); }
73 PictureSet(SkPicture* picture);
74 virtual ~PictureSet();
76 #ifdef FAST_PICTURESET
77 void displayBucket(Bucket* bucket);
78 void displayBuckets();
79 WTF::Vector<Bucket*>* bucketsToUpdate() { return &mUpdatedBuckets; }
80 Bucket* getBucket(int x, int y);
81 void addToBucket(Bucket* bucket, int dx, int dy, SkIRect& rect);
82 void gatherBucketsForArea(WTF::Vector<Bucket*>& list, const SkIRect& rect);
83 void splitAdd(const SkIRect& rect);
86 void add(const SkRegion& area, SkPicture* picture,
87 uint32_t elapsed, bool split);
89 // Update mWidth/mHeight, and adds any additional inval region
90 void checkDimensions(int width, int height, SkRegion* inval);
92 bool draw(SkCanvas* );
93 static PictureSet* GetNativePictureSet(JNIEnv* env, jobject jpic);
94 int height() const { return mHeight; }
95 bool isEmpty() const; // returns true if empty or only trivial content
96 void set(const PictureSet& );
98 #ifdef FAST_PICTURESET
100 void add(const SkRegion& area, SkPicture* picture,
101 uint32_t elapsed, bool split, bool empty);
102 const SkIRect& bounds(size_t i) const {
103 return mPictures[i].mArea.getBounds(); }
104 bool reuseSubdivided(const SkRegion& );
105 void setPicture(size_t i, SkPicture* p);
106 void setDrawTimes(const PictureSet& );
107 size_t size() const { return mPictures.size(); }
108 void split(PictureSet* result) const;
109 bool upToDate(size_t i) const { return mPictures[i].mPicture != NULL; }
111 int width() const { return mWidth; }
112 void dump(const char* label) const;
113 bool validate(const char* label) const;
115 bool emptyPicture(SkPicture* ) const; // true if no text, images, paths
116 #ifdef FAST_PICTURESET
118 WTF::Vector<Bucket*> mUpdatedBuckets;
126 bool mWroteElapsed : 8;
127 bool mBase : 8; // true if nothing is drawn underneath this
128 bool mEmpty : 8; // true if the picture only draws white
130 void add(const Pictures* temp);
131 WTF::Vector<Pictures> mPictures;
134 float mAdditionalArea;