From 3adbe453816c9282bfe1d212e813661ce2590955 Mon Sep 17 00:00:00 2001 From: Nicolas Roard Date: Tue, 4 Oct 2011 18:01:40 -0700 Subject: Streamline the layers update codepath. Directly update the layers transform and position. This makes updates faster and less dependent on other webkit work. counterpart java CL: https://android-git.corp.google.com/g/#/c/139853/ bug:5218173 Change-Id: I03a76ab853e81f0f12177fb785707ffb8dace330 --- Source/WebCore/platform/graphics/android/Layer.h | 1 - .../platform/graphics/android/LayerAndroid.cpp | 35 ++++++++++++++++++++++ .../platform/graphics/android/LayerAndroid.h | 6 ++++ Source/WebKit/android/jni/WebViewCore.cpp | 33 ++++++++++++-------- Source/WebKit/android/jni/WebViewCore.h | 1 + 5 files changed, 63 insertions(+), 13 deletions(-) (limited to 'Source') diff --git a/Source/WebCore/platform/graphics/android/Layer.h b/Source/WebCore/platform/graphics/android/Layer.h index 24302ce..c8bb81d 100644 --- a/Source/WebCore/platform/graphics/android/Layer.h +++ b/Source/WebCore/platform/graphics/android/Layer.h @@ -136,7 +136,6 @@ protected: bool m_hasOverflowChildren; -private: bool isAncestor(const Layer*) const; Layer* fParent; diff --git a/Source/WebCore/platform/graphics/android/LayerAndroid.cpp b/Source/WebCore/platform/graphics/android/LayerAndroid.cpp index b086c79..4e00a4b 100644 --- a/Source/WebCore/platform/graphics/android/LayerAndroid.cpp +++ b/Source/WebCore/platform/graphics/android/LayerAndroid.cpp @@ -575,6 +575,7 @@ void LayerAndroid::updatePositions() void LayerAndroid::updateGLPositionsAndScale(const TransformationMatrix& parentMatrix, const FloatRect& clipping, float opacity, float scale) { + m_atomicSync.lock(); IntSize layerSize(getSize().width(), getSize().height()); FloatPoint anchorPoint(getAnchorPoint().fX, getAnchorPoint().fY); FloatPoint position(getPosition().fX, getPosition().fY); @@ -593,6 +594,7 @@ void LayerAndroid::updateGLPositionsAndScale(const TransformationMatrix& parentM -originY, -anchorPointZ()); + m_atomicSync.unlock(); setDrawTransform(localMatrix); if (m_drawTransform.isIdentityOrTranslation()) { // adjust the translation coordinates of the draw transform matrix so @@ -762,6 +764,39 @@ void LayerAndroid::assignTextureTo(LayerAndroid* newTree) } } +bool LayerAndroid::updateWithTree(LayerAndroid* newTree) +{ + bool needsRepaint = false; + int count = this->countChildren(); + for (int i = 0; i < count; i++) + needsRepaint |= this->getChild(i)->updateWithTree(newTree); + + if (newTree) { + LayerAndroid* newLayer = newTree->findById(uniqueId()); + needsRepaint |= updateWithLayer(newLayer); + } + return needsRepaint; +} + +bool LayerAndroid::updateWithLayer(LayerAndroid* layer) +{ + if (!layer) + return true; + + android::AutoMutex lock(m_atomicSync); + m_position = layer->m_position; + m_anchorPoint = layer->m_anchorPoint; + m_size = layer->m_size; + m_opacity = layer->m_opacity; + m_transform = layer->m_transform; + + if ((m_recordingPicture != layer->m_recordingPicture) + || (m_imageRef != layer->m_imageRef)) + return true; + + return false; +} + void LayerAndroid::createTexture() { int count = this->countChildren(); diff --git a/Source/WebCore/platform/graphics/android/LayerAndroid.h b/Source/WebCore/platform/graphics/android/LayerAndroid.h index 4ae8bd3..38d867f 100644 --- a/Source/WebCore/platform/graphics/android/LayerAndroid.h +++ b/Source/WebCore/platform/graphics/android/LayerAndroid.h @@ -273,6 +273,12 @@ public: void assignTextureTo(LayerAndroid* newTree); void createTexture(); + // Update layers using another tree. Only works for basic properties + // such as the position, the transform. Return true if anything more + // complex is needed. + bool updateWithTree(LayerAndroid*); + bool updateWithLayer(LayerAndroid*); + SkBitmapRef* imageRef() { return m_imageRef; } ImageTexture* imageTexture() { return m_imageTexture; } int type() { return m_type; } diff --git a/Source/WebKit/android/jni/WebViewCore.cpp b/Source/WebKit/android/jni/WebViewCore.cpp index 26c73b2..6d6b81c 100644 --- a/Source/WebKit/android/jni/WebViewCore.cpp +++ b/Source/WebKit/android/jni/WebViewCore.cpp @@ -919,6 +919,19 @@ void WebViewCore::rebuildPictureSet(PictureSet* pictureSet) #endif } +bool WebViewCore::updateLayers(LayerAndroid* layers) +{ + // We update the layers + ChromeClientAndroid* chromeC = static_cast(m_mainFrame->page()->chrome()->client()); + GraphicsLayerAndroid* root = static_cast(chromeC->layersSync()); + if (root) { + root->notifyClientAnimationStarted(); + LayerAndroid* updatedLayer = root->contentLayer(); + return layers->updateWithTree(updatedLayer); + } + return true; +} + BaseLayerAndroid* WebViewCore::createBaseLayer() { BaseLayerAndroid* base = new BaseLayerAndroid(); @@ -4119,20 +4132,16 @@ void WebViewCore::addVisitedLink(const UChar* string, int length) m_groupForVisitedLinks->addVisitedLink(string, length); } -static jint UpdateLayers(JNIEnv *env, jobject obj, jobject region) +static bool UpdateLayers(JNIEnv *env, jobject obj, jint jbaseLayer) { WebViewCore* viewImpl = GET_NATIVE_VIEW(env, obj); - BaseLayerAndroid* result = viewImpl->createBaseLayer(); - SkRegion* nativeRegion = GraphicsJNI::getNativeRegion(env, region); - if (result) { - SkIRect bounds; - LayerAndroid* root = static_cast(result->getChild(0)); - if (root) { - root->bounds().roundOut(&bounds); - nativeRegion->setRect(bounds); - } + BaseLayerAndroid* baseLayer = (BaseLayerAndroid*) jbaseLayer; + if (baseLayer) { + LayerAndroid* root = static_cast(baseLayer->getChild(0)); + if (root) + return viewImpl->updateLayers(root); } - return reinterpret_cast(result); + return true; } static jint RecordContent(JNIEnv *env, jobject obj, jobject region, jobject pt) @@ -4707,7 +4716,7 @@ static JNINativeMethod gJavaWebViewCoreMethods[] = { (void*) UpdateFrameCache }, { "nativeGetContentMinPrefWidth", "()I", (void*) GetContentMinPrefWidth }, - { "nativeUpdateLayers", "(Landroid/graphics/Region;)I", + { "nativeUpdateLayers", "(I)Z", (void*) UpdateLayers }, { "nativeRecordContent", "(Landroid/graphics/Region;Landroid/graphics/Point;)I", (void*) RecordContent }, diff --git a/Source/WebKit/android/jni/WebViewCore.h b/Source/WebKit/android/jni/WebViewCore.h index 877f716..a25c5bb 100644 --- a/Source/WebKit/android/jni/WebViewCore.h +++ b/Source/WebKit/android/jni/WebViewCore.h @@ -525,6 +525,7 @@ namespace android { // and doing a copy of the layers. The layers' content may be updated // as we are calling layersSync(). BaseLayerAndroid* createBaseLayer(); + bool updateLayers(LayerAndroid*); int textWrapWidth() const { return m_textWrapWidth; } float scale() const { return m_scale; } -- cgit v1.1