From 42326004062d6b846c3050ad03a1e80fa9db425c Mon Sep 17 00:00:00 2001 From: Chris Craik Date: Fri, 28 Sep 2012 15:11:12 -0700 Subject: Determine maxZoomScale from bitmap/text drawing bug:7247750 Change-Id: I8238acc2c20942ab2f42936d16a03226909aebcd --- .../android/context/PlatformGraphicsContextRecording.cpp | 7 +++++-- .../android/context/PlatformGraphicsContextRecording.h | 4 ++-- .../platform/graphics/android/layers/LayerAndroid.cpp | 4 ++-- .../WebCore/platform/graphics/android/layers/LayerAndroid.h | 2 +- .../WebCore/platform/graphics/android/layers/LayerContent.h | 2 +- .../platform/graphics/android/layers/PictureLayerContent.cpp | 8 ++++---- .../platform/graphics/android/layers/PictureLayerContent.h | 2 +- .../graphics/android/layers/PicturePileLayerContent.cpp | 2 +- .../graphics/android/layers/PicturePileLayerContent.h | 4 ++-- .../WebCore/platform/graphics/android/rendering/Surface.cpp | 7 +++---- Source/WebCore/platform/graphics/android/rendering/Surface.h | 3 +-- .../platform/graphics/android/rendering/SurfaceBacking.cpp | 10 +++++----- .../platform/graphics/android/rendering/SurfaceBacking.h | 4 ++-- Source/WebKit/android/jni/PicturePile.cpp | 12 ++++++------ Source/WebKit/android/jni/PicturePile.h | 6 +++--- 15 files changed, 39 insertions(+), 38 deletions(-) diff --git a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.cpp b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.cpp index 867ff56..c865a54 100644 --- a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.cpp +++ b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.cpp @@ -498,7 +498,7 @@ PlatformGraphicsContextRecording::PlatformGraphicsContextRecording(Recording* re , mPicture(0) , mRecording(recording) , mOperationState(0) - , m_hasText(false) + , m_maxZoomScale(1) , m_isEmpty(true) , m_canvasProxy(this) { @@ -524,7 +524,7 @@ bool PlatformGraphicsContextRecording::isPaintingDisabled() SkCanvas* PlatformGraphicsContextRecording::recordingCanvas() { - m_hasText = true; + m_maxZoomScale = 1e6f; return &m_canvasProxy; } @@ -779,6 +779,9 @@ void PlatformGraphicsContextRecording::drawBitmapRect(const SkBitmap& bitmap, const SkIRect* src, const SkRect& dst, CompositeOperator op) { + float widthScale = dst.width() == 0 ? 1 : bitmap.width() / dst.width(); + float heightScale = dst.height() == 0 ? 1 : bitmap.height() / dst.height(); + m_maxZoomScale = std::max(m_maxZoomScale, std::max(widthScale, heightScale)); appendDrawingOperation(NEW_OP(DrawBitmapRect)(bitmap, *src, dst, op), dst); } diff --git a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.h b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.h index 061ee0e..930f1f2 100644 --- a/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.h +++ b/Source/WebCore/platform/graphics/android/context/PlatformGraphicsContextRecording.h @@ -143,7 +143,7 @@ public: bool translucent = false, bool drawBackground = true, const IntRect& thumb = IntRect()); - bool hasText() { return m_hasText; } + float maxZoomScale() { return m_maxZoomScale; } bool isEmpty() { return m_isEmpty; } private: @@ -206,7 +206,7 @@ private: Vector mMatrixStack; State* mOperationState; - bool m_hasText; + float m_maxZoomScale; bool m_isEmpty; RecordingContextCanvasProxy m_canvasProxy; }; diff --git a/Source/WebCore/platform/graphics/android/layers/LayerAndroid.cpp b/Source/WebCore/platform/graphics/android/layers/LayerAndroid.cpp index 84ce910..a652d3e 100644 --- a/Source/WebCore/platform/graphics/android/layers/LayerAndroid.cpp +++ b/Source/WebCore/platform/graphics/android/layers/LayerAndroid.cpp @@ -211,9 +211,9 @@ LayerAndroid::~LayerAndroid() #endif } -bool LayerAndroid::hasText() +float LayerAndroid::maxZoomScale() const { - return m_content && m_content->hasText(); + return m_content ? m_content->maxZoomScale() : 1.0f; } static int gDebugNbAnims = 0; diff --git a/Source/WebCore/platform/graphics/android/layers/LayerAndroid.h b/Source/WebCore/platform/graphics/android/layers/LayerAndroid.h index 5a1ef57..6c2e43d 100644 --- a/Source/WebCore/platform/graphics/android/layers/LayerAndroid.h +++ b/Source/WebCore/platform/graphics/android/layers/LayerAndroid.h @@ -262,7 +262,7 @@ public: LayerType type() { return m_type; } virtual SubclassType subclassType() const { return LayerAndroid::StandardLayer; } - bool hasText(); + float maxZoomScale() const; void copyAnimationStartTimesRecursive(LayerAndroid* oldTree); diff --git a/Source/WebCore/platform/graphics/android/layers/LayerContent.h b/Source/WebCore/platform/graphics/android/layers/LayerContent.h index a18e4c8..b6714ba 100644 --- a/Source/WebCore/platform/graphics/android/layers/LayerContent.h +++ b/Source/WebCore/platform/graphics/android/layers/LayerContent.h @@ -45,7 +45,7 @@ public: bool isEmpty() { return !width() || !height(); } virtual void setCheckForOptimisations(bool check) = 0; virtual void checkForOptimisations() = 0; - virtual bool hasText() = 0; + virtual float maxZoomScale() = 0; virtual void draw(SkCanvas* canvas) = 0; virtual PrerenderedInval* prerenderForRect(const IntRect& dirty) { return 0; } virtual void clearPrerenders() { }; diff --git a/Source/WebCore/platform/graphics/android/layers/PictureLayerContent.cpp b/Source/WebCore/platform/graphics/android/layers/PictureLayerContent.cpp index e40c9b6..bfd477e 100644 --- a/Source/WebCore/platform/graphics/android/layers/PictureLayerContent.cpp +++ b/Source/WebCore/platform/graphics/android/layers/PictureLayerContent.cpp @@ -48,13 +48,13 @@ int PictureLayerContent::height() void PictureLayerContent::checkForOptimisations() { if (!m_checkedContent) - hasText(); // for now only check the presence of text + maxZoomScale(); // for now only check the maximum scale for painting } -bool PictureLayerContent::hasText() +float PictureLayerContent::maxZoomScale() { if (m_checkedContent) - return m_hasText; + return m_hasText ? 1e6 : 1.0; // Let's check if we have text or not. If we don't, we can limit // ourselves to scale 1! @@ -76,7 +76,7 @@ bool PictureLayerContent::hasText() m_checkedContent = true; - return m_hasText; + return m_hasText ? 1e6 : 1.0; } void PictureLayerContent::draw(SkCanvas* canvas) diff --git a/Source/WebCore/platform/graphics/android/layers/PictureLayerContent.h b/Source/WebCore/platform/graphics/android/layers/PictureLayerContent.h index cf633cb..e5181a5 100644 --- a/Source/WebCore/platform/graphics/android/layers/PictureLayerContent.h +++ b/Source/WebCore/platform/graphics/android/layers/PictureLayerContent.h @@ -40,7 +40,7 @@ public: virtual int height(); virtual void setCheckForOptimisations(bool check) { m_checkedContent = !check; } virtual void checkForOptimisations(); - virtual bool hasText(); + virtual float maxZoomScale(); virtual void draw(SkCanvas* canvas); virtual void serialize(SkWStream* stream); diff --git a/Source/WebCore/platform/graphics/android/layers/PicturePileLayerContent.cpp b/Source/WebCore/platform/graphics/android/layers/PicturePileLayerContent.cpp index 1167bda..e48751d 100644 --- a/Source/WebCore/platform/graphics/android/layers/PicturePileLayerContent.cpp +++ b/Source/WebCore/platform/graphics/android/layers/PicturePileLayerContent.cpp @@ -12,7 +12,7 @@ namespace WebCore { PicturePileLayerContent::PicturePileLayerContent(const PicturePile& picturePile) : m_picturePile(picturePile) - , m_hasText(picturePile.hasText()) + , m_maxZoomScale(picturePile.maxZoomScale()) , m_hasContent(!picturePile.isEmpty()) { } diff --git a/Source/WebCore/platform/graphics/android/layers/PicturePileLayerContent.h b/Source/WebCore/platform/graphics/android/layers/PicturePileLayerContent.h index 9f3a263..cbaebed 100644 --- a/Source/WebCore/platform/graphics/android/layers/PicturePileLayerContent.h +++ b/Source/WebCore/platform/graphics/android/layers/PicturePileLayerContent.h @@ -41,7 +41,7 @@ public: virtual void setCheckForOptimisations(bool check) {} virtual void checkForOptimisations() {} // already performed, stored in m_hasText/m_hasContent - virtual bool hasText() { return m_hasText; } + virtual float maxZoomScale() { return m_maxZoomScale; } virtual void draw(SkCanvas* canvas); virtual void serialize(SkWStream* stream); virtual PrerenderedInval* prerenderForRect(const IntRect& dirty); @@ -50,7 +50,7 @@ public: private: PicturePile m_picturePile; - bool m_hasText; + float m_maxZoomScale; bool m_hasContent; }; diff --git a/Source/WebCore/platform/graphics/android/rendering/Surface.cpp b/Source/WebCore/platform/graphics/android/rendering/Surface.cpp index 96a4a16..6caf93b 100644 --- a/Source/WebCore/platform/graphics/android/rendering/Surface.cpp +++ b/Source/WebCore/platform/graphics/android/rendering/Surface.cpp @@ -52,7 +52,7 @@ namespace WebCore { Surface::Surface() : m_surfaceBacking(0) , m_needsTexture(false) - , m_hasText(false) + , m_maxZoomScale(1) { #ifdef DEBUG_COUNT ClassTracker::instance()->increment("Surface"); @@ -140,7 +140,7 @@ void Surface::addLayer(LayerAndroid* layer, const TransformationMatrix& transfor SkSafeRef(layer); m_needsTexture |= layer->needsTexture(); - m_hasText |= layer->hasText(); + m_maxZoomScale = std::max(m_maxZoomScale, layer->maxZoomScale()); // add this layer's size to the surface's area // TODO: handle scale/3d transform mapping @@ -211,7 +211,6 @@ void Surface::prepareGL(bool layerTilesDisabled, bool updateWithBlit) if (tilesDisabled) { m_surfaceBacking->discardTextures(); } else { - bool allowZoom = hasText(); // only allow for scale > 1 if painting vectors IntRect prepareArea = computePrepareArea(); IntRect fullArea = fullContentArea(); @@ -223,7 +222,7 @@ void Surface::prepareGL(bool layerTilesDisabled, bool updateWithBlit) prepareArea.x(), prepareArea.y(), prepareArea.width(), prepareArea.height(), fullArea.x(), fullArea.y(), fullArea.width(), fullArea.height()); - m_surfaceBacking->prepareGL(getFirstLayer()->state(), allowZoom, + m_surfaceBacking->prepareGL(getFirstLayer()->state(), m_maxZoomScale, prepareArea, fullArea, this, useAggressiveRendering(), updateWithBlit); } diff --git a/Source/WebCore/platform/graphics/android/rendering/Surface.h b/Source/WebCore/platform/graphics/android/rendering/Surface.h index f9f38e6..654d7bf 100644 --- a/Source/WebCore/platform/graphics/android/rendering/Surface.h +++ b/Source/WebCore/platform/graphics/android/rendering/Surface.h @@ -61,7 +61,6 @@ public: LayerAndroid* getFirstLayer() const { return m_layers[0]; } bool needsTexture() { return m_needsTexture; } - bool hasText() { return m_hasText; } bool isBase(); // don't allow transform fudging for merged layers - they need the transform @@ -87,7 +86,7 @@ private: SurfaceBacking* m_surfaceBacking; bool m_needsTexture; - bool m_hasText; + float m_maxZoomScale; Vector m_layers; Color m_background; diff --git a/Source/WebCore/platform/graphics/android/rendering/SurfaceBacking.cpp b/Source/WebCore/platform/graphics/android/rendering/SurfaceBacking.cpp index 5b11df6..d7b904f 100644 --- a/Source/WebCore/platform/graphics/android/rendering/SurfaceBacking.cpp +++ b/Source/WebCore/platform/graphics/android/rendering/SurfaceBacking.cpp @@ -46,7 +46,7 @@ SurfaceBacking::SurfaceBacking(bool isBaseSurface) , m_scale(-1) , m_futureScale(-1) , m_zooming(false) - , m_hasAllowedZoom(false) + , m_maxZoomScale(1) { #ifdef DEBUG_COUNT @@ -64,7 +64,7 @@ SurfaceBacking::~SurfaceBacking() #endif } -void SurfaceBacking::prepareGL(GLWebViewState* state, bool allowZoom, +void SurfaceBacking::prepareGL(GLWebViewState* state, float maxZoomScale, const IntRect& prepareArea, const IntRect& fullContentArea, TilePainter* painter, bool aggressiveRendering, bool updateWithBlit) @@ -72,11 +72,11 @@ void SurfaceBacking::prepareGL(GLWebViewState* state, bool allowZoom, // If the surface backing has ever zoomed beyond 1.0 scale, it's always // allowed to (so repaints aren't necessary when allowZoom toggles). If not, // and allowZoom is false, don't allow scale greater than 1.0 - m_hasAllowedZoom |= allowZoom; + m_maxZoomScale = std::max(m_maxZoomScale, maxZoomScale); float scale = state->scale(); bool scaleOverridden = false; - if (scale > 1 && !m_hasAllowedZoom) { - scale = 1; + if (scale > m_maxZoomScale) { + scale = m_maxZoomScale; scaleOverridden = true; } diff --git a/Source/WebCore/platform/graphics/android/rendering/SurfaceBacking.h b/Source/WebCore/platform/graphics/android/rendering/SurfaceBacking.h index 80c6545..ff866bf 100644 --- a/Source/WebCore/platform/graphics/android/rendering/SurfaceBacking.h +++ b/Source/WebCore/platform/graphics/android/rendering/SurfaceBacking.h @@ -40,7 +40,7 @@ class SurfaceBacking : public SkRefCnt { public: SurfaceBacking(bool isBaseSurface); ~SurfaceBacking(); - void prepareGL(GLWebViewState* state, bool allowZoom, + void prepareGL(GLWebViewState* state, float maxZoomScale, const IntRect& prepareArea, const IntRect& fullContentArea, TilePainter* painter, bool aggressiveRendering, bool updateWithBlit); @@ -95,7 +95,7 @@ private: float m_futureScale; double m_zoomUpdateTime; bool m_zooming; - bool m_hasAllowedZoom; + float m_maxZoomScale; }; } // namespace WebCore diff --git a/Source/WebKit/android/jni/PicturePile.cpp b/Source/WebKit/android/jni/PicturePile.cpp index f995e92..174980a 100644 --- a/Source/WebKit/android/jni/PicturePile.cpp +++ b/Source/WebKit/android/jni/PicturePile.cpp @@ -280,13 +280,13 @@ PrerenderedInval* PicturePile::prerenderedInvalForArea(const IntRect& area) return 0; } -bool PicturePile::hasText() const +float PicturePile::maxZoomScale() const { + float maxZoomScale = 1; for (size_t i = 0; i < m_pile.size(); i++) { - if (m_pile[i].hasText) - return true; + maxZoomScale = std::max(maxZoomScale, m_pile[i].maxZoomScale); } - return false; + return maxZoomScale; } bool PicturePile::isEmpty() const @@ -313,7 +313,7 @@ Picture* PicturePile::recordPicture(PicturePainter* painter, PictureContainer& p WebCore::PlatformGraphicsContextRecording pgc(picture); WebCore::GraphicsContext gc(&pgc); painter->paintContents(&gc, pc.area); - pc.hasText = pgc.hasText(); + pc.maxZoomScale = pgc.maxZoomScale(); if (pgc.isEmpty()) { SkSafeUnref(picture); picture = 0; @@ -365,7 +365,7 @@ Picture* PicturePile::recordPicture(PicturePainter* painter, PictureContainer& p painter->paintContents(&gc, drawArea); // TODO: consider paint-time checking for these with SkPicture painting? - pc.hasText = true; + pc.maxZoomScale = FLOAT_MAX; SkSafeUnref(canvas); picture->endRecording(); diff --git a/Source/WebKit/android/jni/PicturePile.h b/Source/WebKit/android/jni/PicturePile.h index 1f99054..51bf384 100644 --- a/Source/WebKit/android/jni/PicturePile.h +++ b/Source/WebKit/android/jni/PicturePile.h @@ -71,13 +71,13 @@ public: IntRect area; bool dirty; RefPtr prerendered; - bool hasText; + float maxZoomScale; PictureContainer(const IntRect& area) : picture(0) , area(area) , dirty(true) - , hasText(false) + , maxZoomScale(1) {} PictureContainer(const PictureContainer& other); @@ -105,7 +105,7 @@ public: PrerenderedInval* prerenderedInvalForArea(const IntRect& area); // UI-side methods used to check content, after construction/updates are complete - bool hasText() const; + float maxZoomScale() const; bool isEmpty() const; private: -- cgit v1.1