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 APPLE COMPUTER, INC. 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 47 class SkCanvas; 48 class SkPicture; 49 class SkIRect; 50 51 namespace android { 52 53 class PictureSet { 54 public: 55 PictureSet(); PictureSet(const PictureSet & src)56 PictureSet(const PictureSet& src) { set(src); } 57 virtual ~PictureSet(); add(const SkRegion & area,SkPicture * picture,uint32_t elapsed,bool split)58 void add(const SkRegion& area, SkPicture* picture, 59 uint32_t elapsed, bool split) 60 { 61 add(area, picture, elapsed, split, emptyPicture(picture)); 62 } 63 void add(const SkRegion& area, SkPicture* picture, 64 uint32_t elapsed, bool split, bool empty); bounds(size_t i)65 const SkIRect& bounds(size_t i) const { 66 return mPictures[i].mArea.getBounds(); } 67 bool build(); 68 // Update mWidth/mHeight, and adds any additional inval region 69 void checkDimensions(int width, int height, SkRegion* inval); 70 void clear(); 71 bool draw(SkCanvas* ); 72 static PictureSet* GetNativePictureSet(JNIEnv* env, jobject jpic); height()73 int height() const { return mHeight; } 74 bool isEmpty() const; // returns true if empty or only trivial content 75 bool reuseSubdivided(const SkRegion& ); 76 void set(const PictureSet& ); 77 void setDrawTimes(const PictureSet& ); 78 void setPicture(size_t i, SkPicture* p); size()79 size_t size() const { return mPictures.size(); } 80 void split(PictureSet* result) const; upToDate(size_t i)81 bool upToDate(size_t i) const { return mPictures[i].mPicture != NULL; } width()82 int width() const { return mWidth; } 83 void dump(const char* label) const; 84 bool validate(const char* label) const; 85 private: 86 bool emptyPicture(SkPicture* ) const; // true if no text, images, paths 87 struct Pictures { 88 SkRegion mArea; 89 SkPicture* mPicture; 90 SkIRect mUnsplit; 91 uint32_t mElapsed; 92 bool mSplit : 8; 93 bool mWroteElapsed : 8; 94 bool mBase : 8; // true if nothing is drawn underneath this 95 bool mEmpty : 8; // true if the picture only draws white 96 }; 97 void add(const Pictures* temp); 98 WTF::Vector<Pictures> mPictures; 99 int mHeight; 100 int mWidth; 101 }; 102 } 103 104 #endif 105