diff options
-rw-r--r-- | WebCore/platform/graphics/android/LayerAndroid.cpp | 83 | ||||
-rw-r--r-- | WebCore/platform/graphics/android/LayerAndroid.h | 23 | ||||
-rw-r--r-- | WebKit/android/nav/WebView.cpp | 10 |
3 files changed, 92 insertions, 24 deletions
diff --git a/WebCore/platform/graphics/android/LayerAndroid.cpp b/WebCore/platform/graphics/android/LayerAndroid.cpp index 44f19c2..0561731 100644 --- a/WebCore/platform/graphics/android/LayerAndroid.cpp +++ b/WebCore/platform/graphics/android/LayerAndroid.cpp @@ -159,12 +159,6 @@ void LayerAndroid::setBackgroundColor(SkColor color) static int gDebugChildLevel; -void LayerAndroid::draw(SkCanvas* canvas, const SkRect* viewPort) -{ - gDebugChildLevel = 0; - paintChildren(viewPort, canvas, 1); -} - void LayerAndroid::bounds(SkRect* rect) const { rect->fLeft = m_position.fX + m_translation.fX; @@ -247,8 +241,30 @@ void LayerAndroid::paintChildren(const SkRect* viewPort, SkCanvas* canvas, canvas->restoreToCount(count); } -bool LayerAndroid::calcPosition(const SkRect* viewPort, - SkMatrix* matrix) { +void LayerAndroid::updatePosition(const SkRect& viewPort) { + if (m_isFixed) { + float x = 0; + float y = 0; + float w = viewPort.width(); + float h = viewPort.height(); + float dx = viewPort.fLeft; + float dy = viewPort.fTop; + + if (m_fixedLeft.defined()) + x = dx + m_fixedLeft.calcFloatValue(w); + else if (m_fixedRight.defined()) + x = dx + w - m_fixedRight.calcFloatValue(w) - m_size.width(); + + if (m_fixedTop.defined()) + y = dy + m_fixedTop.calcFloatValue(h); + else if (m_fixedBottom.defined()) + y = dy + h - m_fixedBottom.calcFloatValue(h) - m_size.height(); + + this->setPosition(x, y); + } +} + +bool LayerAndroid::calcPosition(SkCanvas* canvas, const SkRect* viewPort) { if (viewPort && m_isFixed) { float x = 0; float y = 0; @@ -267,14 +283,51 @@ bool LayerAndroid::calcPosition(const SkRect* viewPort, else if (m_fixedBottom.defined()) y = dy + h - m_fixedBottom.calcFloatValue(h) - m_size.height(); - if (matrix) - matrix->setTranslate(x, y); - setPosition(x, y); + this->setPosition(x, y); + canvas->translate(x, y); return true; } return false; } +void LayerAndroid::onSetupCanvas(SkCanvas* canvas, SkScalar opacity, + const SkRect* viewport) { + if (!this->calcPosition(canvas, viewport)) { + SkMatrix matrix; + matrix.setTranslate(m_translation.fX, m_translation.fY); + if (m_doRotation) { + matrix.preRotate(m_angleTransform); + } + matrix.preScale(m_scale.fX, m_scale.fY); + this->setMatrix(matrix); + + this->INHERITED::onSetupCanvas(canvas, opacity, viewport); + } + + if (m_haveClip) { + SkRect r; + r.set(0, 0, getSize().width(), getSize().height()); + canvas->clipRect(r); + } +} + +void LayerAndroid::onDraw(SkCanvas* canvas, SkScalar opacity, + const SkRect* viewport) { + if (!prepareContext()) + return; + + if (!m_haveImage && !m_drawsContent && !m_isRootLayer) + return; + + SkAutoCanvasRestore restore(canvas, true); + + int canvasOpacity = SkScalarRound(opacity * 255); + if (canvasOpacity < 255) + canvas->setDrawFilter(new OpacityDrawFilter(canvasOpacity)); + + m_recordingPicture->draw(canvas); +} + void LayerAndroid::paintMe(const SkRect* viewPort, SkCanvas* canvas, float opacity) @@ -302,11 +355,9 @@ void LayerAndroid::paintMe(const SkRect* viewPort, */ float x, y; - SkMatrix matrix; - if (!calcPosition(viewPort, - &matrix)) { + if (!calcPosition(canvas, viewPort)) { + SkMatrix matrix; matrix.reset(); - if (m_doRotation) { float anchorX = m_anchorPoint.fX * m_size.width(); float anchorY = m_anchorPoint.fY * m_size.height(); @@ -325,8 +376,8 @@ void LayerAndroid::paintMe(const SkRect* viewPort, } matrix.postTranslate(m_translation.fX + m_position.fX, m_translation.fY + m_position.fY); + canvas->concat(matrix); } - canvas->concat(matrix); m_recordingPicture->draw(canvas); diff --git a/WebCore/platform/graphics/android/LayerAndroid.h b/WebCore/platform/graphics/android/LayerAndroid.h index 841eeb8..9037dc5 100644 --- a/WebCore/platform/graphics/android/LayerAndroid.h +++ b/WebCore/platform/graphics/android/LayerAndroid.h @@ -52,7 +52,7 @@ public: virtual void setBackgroundColor(SkColor color); void setIsRootLayer(bool isRootLayer) { m_isRootLayer = isRootLayer; } - virtual void draw(SkCanvas*, const SkRect* viewPort); +// virtual void draw(SkCanvas*, SkScalar opacity, const SkRect* viewPort); bool prepareContext(bool force = false); void startRecording(); void stopRecording(); @@ -70,7 +70,11 @@ public: void dumpLayers(FILE*, int indentLevel) const; void bounds(SkRect* ) const; - bool calcPosition(const SkRect* viewPort, SkMatrix*); + /** Call this with the current viewport (scrolling, zoom) to update its + position attribute, so that later calls like bounds() will report the + corrected position (assuming the layer had fixed-positioning). + */ + void updatePosition(const SkRect& viewPort); void clipArea(SkTDArray<SkRect>* region) const; const LayerAndroid* find(int x, int y) const; const LayerAndroid* findById(int uniqueID) const; @@ -81,7 +85,18 @@ public: private: bool boundsIsUnique(SkTDArray<SkRect>* region, const SkRect& local) const; void clipInner(SkTDArray<SkRect>* region, const SkRect& local) const; - void paintChildren(const SkRect* viewPort, SkCanvas* canvas, float opacity); + +protected: + virtual void onSetupCanvas(SkCanvas*, SkScalar opacity, const SkRect*); + virtual void onDraw(SkCanvas*, SkScalar opacity, const SkRect* viewPort); + +private: + + bool calcPosition(SkCanvas*, const SkRect* viewPort); + + void paintChildren(const SkRect* viewPort, SkCanvas* canvas, + float opacity); + void paintMe(const SkRect* viewPort, SkCanvas* canvas, float opacity); @@ -97,6 +112,8 @@ private: KeyframesMap m_animations; FindOnPage* m_findOnPage; int m_uniqueId; + + typedef SkLayer INHERITED; }; } diff --git a/WebKit/android/nav/WebView.cpp b/WebKit/android/nav/WebView.cpp index 04e9336..8ec4cca 100644 --- a/WebKit/android/nav/WebView.cpp +++ b/WebKit/android/nav/WebView.cpp @@ -558,7 +558,7 @@ CachedRoot* getFrameCache(FrameCachePermission allowNewer) getViewMetrics(&viewMetrics); LayerAndroid* layer = const_cast<LayerAndroid*>( m_frameCacheUI->rootLayer()->findById(layerId)); - layer->calcPosition(&viewMetrics, 0); + layer->updatePosition(viewMetrics); } #endif fixCursor(); @@ -630,9 +630,9 @@ void getViewMetrics(SkRect* viewMetrics) int scrollY = env->GetIntField(jMetrics, m_javaGlue.m_metricsScrollY); int width = env->GetIntField(jMetrics, m_javaGlue.m_metricsWidth); int height = env->GetIntField(jMetrics, m_javaGlue.m_metricsHeight); - int scale = env->GetFloatField(jMetrics, m_javaGlue.m_metricsScale); - *viewMetrics = IntRect(scrollX / scale, scrollY / scale, - width / scale, height / scale); + float scale = env->GetFloatField(jMetrics, m_javaGlue.m_metricsScale); + viewMetrics->set(scrollX / scale, scrollY / scale, + (scrollX + width) / scale, (scrollY + height) / scale); env->DeleteLocalRef(jMetrics); checkException(env); } @@ -1457,7 +1457,7 @@ static void nativeDrawLayers(JNIEnv *env, jobject obj, jint layer, jobject canv) SkRect viewMetrics; view->getViewMetrics(&viewMetrics); layerImpl->setFindOnPage(view->findOnPage()); - layerImpl->draw(canvas, &viewMetrics); + layerImpl->draw(canvas, SK_Scalar1, &viewMetrics); #endif } |