1 /* 2 * Copyright 2008, The Android Open Source Project 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 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. 12 * 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. 24 */ 25 26 #ifndef PictureSet_h 27 #define PictureSet_h 28 29 #define PICTURE_SET_DUMP 0 30 #define PICTURE_SET_DEBUG 0 31 #define PICTURE_SET_VALIDATE 0 32 33 #if PICTURE_SET_DEBUG 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__) 37 #else 38 #define DBG_SET_LOG(message) ((void)0) 39 #define DBG_SET_LOGD(format, ...) ((void)0) 40 #define DEBUG_SET_UI_LOGD(...) ((void)0) 41 #endif 42 43 #include "jni.h" 44 #include "SkRegion.h" 45 #include <wtf/Vector.h> 46 #include <wtf/HashMap.h> 47 48 // #define FAST_PICTURESET // use a hierarchy of pictures 49 50 class SkCanvas; 51 class SkPicture; 52 class SkIRect; 53 54 namespace android { 55 56 #ifdef FAST_PICTURESET 57 struct BucketPicture { 58 SkPicture* mPicture; 59 SkIRect mArea; 60 SkIRect mRealArea; 61 bool mBase; 62 }; 63 64 typedef std::pair<int, int> BucketPosition; 65 typedef WTF::Vector<BucketPicture> Bucket; 66 typedef WTF::HashMap<BucketPosition , Bucket* > BucketMap; 67 #endif 68 69 class PictureSet { 70 public: 71 PictureSet(); 72 PictureSet(const PictureSet& src) { set(src); } 73 PictureSet(SkPicture* picture); 74 virtual ~PictureSet(); 75 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); 84 #endif 85 86 void add(const SkRegion& area, SkPicture* picture, 87 uint32_t elapsed, bool split); 88 89 // Update mWidth/mHeight, and adds any additional inval region 90 void setDimensions(int width, int height, SkRegion* inval = 0); 91 void clear(); 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& ); 97 98 #ifdef FAST_PICTURESET 99 #else 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; } 110 #endif 111 int width() const { return mWidth; } 112 void dump(const char* label) const; 113 bool validate(const char* label) const; 114 private: 115 bool emptyPicture(SkPicture* ) const; // true if no text, images, paths 116 117 #ifdef FAST_PICTURESET 118 BucketMap mBuckets; 119 WTF::Vector<Bucket*> mUpdatedBuckets; 120 int mBucketSizeX; 121 int mBucketSizeY; 122 int mBucketCountX; 123 int mBucketCountY; 124 #else 125 struct Pictures { 126 SkRegion mArea; 127 SkPicture* mPicture; 128 SkIRect mUnsplit; 129 uint32_t mElapsed; 130 bool mSplit : 8; 131 bool mWroteElapsed : 8; 132 bool mBase : 8; // true if nothing is drawn underneath this 133 bool mEmpty : 8; // true if the picture only draws white 134 }; 135 void add(const Pictures* temp); 136 WTF::Vector<Pictures> mPictures; 137 #endif 138 float mBaseArea; 139 float mAdditionalArea; 140 int mHeight; 141 int mWidth; 142 }; 143 } 144 145 #endif 146