diff options
14 files changed, 140 insertions, 74 deletions
diff --git a/Source/WebCore/platform/android/RenderThemeAndroid.cpp b/Source/WebCore/platform/android/RenderThemeAndroid.cpp index c6e3bc5..7ef814e 100644 --- a/Source/WebCore/platform/android/RenderThemeAndroid.cpp +++ b/Source/WebCore/platform/android/RenderThemeAndroid.cpp @@ -212,9 +212,12 @@ void RenderThemeAndroid::adjustButtonStyle(CSSStyleSelector*, RenderStyle* style { // Code is taken from RenderThemeSafari.cpp // It makes sure we have enough space for the button text. - const int padding = 8; - style->setPaddingLeft(Length(padding, Fixed)); - style->setPaddingRight(Length(padding, Fixed)); + const int paddingHoriz = 12; + const int paddingVert = 8; + style->setPaddingLeft(Length(paddingHoriz, Fixed)); + style->setPaddingRight(Length(paddingHoriz, Fixed)); + style->setPaddingTop(Length(paddingVert, Fixed)); + style->setPaddingBottom(Length(paddingVert, Fixed)); // Set a min-height so that we can't get smaller than the mini button. style->setMinHeight(Length(15, Fixed)); diff --git a/Source/WebCore/platform/graphics/android/BaseLayerAndroid.cpp b/Source/WebCore/platform/graphics/android/BaseLayerAndroid.cpp index 0ab28d7..547ac39 100644 --- a/Source/WebCore/platform/graphics/android/BaseLayerAndroid.cpp +++ b/Source/WebCore/platform/graphics/android/BaseLayerAndroid.cpp @@ -54,6 +54,12 @@ #endif // DEBUG +// TODO: dynamically determine based on DPI +#define PREFETCH_SCALE_MODIFIER 0.3 +#define PREFETCH_OPACITY 1 +#define PREFETCH_X_DIST 1 +#define PREFETCH_Y_DIST 2 + namespace WebCore { using namespace android; @@ -116,6 +122,49 @@ void BaseLayerAndroid::drawCanvas(SkCanvas* canvas) } #if USE(ACCELERATED_COMPOSITING) + +void BaseLayerAndroid::prefetchBasePicture(SkRect& viewport, float currentScale, + TiledPage* prefetchTiledPage) +{ + SkIRect bounds; + float prefetchScale = currentScale * PREFETCH_SCALE_MODIFIER; + + float invTileWidth = (prefetchScale) + / TilesManager::instance()->tileWidth(); + float invTileHeight = (prefetchScale) + / TilesManager::instance()->tileHeight(); + bool goingDown = m_glWebViewState->goingDown(); + bool goingLeft = m_glWebViewState->goingLeft(); + + + XLOG("fetch rect %f %f %f %f, scale %f", + viewport.fLeft, + viewport.fTop, + viewport.fRight, + viewport.fBottom, + scale); + + bounds.fLeft = static_cast<int>(floorf(viewport.fLeft * invTileWidth)) - PREFETCH_X_DIST; + bounds.fTop = static_cast<int>(floorf(viewport.fTop * invTileHeight)) - PREFETCH_Y_DIST; + bounds.fRight = static_cast<int>(ceilf(viewport.fRight * invTileWidth)) + PREFETCH_X_DIST; + bounds.fBottom = static_cast<int>(ceilf(viewport.fBottom * invTileHeight)) + PREFETCH_Y_DIST; + + XLOG("prefetch rect %d %d %d %d, scale %f, preparing page %p", + bounds.fLeft, bounds.fTop, + bounds.fRight, bounds.fBottom, + scale * PREFETCH_SCALE, + prefetchTiledPage); + + prefetchTiledPage->setScale(prefetchScale); + prefetchTiledPage->updateTileDirtiness(bounds); + prefetchTiledPage->prepare(goingDown, goingLeft, bounds, + TiledPage::ExpandedBounds); + prefetchTiledPage->swapBuffersIfReady(bounds, + prefetchScale, + TiledPage::SwapWhateverIsReady); + prefetchTiledPage->draw(PREFETCH_OPACITY, bounds); +} + bool BaseLayerAndroid::drawBasePictureInGL(SkRect& viewport, float scale, double currentTime, bool* buffersSwappedPtr) { @@ -183,6 +232,13 @@ bool BaseLayerAndroid::drawBasePictureInGL(SkRect& viewport, float scale, bool scrolling = m_scrollState != NotScrolling; bool zooming = ZoomManager::kNoScaleRequest != zoomManager->scaleRequestState(); + // prefetch in the nextTiledPage if unused by zooming (even if not scrolling + // since we want the tiles to be ready before they're needed) + bool usePrefetchPage = !zooming; + nextTiledPage->setIsPrefetchPage(usePrefetchPage); + if (usePrefetchPage) + prefetchBasePicture(viewport, scale, nextTiledPage); + // When we aren't zooming, we should TRY and swap tile buffers if they're // ready. When scrolling, we swap whatever's ready. Otherwise, buffer until // the entire page is ready and then swap. @@ -287,7 +343,6 @@ bool BaseLayerAndroid::drawGL(double currentTime, LayerAndroid* compositedRoot, m_glWebViewState->resetLayersDirtyArea(); } - m_glWebViewState->paintExtras(); m_previousVisible = visibleRect; diff --git a/Source/WebCore/platform/graphics/android/BaseLayerAndroid.h b/Source/WebCore/platform/graphics/android/BaseLayerAndroid.h index a42a372..26fd158 100644 --- a/Source/WebCore/platform/graphics/android/BaseLayerAndroid.h +++ b/Source/WebCore/platform/graphics/android/BaseLayerAndroid.h @@ -66,6 +66,8 @@ public: void swapExtra(BaseLayerAndroid* base) { m_extra.swap(base->m_extra); } private: #if USE(ACCELERATED_COMPOSITING) + void prefetchBasePicture(SkRect& viewport, float currentScale, + TiledPage* prefetchTiledPage); bool drawBasePictureInGL(SkRect& viewport, float scale, double currentTime, bool* buffersSwappedPtr); diff --git a/Source/WebCore/platform/graphics/android/GLWebViewState.cpp b/Source/WebCore/platform/graphics/android/GLWebViewState.cpp index c0f6623..0b2d058 100644 --- a/Source/WebCore/platform/graphics/android/GLWebViewState.cpp +++ b/Source/WebCore/platform/graphics/android/GLWebViewState.cpp @@ -180,8 +180,12 @@ void GLWebViewState::setRings(Vector<IntRect>& rings, bool isPressed) android::Mutex::Autolock lock(m_baseLayerLock); m_displayRings = true; m_rings.setEmpty(); - for (size_t i = 0; i < rings.size(); i++) - m_rings.op(rings.at(i), SkRegion::kUnion_Op); + for (size_t i = 0; i < rings.size(); i++) { + if (i == 0) + m_rings.setRect(rings.at(i)); + else + m_rings.op(rings.at(i), SkRegion::kUnion_Op); + } m_ringsIsPressed = isPressed; } @@ -569,6 +573,10 @@ bool GLWebViewState::drawGL(IntRect& rect, SkRect& viewport, IntRect* invalRect, double currentTime = setupDrawing(rect, viewport, webViewRect, titleBarHeight, clip, scale); bool ret = baseLayer->drawGL(currentTime, compositedRoot, rect, viewport, scale, buffersSwappedPtr); + // Reset the clip to make sure we can draw the rings. If this isn't done, the + // current clip will be the clip of whatever layer was last drawn + TilesManager::instance()->shader()->clip(clip); + paintExtras(); glBindBuffer(GL_ARRAY_BUFFER, 0); diff --git a/Source/WebCore/platform/graphics/android/GraphicsContextAndroid.cpp b/Source/WebCore/platform/graphics/android/GraphicsContextAndroid.cpp index e015f5a..86e1f63 100644 --- a/Source/WebCore/platform/graphics/android/GraphicsContextAndroid.cpp +++ b/Source/WebCore/platform/graphics/android/GraphicsContextAndroid.cpp @@ -380,12 +380,13 @@ public: m_state->antiAliasClipPaths.append(clipPath); if (!haveLayerOutstanding) { SkRect bounds = clipPath.getBounds(); - if (m_platformGfxCtx && m_platformGfxCtx->mCanvas) + if (m_platformGfxCtx && m_platformGfxCtx->mCanvas) { m_platformGfxCtx->mCanvas->saveLayerAlpha(&bounds, 255, static_cast<SkCanvas::SaveFlags>(SkCanvas::kHasAlphaLayer_SaveFlag | SkCanvas::kFullColorLayer_SaveFlag | SkCanvas::kClipToLayer_SaveFlag)); - else + m_platformGfxCtx->mCanvas->save(); + } else ASSERT(0); } } @@ -395,6 +396,10 @@ public: // Anti-aliased clipping: // // Refer to PlatformContextSkia.cpp's applyAntiAliasedClipPaths() for more details + + if (m_platformGfxCtx && m_platformGfxCtx->mCanvas) + m_platformGfxCtx->mCanvas->restore(); + SkPaint paint; paint.setXfermodeMode(SkXfermode::kClear_Mode); paint.setAntiAlias(true); diff --git a/Source/WebCore/platform/graphics/android/Layer.cpp b/Source/WebCore/platform/graphics/android/Layer.cpp index 22c40f1..361cb4e 100644 --- a/Source/WebCore/platform/graphics/android/Layer.cpp +++ b/Source/WebCore/platform/graphics/android/Layer.cpp @@ -18,9 +18,9 @@ Layer::Layer() { m_position.set(0, 0); m_anchorPoint.set(SK_ScalarHalf, SK_ScalarHalf); - fMatrix.reset(); - fChildrenMatrix.reset(); - fFlags = 0; + m_matrix.reset(); + m_childrenMatrix.reset(); + m_shouldInheritFromRootTransform = false; m_hasOverflowChildren = false; @@ -37,9 +37,9 @@ Layer::Layer(const Layer& src) : INHERITED() { m_position = src.m_position; m_anchorPoint = src.m_anchorPoint; - fMatrix = src.fMatrix; - fChildrenMatrix = src.fChildrenMatrix; - fFlags = src.fFlags; + m_matrix = src.m_matrix; + m_childrenMatrix = src.m_childrenMatrix; + m_shouldInheritFromRootTransform = src.m_shouldInheritFromRootTransform; m_hasOverflowChildren = src.m_hasOverflowChildren; @@ -50,7 +50,7 @@ Layer::Layer(const Layer& src) : INHERITED() { } Layer::~Layer() { - this->removeChildren(); + removeChildren(); #ifdef DEBUG_TRACK_NEW_DELETE gLayerAllocCount -= 1; @@ -60,28 +60,6 @@ Layer::~Layer() { /////////////////////////////////////////////////////////////////////////////// -bool Layer::isInheritFromRootTransform() const { - return (fFlags & kInheritFromRootTransform_Flag) != 0; -} - -void Layer::setInheritFromRootTransform(bool doInherit) { - if (doInherit) { - fFlags |= kInheritFromRootTransform_Flag; - } else { - fFlags &= ~kInheritFromRootTransform_Flag; - } -} - -void Layer::setMatrix(const SkMatrix& matrix) { - fMatrix = matrix; -} - -void Layer::setChildrenMatrix(const SkMatrix& matrix) { - fChildrenMatrix = matrix; -} - -/////////////////////////////////////////////////////////////////////////////// - int Layer::countChildren() const { return m_children.count(); } @@ -111,7 +89,7 @@ void Layer::detachFromParent() { SkASSERT(index >= 0); fParent->m_children.remove(index); fParent = NULL; - this->unref(); // this call might delete us + unref(); // this call might delete us } } @@ -142,15 +120,15 @@ void Layer::getLocalTransform(SkMatrix* matrix) const { SkScalar tx = SkScalarMul(m_anchorPoint.fX, m_size.width()); SkScalar ty = SkScalarMul(m_anchorPoint.fY, m_size.height()); matrix->preTranslate(tx, ty); - matrix->preConcat(this->getMatrix()); + matrix->preConcat(getMatrix()); matrix->preTranslate(-tx, -ty); } void Layer::localToGlobal(SkMatrix* matrix) const { - this->getLocalTransform(matrix); + getLocalTransform(matrix); - if (this->isInheritFromRootTransform()) { - matrix->postConcat(this->getRootLayer()->getMatrix()); + if (shouldInheritFromRootTransform()) { + matrix->postConcat(getRootLayer()->getMatrix()); return; } @@ -176,14 +154,14 @@ void Layer::onDraw(SkCanvas*, SkScalar opacity) { void Layer::draw(SkCanvas* canvas, SkScalar opacity) { #if 0 SkString str1, str2; - // this->getMatrix().toDumpString(&str1); - // this->getChildrenMatrix().toDumpString(&str2); + // getMatrix().toDumpString(&str1); + // getChildrenMatrix().toDumpString(&str2); SkDebugf("--- drawlayer %p opacity %g size [%g %g] pos [%g %g] matrix %s children %s\n", - this, opacity * this->getOpacity(), m_size.width(), m_size.height(), + this, opacity * getOpacity(), m_size.width(), m_size.height(), m_position.fX, m_position.fY, str1.c_str(), str2.c_str()); #endif - opacity = SkScalarMul(opacity, this->getOpacity()); + opacity = SkScalarMul(opacity, getOpacity()); if (opacity <= 0) { // SkDebugf("---- abort drawing %p opacity %g\n", this, opacity); return; @@ -194,19 +172,19 @@ void Layer::draw(SkCanvas* canvas, SkScalar opacity) { // apply our local transform { SkMatrix tmp; - this->getLocalTransform(&tmp); - if (this->isInheritFromRootTransform()) { + getLocalTransform(&tmp); + if (shouldInheritFromRootTransform()) { // should we also apply the root's childrenMatrix? canvas->setMatrix(getRootLayer()->getMatrix()); } canvas->concat(tmp); } - this->onDraw(canvas, opacity); + onDraw(canvas, opacity); #ifdef DEBUG_DRAW_LAYER_BOUNDS { - SkRect r = SkRect::MakeSize(this->getSize()); + SkRect r = SkRect::MakeSize(getSize()); SkPaint p; p.setAntiAlias(true); p.setStyle(SkPaint::kStroke_Style); @@ -218,11 +196,11 @@ void Layer::draw(SkCanvas* canvas, SkScalar opacity) { } #endif - int count = this->countChildren(); + int count = countChildren(); if (count > 0) { - canvas->concat(this->getChildrenMatrix()); + canvas->concat(getChildrenMatrix()); for (int i = 0; i < count; i++) { - this->getChild(i)->draw(canvas, opacity); + getChild(i)->draw(canvas, opacity); } } } diff --git a/Source/WebCore/platform/graphics/android/Layer.h b/Source/WebCore/platform/graphics/android/Layer.h index 107c457..7b27349 100644 --- a/Source/WebCore/platform/graphics/android/Layer.h +++ b/Source/WebCore/platform/graphics/android/Layer.h @@ -34,24 +34,27 @@ public: Layer(const Layer&); virtual ~Layer(); - bool isInheritFromRootTransform() const; + // Whether the layer should apply its tranform directly onto the root + // layer, rather than using the transforms of all ancestor layers. This is + // used for fixed position layers. + bool shouldInheritFromRootTransform() const { return m_shouldInheritFromRootTransform; } SkScalar getOpacity() const { return m_opacity; } const SkSize& getSize() const { return m_size; } const SkPoint& getPosition() const { return m_position; } const SkPoint& getAnchorPoint() const { return m_anchorPoint; } - const SkMatrix& getMatrix() const { return fMatrix; } - const SkMatrix& getChildrenMatrix() const { return fChildrenMatrix; } + const SkMatrix& getMatrix() const { return m_matrix; } + const SkMatrix& getChildrenMatrix() const { return m_childrenMatrix; } SkScalar getWidth() const { return m_size.width(); } SkScalar getHeight() const { return m_size.height(); } - void setInheritFromRootTransform(bool); + void setShouldInheritFromRootTransform(bool inherit) { m_shouldInheritFromRootTransform = inherit; } void setOpacity(SkScalar opacity) { m_opacity = opacity; } void setSize(SkScalar w, SkScalar h) { m_size.set(w, h); } void setPosition(SkScalar x, SkScalar y) { m_position.set(x, y); } void setAnchorPoint(SkScalar x, SkScalar y) { m_anchorPoint.set(x, y); } - void setMatrix(const SkMatrix&); - void setChildrenMatrix(const SkMatrix&); + void setMatrix(const SkMatrix& matrix) { m_matrix = matrix; } + void setChildrenMatrix(const SkMatrix& matrix) { m_childrenMatrix = matrix; } // children @@ -118,10 +121,6 @@ protected: bool m_hasOverflowChildren; private: - enum Flags { - kInheritFromRootTransform_Flag = 0x01 - }; - Layer* fParent; SkScalar m_opacity; SkSize m_size; @@ -130,9 +129,9 @@ private: // The point in the layer used as the origin for local transformations, // expressed as a fraction of the layer size. SkPoint m_anchorPoint; - SkMatrix fMatrix; - SkMatrix fChildrenMatrix; - uint32_t fFlags; + SkMatrix m_matrix; + SkMatrix m_childrenMatrix; + bool m_shouldInheritFromRootTransform; SkTDArray<Layer*> m_children; diff --git a/Source/WebCore/platform/graphics/android/LayerAndroid.h b/Source/WebCore/platform/graphics/android/LayerAndroid.h index 8078762..31bb185 100644 --- a/Source/WebCore/platform/graphics/android/LayerAndroid.h +++ b/Source/WebCore/platform/graphics/android/LayerAndroid.h @@ -170,7 +170,7 @@ public: m_fixedRect = viewRect; m_isFixed = true; m_renderLayerPos = renderLayerPos; - setInheritFromRootTransform(true); + setShouldInheritFromRootTransform(true); } void setBackgroundColor(SkColor color); diff --git a/Source/WebCore/platform/graphics/android/PaintTileOperation.cpp b/Source/WebCore/platform/graphics/android/PaintTileOperation.cpp index aa3f320..19b49f1 100644 --- a/Source/WebCore/platform/graphics/android/PaintTileOperation.cpp +++ b/Source/WebCore/platform/graphics/android/PaintTileOperation.cpp @@ -81,6 +81,10 @@ int PaintTileOperation::priority() unsigned long long drawDelta = currentDraw - m_tile->drawCount(); int priority = 100000 * (int)std::min(drawDelta, (unsigned long long)1000); + // prioritize the prefetch page, if it exists + if (!m_tile->page() || !m_tile->page()->isPrefetchPage()) + priority += 200000; + // prioritize unpainted tiles, within the same drawCount if (m_tile->frontTexture()) priority += 50000; diff --git a/Source/WebCore/platform/graphics/android/TiledPage.cpp b/Source/WebCore/platform/graphics/android/TiledPage.cpp index ede7d1b..2b8ebcc 100644 --- a/Source/WebCore/platform/graphics/android/TiledPage.cpp +++ b/Source/WebCore/platform/graphics/android/TiledPage.cpp @@ -31,6 +31,8 @@ #include "GLUtils.h" #include "IntRect.h" #include "PaintTileOperation.h" +#include "SkPaint.h" +#include "SkPaintFlagsDrawFilter.h" #include "TilesManager.h" #include <cutils/log.h> @@ -65,6 +67,7 @@ TiledPage::TiledPage(int id, GLWebViewState* state) , m_glWebViewState(state) , m_latestPictureInval(0) , m_prepare(false) + , m_isPrefetchPage(false) { m_baseTiles = new BaseTile[TilesManager::getMaxTextureAllocation() + 1]; #ifdef DEBUG_COUNT @@ -366,9 +369,15 @@ void TiledPage::draw(float transparency, const SkIRect& tileBounds) bool TiledPage::paint(BaseTile* tile, SkCanvas* canvas, unsigned int* pictureUsed) { + // TODO: consider other flags so the pre-rendered tiles aren't so ugly + static SkPaintFlagsDrawFilter prefetchFilter(SkPaint::kAllFlags, 0); + if (!m_glWebViewState) return false; + if (isPrefetchPage()) + canvas->setDrawFilter(&prefetchFilter); + *pictureUsed = m_glWebViewState->paintBaseLayerContent(canvas); return true; } diff --git a/Source/WebCore/platform/graphics/android/TiledPage.h b/Source/WebCore/platform/graphics/android/TiledPage.h index 946421c..c903abc 100644 --- a/Source/WebCore/platform/graphics/android/TiledPage.h +++ b/Source/WebCore/platform/graphics/android/TiledPage.h @@ -98,6 +98,8 @@ public: void updateBaseTileSize(); bool scrollingDown() { return m_scrollingDown; } SkIRect* expandedTileBounds() { return &m_expandedTileBounds; } + bool isPrefetchPage() { return m_isPrefetchPage; } + void setIsPrefetchPage(bool isPrefetch) { m_isPrefetchPage = isPrefetch; } private: void prepareRow(bool goingLeft, int tilesInRow, int firstTileX, int y, const SkIRect& tileBounds); @@ -127,6 +129,7 @@ private: bool m_prepare; bool m_scrollingDown; SkIRect m_expandedTileBounds; + bool m_isPrefetchPage; }; } // namespace WebCore diff --git a/Source/WebKit/android/WebCoreSupport/FrameLoaderClientAndroid.cpp b/Source/WebKit/android/WebCoreSupport/FrameLoaderClientAndroid.cpp index 31eed62..3134a44 100644 --- a/Source/WebKit/android/WebCoreSupport/FrameLoaderClientAndroid.cpp +++ b/Source/WebKit/android/WebCoreSupport/FrameLoaderClientAndroid.cpp @@ -919,6 +919,10 @@ void FrameLoaderClientAndroid::transitionToCommittedFromCachedFrame(WebCore::Cac #ifdef ANDROID_META_SUPPORT platformData->restoreMetadata(m_frame->settings()); #endif + WebViewCore* webViewCore = WebViewCore::getWebViewCore(m_frame->view()); + + webViewCore->clearContent(); + m_webFrame->transitionToCommitted(m_frame); } @@ -952,6 +956,7 @@ void FrameLoaderClientAndroid::transitionToCommittedForNewPage() { // Create a new WebFrameView for the new FrameView WebFrameView* newFrameView = new WebFrameView(m_frame->view(), webViewCore); + webViewCore->clearContent(); newFrameView->setLocation(bounds.x(), bounds.y()); newFrameView->setSize(bounds.width(), bounds.height()); newFrameView->setVisibleSize(visBounds.width(), visBounds.height()); diff --git a/Source/WebKit/android/jni/ViewStateSerializer.cpp b/Source/WebKit/android/jni/ViewStateSerializer.cpp index 794c118..b3556c3 100644 --- a/Source/WebKit/android/jni/ViewStateSerializer.cpp +++ b/Source/WebKit/android/jni/ViewStateSerializer.cpp @@ -257,7 +257,7 @@ void serializeLayer(LayerAndroid* layer, SkWStream* stream) stream->write8(type); // Start with Layer fields - stream->writeBool(layer->isInheritFromRootTransform()); + stream->writeBool(layer->shouldInheritFromRootTransform()); stream->writeScalar(layer->getOpacity()); stream->writeScalar(layer->getSize().width()); stream->writeScalar(layer->getSize().height()); @@ -338,7 +338,7 @@ LayerAndroid* deserializeLayer(SkStream* stream) } // Layer fields - layer->setInheritFromRootTransform(stream->readBool()); + layer->setShouldInheritFromRootTransform(stream->readBool()); layer->setOpacity(stream->readScalar()); layer->setSize(stream->readScalar(), stream->readScalar()); layer->setPosition(stream->readScalar(), stream->readScalar()); diff --git a/Source/WebKit/android/jni/WebCoreFrameBridge.cpp b/Source/WebKit/android/jni/WebCoreFrameBridge.cpp index f243b09..46499b1 100644 --- a/Source/WebKit/android/jni/WebCoreFrameBridge.cpp +++ b/Source/WebKit/android/jni/WebCoreFrameBridge.cpp @@ -1479,11 +1479,6 @@ static void LoadUrl(JNIEnv *env, jobject obj, jstring url, jobject headers) } LOGV("LoadUrl %s", kurl.string().latin1().data()); pFrame->loader()->load(request, false); - - // Loading a new URL, clear the picture set. - WebCore::FrameView* view = pFrame->view(); - if (view) - WebViewCore::getWebViewCore(view)->clearContent(); } static void PostUrl(JNIEnv *env, jobject obj, jstring url, jbyteArray postData) |