summaryrefslogtreecommitdiffstats
path: root/Source/WebKit/android/jni/PictureSet.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebKit/android/jni/PictureSet.cpp')
-rw-r--r--Source/WebKit/android/jni/PictureSet.cpp173
1 files changed, 83 insertions, 90 deletions
diff --git a/Source/WebKit/android/jni/PictureSet.cpp b/Source/WebKit/android/jni/PictureSet.cpp
index 4d9d16c..8e95aa3 100644
--- a/Source/WebKit/android/jni/PictureSet.cpp
+++ b/Source/WebKit/android/jni/PictureSet.cpp
@@ -26,17 +26,16 @@
#define LOG_NDEBUG 0
#define LOG_TAG "pictureset"
-//#include <config.h>
-#include "CachedPrefix.h"
-#include "android_graphics.h"
+#include "config.h"
#include "PictureSet.h"
+
+#include "android_graphics.h"
#include "SkBounder.h"
#include "SkCanvas.h"
#include "SkPicture.h"
#include "SkRect.h"
#include "SkRegion.h"
#include "SkStream.h"
-#include "TimeCounter.h"
#define MAX_DRAW_TIME 100
#define MIN_SPLITTABLE 400
@@ -133,7 +132,7 @@ PictureSet::PictureSet(SkPicture* picture) :
pictureAndBounds.mPicture = picture;
SkSafeRef(pictureAndBounds.mPicture);
pictureAndBounds.mEmpty = false;
- pictureAndBounds.mArea.setRect(0, 0, mWidth, mHeight);
+ pictureAndBounds.mArea.set(0, 0, mWidth, mHeight);
pictureAndBounds.mSplit = false;
pictureAndBounds.mBase = true;
pictureAndBounds.mElapsed = 0;
@@ -158,14 +157,13 @@ void PictureSet::add(const Pictures* temp)
}
#endif // FAST_PICTURESET
-void PictureSet::add(const SkRegion& area, SkPicture* picture,
- uint32_t elapsed, bool split)
+void PictureSet::add(const SkRegion& area, uint32_t elapsed, bool split)
{
if (area.isRect()) {
#ifdef FAST_PICTURESET
splitAdd(area.getBounds());
#else
- add(area, picture, elapsed, split, false);
+ add(area.getBounds(), elapsed, split, false);
#endif // FAST_PICTURESET
} else {
SkRegion::Iterator cliperator(area);
@@ -174,9 +172,7 @@ void PictureSet::add(const SkRegion& area, SkPicture* picture,
#ifdef FAST_PICTURESET
splitAdd(ir);
#else
- SkRegion newArea;
- newArea.setRect(ir);
- add(newArea, picture, elapsed, split, false);
+ add(ir, elapsed, split, false);
#endif // FAST_PICTURESET
cliperator.next();
}
@@ -449,8 +445,7 @@ void PictureSet::splitAdd(const SkIRect& rect)
// things (deleting additional pictures + full repaint of base pictures)
#ifdef FAST_PICTURESET
#else
-void PictureSet::add(const SkRegion& area, SkPicture* picture,
- uint32_t elapsed, bool split, bool empty)
+void PictureSet::add(const SkIRect& area, uint32_t elapsed, bool split, bool empty)
{
bool checkForNewBases = false;
@@ -459,12 +454,11 @@ void PictureSet::add(const SkRegion& area, SkPicture* picture,
#ifdef DEBUG
XLOG("--- before adding the new inval ---");
for (Pictures* working = mPictures.begin(); working != mPictures.end(); working++) {
- SkIRect currentArea = working->mArea.getBounds();
- XLOG("picture %d (%d, %d, %d, %d - %d x %d) (isRect? %c) base: %c",
+ SkIRect currentArea = working->mArea;
+ XLOG("picture %d (%d, %d, %d, %d - %d x %d) base: %c",
working - first,
currentArea.fLeft, currentArea.fTop, currentArea.fRight, currentArea.fBottom,
currentArea.width(), currentArea.height(),
- working->mArea.isRect() ? 'Y' : 'N',
working->mBase ? 'Y' : 'N');
}
XLOG("----------------------------------");
@@ -472,14 +466,14 @@ void PictureSet::add(const SkRegion& area, SkPicture* picture,
// let's gather all the Pictures intersecting with the new invalidated
// area, collect their area and remove their picture
- SkIRect totalArea = area.getBounds();
+ SkIRect totalArea = area;
for (Pictures* working = first; working != last; working++) {
- SkIRect inval = area.getBounds();
+ SkIRect inval = area;
bool remove = false;
- if (!working->mBase && working->mArea.intersects(inval))
+ if (!working->mBase && SkIRect::Intersects(working->mArea, inval))
remove = true;
if (working->mBase) {
- SkIRect baseArea = working->mArea.getBounds();
+ SkIRect baseArea = working->mArea;
if (area.contains(baseArea)) {
remove = true;
checkForNewBases = true;
@@ -487,21 +481,19 @@ void PictureSet::add(const SkRegion& area, SkPicture* picture,
}
if (remove) {
- SkIRect currentArea = working->mArea.getBounds();
+ SkIRect currentArea = working->mArea;
if (working->mBase)
mBaseArea -= currentArea.width() * currentArea.height();
else
mAdditionalArea -= currentArea.width() * currentArea.height();
totalArea.join(currentArea);
- XLOG("picture %d (%d, %d, %d, %d - %d x %d) (isRect? %c) intersects with the new inval area (%d, %d, %d, %d - %d x %d) (isRect? %c, we remove it",
+ XLOG("picture %d (%d, %d, %d, %d - %d x %d) intersects with the new inval area (%d, %d, %d, %d - %d x %d)",
working - first,
currentArea.fLeft, currentArea.fTop, currentArea.fRight, currentArea.fBottom,
currentArea.width(), currentArea.height(),
- working->mArea.isRect() ? 'Y' : 'N',
inval.fLeft, inval.fTop, inval.fRight, inval.fBottom,
- inval.width(), inval.height(),
- area.isRect() ? 'Y' : 'N');
+ inval.width(), inval.height());
working->mArea.setEmpty();
SkSafeUnref(working->mPicture);
working->mPicture = 0;
@@ -510,9 +502,7 @@ void PictureSet::add(const SkRegion& area, SkPicture* picture,
// Now we can add the new Picture to the list, with the correct area
// that need to be repainted
- SkRegion collect;
- collect.setRect(totalArea);
- Pictures pictureAndBounds = {collect, 0, collect.getBounds(),
+ Pictures pictureAndBounds = {totalArea, 0, totalArea,
elapsed, split, false, false, empty};
#ifdef FAST_PICTURESET
@@ -520,6 +510,13 @@ void PictureSet::add(const SkRegion& area, SkPicture* picture,
checkForNewBases = true;
#endif
+ if (!size()) {
+ pictureAndBounds.mBase = true;
+ mBaseArea = totalArea.width() * totalArea.height();
+ mAdditionalArea = 0;
+ mPictures.append(pictureAndBounds);
+ return;
+ }
mPictures.append(pictureAndBounds);
mAdditionalArea += totalArea.width() * totalArea.height();
last = mPictures.end();
@@ -553,12 +550,11 @@ void PictureSet::add(const SkRegion& area, SkPicture* picture,
#ifdef DEBUG
XLOG("--- after adding the new inval, but before collapsing ---");
for (Pictures* working = mPictures.begin(); working != mPictures.end(); working++) {
- SkIRect currentArea = working->mArea.getBounds();
- XLOG("picture %d (%d, %d, %d, %d - %d x %d) (isRect? %c) base: %c",
+ SkIRect currentArea = working->mArea;
+ XLOG("picture %d (%d, %d, %d, %d - %d x %d) base: %c",
working - first,
currentArea.fLeft, currentArea.fTop, currentArea.fRight, currentArea.fBottom,
currentArea.width(), currentArea.height(),
- working->mArea.isRect() ? 'Y' : 'N',
working->mBase ? 'Y' : 'N');
}
XLOG("----------------------------------");
@@ -578,12 +574,11 @@ void PictureSet::add(const SkRegion& area, SkPicture* picture,
#ifdef DEBUG
XLOG("--- after adding the new inval ---");
for (Pictures* working = mPictures.begin(); working != mPictures.end(); working++) {
- SkIRect currentArea = working->mArea.getBounds();
- XLOG("picture %d (%d, %d, %d, %d - %d x %d) (isRect? %c) base: %c picture %x",
+ SkIRect currentArea = working->mArea;
+ XLOG("picture %d (%d, %d, %d, %d - %d x %d) base: %c picture %x",
working - first,
currentArea.fLeft, currentArea.fTop, currentArea.fRight, currentArea.fBottom,
currentArea.width(), currentArea.height(),
- working->mArea.isRect() ? 'Y' : 'N',
working->mBase ? 'Y' : 'N', working->mPicture);
}
XLOG("----------------------------------");
@@ -596,7 +591,8 @@ void PictureSet::add(const SkRegion& area, SkPicture* picture,
Pictures* last = mPictures.end();
XLOG("checkForNewBases...");
for (Pictures* working = mPictures.begin(); working != last; working++) {
- SkRegion& area = working->mArea;
+ SkRegion area;
+ area.setRect(working->mArea);
const SkIRect& a = area.getBounds();
if (drawn.contains(working->mArea) == false) {
working->mBase = true;
@@ -607,6 +603,19 @@ void PictureSet::add(const SkRegion& area, SkPicture* picture,
drawn.op(working->mArea, SkRegion::kUnion_Op);
}
}
+
+#ifdef DEBUG
+ XLOG("--- after checking for bases ---");
+ for (Pictures* working = mPictures.begin(); working != mPictures.end(); working++) {
+ SkIRect currentArea = working->mArea;
+ XLOG("picture %d (%d, %d, %d, %d - %d x %d) base: %c picture %x",
+ working - first,
+ currentArea.fLeft, currentArea.fTop, currentArea.fRight, currentArea.fBottom,
+ currentArea.width(), currentArea.height(),
+ working->mBase ? 'Y' : 'N', working->mPicture);
+ }
+ XLOG("----------------------------------");
+#endif
}
#endif // FAST_PICTURESET
@@ -693,6 +702,22 @@ void PictureSet::clear()
mWidth = mHeight = 0;
}
+uint32_t getThreadMsec()
+{
+#if defined(HAVE_POSIX_CLOCKS)
+ struct timespec tm;
+
+ clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tm);
+ return tm.tv_sec * 1000LL + tm.tv_nsec / 1000000;
+#else
+ struct timeval now;
+ struct timezone zone;
+
+ gettimeofday(&now, &zone);
+ return now.tv_sec * 1000LL + now.tv_usec / 1000;
+#endif
+}
+
bool PictureSet::draw(SkCanvas* canvas)
{
#ifdef FAST_PICTURESET
@@ -745,11 +770,13 @@ bool PictureSet::draw(SkCanvas* canvas)
return false;
SkIRect irect;
bounds.roundOut(&irect);
+ if (!irect.intersect(0, 0, width(), height()))
+ return false;
for (working = last; working != first; ) {
--working;
if (working->mArea.contains(irect)) {
#if PICTURE_SET_DEBUG
- const SkIRect& b = working->mArea.getBounds();
+ const SkIRect& b = working->mArea;
DBG_SET_LOGD("contains working->mArea={%d,%d,%d,%d}"
" irect={%d,%d,%d,%d}", b.fLeft, b.fTop, b.fRight, b.fBottom,
irect.fLeft, irect.fTop, irect.fRight, irect.fBottom);
@@ -762,7 +789,8 @@ bool PictureSet::draw(SkCanvas* canvas)
last - mPictures.begin());
uint32_t maxElapsed = 0;
for (working = first; working != last; working++) {
- const SkRegion& area = working->mArea;
+ SkRegion area;
+ area.setRect(working->mArea);
if (area.quickReject(irect)) {
#if PICTURE_SET_DEBUG
const SkIRect& b = area.getBounds();
@@ -835,7 +863,7 @@ void PictureSet::dump(const char* label) const
MeasureStream measure;
if (working->mPicture != NULL)
working->mPicture->serialize(&measure);
- LOGD(" [%d]"
+ ALOGD(" [%d]"
" mArea.bounds={%d,%d,r=%d,b=%d}"
" mPicture=%p"
" mUnsplit={%d,%d,r=%d,b=%d}"
@@ -1016,40 +1044,6 @@ void PictureSet::set(const PictureSet& src)
#ifdef FAST_PICTURESET
#else
-bool PictureSet::reuseSubdivided(const SkRegion& inval)
-{
- validate(__FUNCTION__);
-
- if (inval.isComplex())
- return false;
- Pictures* working, * last = mPictures.end();
- const SkIRect& invalBounds = inval.getBounds();
- bool steal = false;
- for (working = mPictures.begin(); working != last; working++) {
- if (working->mSplit && invalBounds == working->mUnsplit) {
- steal = true;
- continue;
- }
- if (steal == false)
- continue;
- SkRegion temp = SkRegion(inval);
- temp.op(working->mArea, SkRegion::kIntersect_Op);
- if (temp.isEmpty() || temp == working->mArea)
- continue;
- return false;
- }
- if (steal == false)
- return false;
- for (working = mPictures.begin(); working != last; working++) {
- if ((working->mSplit == false || invalBounds != working->mUnsplit) &&
- inval.contains(working->mArea) == false)
- continue;
- SkSafeUnref(working->mPicture);
- working->mPicture = NULL;
- }
- return true;
-}
-
void PictureSet::setDrawTimes(const PictureSet& src)
{
validate(__FUNCTION__);
@@ -1071,8 +1065,8 @@ void PictureSet::setDrawTimes(const PictureSet& src)
}
DBG_SET_LOGD("%p [%d] [%d] {%d,%d,r=%d,b=%d} working->mElapsed=%d <- %d",
this, working - mPictures.begin(), srcWorking - src.mPictures.begin(),
- working->mArea.getBounds().fLeft, working->mArea.getBounds().fTop,
- working->mArea.getBounds().fRight, working->mArea.getBounds().fBottom,
+ working->mArea.fLeft, working->mArea.fTop,
+ working->mArea.fRight, working->mArea.fBottom,
working->mElapsed, srcWorking->mElapsed);
working->mElapsed = srcWorking->mElapsed;
}
@@ -1115,14 +1109,14 @@ void PictureSet::split(PictureSet* out) const
split ? "true" : "false");
if (multiUnsplitFastPictures <= 1 || split) {
total->op(working->mArea, SkRegion::kDifference_Op);
- out->add(working->mArea, working->mPicture, elapsed, split,
+ out->add(working->mArea, elapsed, split,
working->mEmpty);
} else if (balance < elapsed)
balance = elapsed;
continue;
}
total->op(working->mArea, SkRegion::kDifference_Op);
- const SkIRect& bounds = working->mArea.getBounds();
+ const SkIRect& bounds = working->mArea;
int width = bounds.width();
int height = bounds.height();
int across = 1;
@@ -1148,8 +1142,7 @@ void PictureSet::split(PictureSet* out) const
int right = bounds.fLeft + width * ++indexX / across;
SkIRect cBounds;
cBounds.set(left, top, right, bottom);
- out->add(SkRegion(cBounds), (across | down) != 1 ? NULL :
- working->mPicture, elapsed, true,
+ out->add(cBounds, elapsed, true,
(across | down) != 1 ? false : working->mEmpty);
left = right;
}
@@ -1160,7 +1153,7 @@ void PictureSet::split(PictureSet* out) const
this, mWidth, mHeight, total->isEmpty() ? "true" : "false",
multiUnsplitFastPictures);
if (!total->isEmpty() && multiUnsplitFastPictures > 1)
- out->add(*total, NULL, balance, false, false);
+ out->add(*total, balance, false);
delete total;
validate(__FUNCTION__);
out->dump("split-out");
@@ -1184,24 +1177,24 @@ bool PictureSet::validate(const char* funct) const
const SkIRect& bounds = area.getBounds();
bool localValid = false;
if (working->mUnsplit.isEmpty())
- LOGD("%s working->mUnsplit.isEmpty()", funct);
+ ALOGD("%s working->mUnsplit.isEmpty()", funct);
else if (working->mUnsplit.contains(bounds) == false)
- LOGD("%s working->mUnsplit.contains(bounds) == false", funct);
+ ALOGD("%s working->mUnsplit.contains(bounds) == false", funct);
else if (working->mElapsed >= 1000)
- LOGD("%s working->mElapsed >= 1000", funct);
+ ALOGD("%s working->mElapsed >= 1000", funct);
else if ((working->mSplit & 0xfe) != 0)
- LOGD("%s (working->mSplit & 0xfe) != 0", funct);
+ ALOGD("%s (working->mSplit & 0xfe) != 0", funct);
else if ((working->mWroteElapsed & 0xfe) != 0)
- LOGD("%s (working->mWroteElapsed & 0xfe) != 0", funct);
+ ALOGD("%s (working->mWroteElapsed & 0xfe) != 0", funct);
else if (pict != NULL) {
int pictWidth = pict->width();
int pictHeight = pict->height();
if (pictWidth < bounds.width())
- LOGD("%s pictWidth=%d < bounds.width()=%d", funct, pictWidth, bounds.width());
+ ALOGD("%s pictWidth=%d < bounds.width()=%d", funct, pictWidth, bounds.width());
else if (pictHeight < bounds.height())
- LOGD("%s pictHeight=%d < bounds.height()=%d", funct, pictHeight, bounds.height());
+ ALOGD("%s pictHeight=%d < bounds.height()=%d", funct, pictHeight, bounds.height());
else if (working->mArea.isEmpty())
- LOGD("%s working->mArea.isEmpty()", funct);
+ ALOGD("%s working->mArea.isEmpty()", funct);
else
localValid = true;
} else
@@ -1209,7 +1202,7 @@ bool PictureSet::validate(const char* funct) const
working->mArea.validate();
if (localValid == false) {
if (all.contains(area) == true)
- LOGD("%s all.contains(area) == true", funct);
+ ALOGD("%s all.contains(area) == true", funct);
else
localValid = true;
}
@@ -1220,9 +1213,9 @@ bool PictureSet::validate(const char* funct) const
if (valid) {
valid = false;
if (allBounds.width() != mWidth)
- LOGD("%s allBounds.width()=%d != mWidth=%d", funct, allBounds.width(), mWidth);
+ ALOGD("%s allBounds.width()=%d != mWidth=%d", funct, allBounds.width(), mWidth);
else if (allBounds.height() != mHeight)
- LOGD("%s allBounds.height()=%d != mHeight=%d", funct, allBounds.height(), mHeight);
+ ALOGD("%s allBounds.height()=%d != mHeight=%d", funct, allBounds.height(), mHeight);
else
valid = true;
}