diff options
Diffstat (limited to 'Source')
12 files changed, 172 insertions, 53 deletions
diff --git a/Source/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp b/Source/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp index 68f452a..3975545 100644 --- a/Source/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp +++ b/Source/WebCore/platform/graphics/android/GraphicsLayerAndroid.cpp @@ -531,8 +531,8 @@ void GraphicsLayerAndroid::updateScrollingLayers() if (layerNeedsOverflow) { ASSERT(!m_foregroundLayer && !m_foregroundClipLayer); m_foregroundLayer = new ScrollableLayerAndroid(layer); + m_foregroundLayer->setIntrinsicallyComposited(true); - // TODO: can clip layer be set to not intrinsically composited? m_foregroundClipLayer = new LayerAndroid(layer); m_foregroundClipLayer->setMasksToBounds(true); m_foregroundClipLayer->addChild(m_foregroundLayer); @@ -604,24 +604,22 @@ void GraphicsLayerAndroid::updateFixedBackgroundLayers() { // Grab the background image and create a layer for it // the layer will be fixed positioned. - FillLayer* layers = view->style()->accessBackgroundLayers(); - StyleImage* styleImage = layers->image(); - if (styleImage->isCachedImage()) { - CachedImage* cachedImage = static_cast<StyleCachedImage*>(styleImage)->cachedImage(); - Image* image = cachedImage->image(); - if (image) { - m_fixedBackgroundLayer = new FixedBackgroundImageLayerAndroid(view->style(), - view->width(), - view->height()); - - Color color = view->style()->visitedDependentColor(CSSPropertyBackgroundColor); - SkColor skiaColor = SkColorSetARGB(color.alpha(), - color.red(), - color.green(), - color.blue()); - m_fixedBackgroundLayer->setBackgroundColor(skiaColor); - } - } + + Image* image = FixedBackgroundImageLayerAndroid::GetCachedImage(view->style()); + + if (!image) + return; + + m_fixedBackgroundLayer = new FixedBackgroundImageLayerAndroid(view->style(), + view->width(), + view->height()); + + Color color = view->style()->visitedDependentColor(CSSPropertyBackgroundColor); + SkColor skiaColor = SkColorSetARGB(color.alpha(), + color.red(), + color.green(), + color.blue()); + m_fixedBackgroundLayer->setBackgroundColor(skiaColor); // We need to clip the background image to the bounds of the original element m_foregroundClipLayer = new LayerAndroid(renderLayer); diff --git a/Source/WebCore/platform/graphics/android/layers/BaseLayerAndroid.cpp b/Source/WebCore/platform/graphics/android/layers/BaseLayerAndroid.cpp index 8abff96..62a5824 100644 --- a/Source/WebCore/platform/graphics/android/layers/BaseLayerAndroid.cpp +++ b/Source/WebCore/platform/graphics/android/layers/BaseLayerAndroid.cpp @@ -202,4 +202,35 @@ bool FixedBackgroundImageLayerAndroid::drawGL(bool layerTilesDisabled) return false; } +Image* FixedBackgroundImageLayerAndroid::GetCachedImage(PassRefPtr<RenderStyle> aStyle) +{ + RefPtr<RenderStyle> style = aStyle; + if (!style) + return 0; + + if (!style->hasFixedBackgroundImage()) + return 0; + + FillLayer* layers = style->accessBackgroundLayers(); + StyleImage* styleImage = layers->image(); + + if (!styleImage) + return 0; + + if (!styleImage->isLoaded()) + return 0; + + if (!styleImage->isCachedImage()) + return 0; + + CachedImage* cachedImage = static_cast<StyleCachedImage*>(styleImage)->cachedImage(); + + Image* image = cachedImage->image(); + + if (image == Image::nullImage()) + return 0; + + return image; +} + } // namespace WebCore diff --git a/Source/WebCore/platform/graphics/android/layers/BaseLayerAndroid.h b/Source/WebCore/platform/graphics/android/layers/BaseLayerAndroid.h index afe1c35..9ce8a07 100644 --- a/Source/WebCore/platform/graphics/android/layers/BaseLayerAndroid.h +++ b/Source/WebCore/platform/graphics/android/layers/BaseLayerAndroid.h @@ -31,6 +31,7 @@ namespace WebCore { +class Image; class RenderLayerCompositor; class RenderStyle; @@ -68,6 +69,7 @@ public: virtual bool needsTexture() { return true; } virtual SubclassType subclassType() const { return LayerAndroid::FixedBackgroundImageLayer; } virtual bool drawGL(bool layerTilesDisabled); + static Image* GetCachedImage(PassRefPtr<RenderStyle> style); private: int m_width; diff --git a/Source/WebCore/platform/graphics/android/layers/LayerAndroid.cpp b/Source/WebCore/platform/graphics/android/layers/LayerAndroid.cpp index feb2d99..2703cfd 100644 --- a/Source/WebCore/platform/graphics/android/layers/LayerAndroid.cpp +++ b/Source/WebCore/platform/graphics/android/layers/LayerAndroid.cpp @@ -133,11 +133,13 @@ LayerAndroid::LayerAndroid(const LayerAndroid& layer) : Layer(layer), m_replicatedLayerPosition = layer.m_replicatedLayerPosition; +#ifdef ABSOLUTE_POSITION // If we have absolute elements, we may need to reorder them if they // are followed by another layer that is not also absolutely positioned. // (as absolutely positioned elements are out of the normal flow) bool hasAbsoluteChildren = false; bool hasOnlyAbsoluteFollowers = true; + for (int i = 0; i < layer.countChildren(); i++) { if (layer.getChild(i)->isPositionAbsolute()) { hasAbsoluteChildren = true; @@ -169,6 +171,10 @@ LayerAndroid::LayerAndroid(const LayerAndroid& layer) : Layer(layer), for (int i = 0; i < layer.countChildren(); i++) addChild(layer.getChild(i)->copy())->unref(); } +#else + for (int i = 0; i < layer.countChildren(); i++) + addChild(layer.getChild(i)->copy())->unref(); +#endif KeyframesMap::const_iterator end = layer.m_animations.end(); for (KeyframesMap::const_iterator it = layer.m_animations.begin(); it != end; ++it) { @@ -620,19 +626,8 @@ bool LayerAndroid::canJoinSurface(Surface* surface) LayerAndroid* lastLayer = surface->getFirstLayer(); - // isolate non-tiled layers - // TODO: remove this check so that multiple tiled layers with a invisible - // one inbetween can be merged - if (!needsTexture() || !lastLayer->needsTexture()) - return false; - - // isolate clipped layers - // TODO: paint correctly with clip when merged - if (m_haveClip || lastLayer->m_haveClip) - return false; - // isolate intrinsically composited layers - if (m_intrinsicallyComposited || lastLayer->m_intrinsicallyComposited) + if (needsIsolatedSurface() || lastLayer->needsIsolatedSurface()) return false; // TODO: investigate potential for combining transformed layers @@ -645,6 +640,9 @@ bool LayerAndroid::canJoinSurface(Surface* surface) if (surface->needsTexture() && needsTexture() && m_content->hasText() != surface->hasText()) return false; + if (m_animations.size()) + return false; + // TODO: compare other layer properties - fixed? overscroll? transformed? return true; #endif @@ -664,24 +662,26 @@ void LayerAndroid::assignSurfaces(LayerMergeState* mergeState) } #ifdef LAYER_MERGING_DEBUG - ALOGD("%*slayer %p(%d) rl %p %s surface %p, fixed %d, anim %d, intCom %d, haveClip %d scroll %d", + ALOGD("%*slayer %p(%d) rl %p %s surface %p lvl: %d, fixed %d, anim %d, intCom %d, haveClip %d scroll %d hasText (layer: %d surface: %d) hasContent %d size %.2f x %.2f", 4*mergeState->depth, "", this, m_uniqueId, m_owningLayer, needNewSurface ? "NEW" : "joins", mergeState->currentSurface, + mergeState->nonMergeNestedLevel, isPositionFixed(), m_animations.size() != 0, m_intrinsicallyComposited, m_haveClip, - contentIsScrollable()); + contentIsScrollable(), m_content ? m_content->hasText() : -1, + mergeState->currentSurface ? mergeState->currentSurface->hasText() : -1, + needsTexture(), getWidth(), getHeight()); #endif mergeState->currentSurface->addLayer(this, m_drawTransform); m_surface = mergeState->currentSurface; - if (m_haveClip || contentIsScrollable() || isPositionFixed()) { + if (contentIsScrollable() || isPositionFixed()) { // disable layer merging within the children of these layer types mergeState->nonMergeNestedLevel++; } - // pass the surface through children in drawing order, so that they may // attach themselves (and paint on it) if possible, or ignore it and create // a new one if not @@ -699,7 +699,7 @@ void LayerAndroid::assignSurfaces(LayerMergeState* mergeState) mergeState->depth--; } - if (m_haveClip || contentIsScrollable() || isPositionFixed()) { + if (contentIsScrollable() || isPositionFixed()) { // re-enable joining mergeState->nonMergeNestedLevel--; diff --git a/Source/WebCore/platform/graphics/android/layers/LayerAndroid.h b/Source/WebCore/platform/graphics/android/layers/LayerAndroid.h index c7c795f..97da53c 100644 --- a/Source/WebCore/platform/graphics/android/layers/LayerAndroid.h +++ b/Source/WebCore/platform/graphics/android/layers/LayerAndroid.h @@ -281,6 +281,8 @@ public: Surface* surface() { return m_surface; } void setIntrinsicallyComposited(bool intCom) { m_intrinsicallyComposited = intCom; } + bool needsIsolatedSurface() { return (needsTexture() && m_intrinsicallyComposited) + || subclassType() == LayerAndroid::FixedBackgroundLayer; } int setHwAccelerated(bool hwAccelerated); diff --git a/Source/WebCore/platform/graphics/android/rendering/ImageTexture.cpp b/Source/WebCore/platform/graphics/android/rendering/ImageTexture.cpp index 2819baa..6ff71d9 100644 --- a/Source/WebCore/platform/graphics/android/rendering/ImageTexture.cpp +++ b/Source/WebCore/platform/graphics/android/rendering/ImageTexture.cpp @@ -198,11 +198,12 @@ const TransformationMatrix* ImageTexture::transform() if (!m_layer) return 0; - IntRect layerArea = m_layer->fullContentArea(); - float scaleW = static_cast<float>(layerArea.width()) / static_cast<float>(m_image->width()); - float scaleH = static_cast<float>(layerArea.height()) / static_cast<float>(m_image->height()); TransformationMatrix d = *(m_layer->drawTransform()); TransformationMatrix m; + float scaleW = 1.0f; + float scaleH = 1.0f; + getImageToLayerScale(&scaleW, &scaleH); + m.scaleNonUniform(scaleW, scaleH); m_layerMatrix = d.multiply(m); return &m_layerMatrix; @@ -228,6 +229,24 @@ bool ImageTexture::paint(SkCanvas* canvas) return true; } +void ImageTexture::getImageToLayerScale(float* scaleW, float* scaleH) const +{ + if (!scaleW || !scaleH) + return; + + + IntRect layerArea = m_layer->fullContentArea(); + + if (layerArea.width() == 0 || layerArea.height() == 0) + return; + + // calculate X, Y scale difference between image pixel coordinates and layer + // content coordinates + + *scaleW = static_cast<float>(layerArea.width()) / static_cast<float>(m_image->width()); + *scaleH = static_cast<float>(layerArea.height()) / static_cast<float>(m_image->height()); +} + void ImageTexture::drawGL(LayerAndroid* layer, float opacity, FloatPoint* offset) { @@ -242,6 +261,16 @@ void ImageTexture::drawGL(LayerAndroid* layer, if (m_tileGrid) { bool force3dContentVisible = true; IntRect visibleContentArea = m_layer->visibleContentArea(force3dContentVisible); + + // transform visibleContentArea size to image size + float scaleW = 1.0f; + float scaleH = 1.0f; + getImageToLayerScale(&scaleW, &scaleH); + visibleContentArea.setX(visibleContentArea.x() / scaleW); + visibleContentArea.setWidth(visibleContentArea.width() / scaleW); + visibleContentArea.setY(visibleContentArea.y() / scaleH); + visibleContentArea.setHeight(visibleContentArea.height() / scaleH); + const TransformationMatrix* transformation = transform(); if (offset) m_layerMatrix.translate(offset->x(), offset->y()); diff --git a/Source/WebCore/platform/graphics/android/rendering/ImageTexture.h b/Source/WebCore/platform/graphics/android/rendering/ImageTexture.h index 0571b83..99bec90 100644 --- a/Source/WebCore/platform/graphics/android/rendering/ImageTexture.h +++ b/Source/WebCore/platform/graphics/android/rendering/ImageTexture.h @@ -95,6 +95,7 @@ public: private: const TransformationMatrix* transform(); + void getImageToLayerScale(float* scaleW, float* scaleH) const; SkBitmapRef* m_imageRef; SkBitmap* m_image; diff --git a/Source/WebCore/platform/graphics/android/rendering/Surface.h b/Source/WebCore/platform/graphics/android/rendering/Surface.h index a79a286..7100125 100644 --- a/Source/WebCore/platform/graphics/android/rendering/Surface.h +++ b/Source/WebCore/platform/graphics/android/rendering/Surface.h @@ -93,7 +93,7 @@ public: LayerMergeState(Vector<Surface*>* const allGroups) : surfaceList(allGroups) , currentSurface(0) - , nonMergeNestedLevel(-1) // start at -1 to ignore first LayerAndroid's clipping + , nonMergeNestedLevel(0) , depth(0) {} diff --git a/Source/WebCore/platform/graphics/android/rendering/TransferQueue.cpp b/Source/WebCore/platform/graphics/android/rendering/TransferQueue.cpp index 41d6709..f273091 100644 --- a/Source/WebCore/platform/graphics/android/rendering/TransferQueue.cpp +++ b/Source/WebCore/platform/graphics/android/rendering/TransferQueue.cpp @@ -265,9 +265,9 @@ void TransferQueue::setHasGLContext(bool hasContext) void TransferQueue::emptyAndAbandonQueue() { for (int i = 0 ; i < m_transferQueueSize; i++) - m_transferQueue[i].status = emptyItem; + clearItemInTranferQueue(i); m_emptyItemCount = m_transferQueueSize; - m_pureColorTileQueue.clear(); + clearPureColorQueue(); if (m_sharedSurfaceTexture.get()) { m_sharedSurfaceTexture->abandon(); @@ -295,7 +295,7 @@ void TransferQueue::setPendingDiscard() if (m_transferQueue[i].status == pendingBlit) m_transferQueue[i].status = pendingDiscard; - m_pureColorTileQueue.clear(); + clearPureColorQueue(); bool GLContextExisted = getHasGLContext(); // Unblock the Tex Gen thread first before Tile Page deletion. @@ -307,6 +307,15 @@ void TransferQueue::setPendingDiscard() m_transferQueueItemCond.signal(); } +void TransferQueue::clearPureColorQueue() +{ + for (unsigned int i = 0 ; i < m_pureColorTileQueue.size(); i++) { + SkSafeUnref(m_pureColorTileQueue[i].savedTilePainter); + m_pureColorTileQueue[i].savedTilePainter = 0; + } + m_pureColorTileQueue.clear(); +} + void TransferQueue::updatePureColorTiles() { for (unsigned int i = 0 ; i < m_pureColorTileQueue.size(); i++) { @@ -324,7 +333,7 @@ void TransferQueue::updatePureColorTiles() ALOGV("Warning: Don't expect an emptyItem here."); } } - m_pureColorTileQueue.clear(); + clearPureColorQueue(); } // Call on UI thread to copy from the shared Surface Texture to the Tile's texture. @@ -363,8 +372,7 @@ void TransferQueue::updateDirtyTiles() if (result != OK) ALOGE("unexpected error: updateTexImage return %d", result); } - m_transferQueue[index].savedTilePtr = 0; - m_transferQueue[index].status = emptyItem; + if (obsoleteTile) { ALOGV("Warning: the texture is obsolete for this baseTile"); index = (index + 1) % m_transferQueueSize; @@ -391,7 +399,7 @@ void TransferQueue::updateDirtyTiles() destTexture->setPure(false); destTexture->transferComplete(); - + clearItemInTranferQueue(index); ALOGV("Blit tile x, y %d %d with dest texture %p to destTexture->m_ownTextureId %d", m_transferQueue[index].savedTilePtr, destTexture, @@ -469,6 +477,14 @@ void TransferQueue::addItemInPureColorQueue(const TileRenderInfo* renderInfo) m_pureColorTileQueue.append(data); } +void TransferQueue::clearItemInTranferQueue(int index) +{ + m_transferQueue[index].savedTilePtr = 0; + SkSafeUnref(m_transferQueue[index].savedTilePainter); + m_transferQueue[index].savedTilePainter = 0; + m_transferQueue[index].status = emptyItem; +} + // Translates the info from TileRenderInfo and others to TileTransferData. // This is used by pure color tiles and normal tiles. void TransferQueue::addItemCommon(const TileRenderInfo* renderInfo, @@ -476,6 +492,8 @@ void TransferQueue::addItemCommon(const TileRenderInfo* renderInfo, TileTransferData* data) { data->savedTileTexturePtr = renderInfo->baseTile->backTexture(); + data->savedTilePainter = renderInfo->tilePainter; + SkSafeRef(data->savedTilePainter); data->savedTilePtr = renderInfo->baseTile; data->status = pendingBlit; data->uploadType = type; @@ -552,10 +570,7 @@ void TransferQueue::cleanupPendingDiscard() tile->discardBackTexture(); ALOGV("transfer queue discarded tile %p, removed texture", tile); } - - m_transferQueue[index].savedTilePtr = 0; - m_transferQueue[index].savedTileTexturePtr = 0; - m_transferQueue[index].status = emptyItem; + clearItemInTranferQueue(index); } index = (index + 1) % m_transferQueueSize; } diff --git a/Source/WebCore/platform/graphics/android/rendering/TransferQueue.h b/Source/WebCore/platform/graphics/android/rendering/TransferQueue.h index 44d3c37..9d33ff5 100644 --- a/Source/WebCore/platform/graphics/android/rendering/TransferQueue.h +++ b/Source/WebCore/platform/graphics/android/rendering/TransferQueue.h @@ -37,6 +37,7 @@ namespace WebCore { class Tile; +class TilePainter; class TileTexture; struct GLState { @@ -75,6 +76,7 @@ public: TileTransferData() : status(emptyItem) , savedTilePtr(0) + , savedTilePainter(0) , savedTileTexturePtr(0) , uploadType(DEFAULT_UPLOAD_TYPE) , bitmap(0) @@ -90,6 +92,7 @@ public: TransferItemStatus status; Tile* savedTilePtr; + TilePainter* savedTilePainter; // Ref count the tilePainter to keep the tile alive. TileTexture* savedTileTexturePtr; TextureUploadType uploadType; // This is only useful in Cpu upload code path, so it will be dynamically @@ -178,10 +181,12 @@ private: GLuint srcTexId, GLenum srcTexTarget, int index); + void clearItemInTranferQueue(int index); void addItemCommon(const TileRenderInfo* renderInfo, TextureUploadType type, TileTransferData* data); void updatePureColorTiles(); + void clearPureColorQueue(); // Note that the m_transferQueueIndex only changed in the TexGen thread // where we are going to move on to update the next item in the queue. int m_transferQueueIndex; diff --git a/Source/WebKit/android/jni/WebViewCore.cpp b/Source/WebKit/android/jni/WebViewCore.cpp index 734eb76..dc4f70c 100644 --- a/Source/WebKit/android/jni/WebViewCore.cpp +++ b/Source/WebKit/android/jni/WebViewCore.cpp @@ -838,7 +838,8 @@ BaseLayerAndroid* WebViewCore::createBaseLayer(GraphicsLayerAndroid* root) Color viewBackground = view->baseBackgroundColor(); background = bodyHasCSSBackground ? viewBackground.blend(background) : viewBackground; } - bodyHasFixedBackgroundImage = style->hasFixedBackgroundImage(); + bodyHasFixedBackgroundImage = style->hasFixedBackgroundImage() + && FixedBackgroundImageLayerAndroid::GetCachedImage(style); } PicturePileLayerContent* content = new PicturePileLayerContent(m_content); @@ -1685,6 +1686,35 @@ IntPoint WebViewCore::convertGlobalContentToFrameContent(const IntPoint& point, return IntPoint(point.x() + frameOffset.x(), point.y() + frameOffset.y()); } +Position WebViewCore::trimSelectionPosition(const Position &start, const Position& stop) +{ + int direction = comparePositions(start, stop); + if (direction == 0) + return start; + bool forward = direction < 0; + EAffinity affinity = forward ? DOWNSTREAM : UPSTREAM; + bool move; + Position pos = start; + bool movedTooFar = false; + do { + move = true; + Node* node = pos.anchorNode(); + if (node && node->isTextNode() && node->renderer()) { + RenderText *textRenderer = toRenderText(node->renderer()); + move = !textRenderer->textLength(); + } + if (move) { + Position nextPos = forward ? pos.next() : pos.previous(); + movedTooFar = nextPos.isNull() || pos == nextPos + || ((comparePositions(nextPos, stop) < 0) != forward); + pos = nextPos; + } + } while (move && !movedTooFar); + if (movedTooFar) + pos = stop; + return pos; +} + void WebViewCore::selectText(int startX, int startY, int endX, int endY) { SelectionController* sc = focusedFrame()->selection(); @@ -1721,7 +1751,11 @@ void WebViewCore::selectText(int startX, int startY, int endX, int endY) endPosition = prevEndPosition; } - VisibleSelection selection(startPosition, endPosition); + Position start = startPosition.deepEquivalent(); + Position end = endPosition.deepEquivalent(); + start = trimSelectionPosition(start, end); + end = trimSelectionPosition(end, start); + VisibleSelection selection(start, end); // Only allow changes between caret positions or to text selection. bool selectChangeAllowed = (!selection.isCaret() || sc->isCaret()); if (selectChangeAllowed && sc->shouldChangeSelection(selection)) diff --git a/Source/WebKit/android/jni/WebViewCore.h b/Source/WebKit/android/jni/WebViewCore.h index b43262c..c6b26c6 100644 --- a/Source/WebKit/android/jni/WebViewCore.h +++ b/Source/WebKit/android/jni/WebViewCore.h @@ -734,6 +734,8 @@ namespace android { static WebCore::IntRect positionToTextRect(const WebCore::Position& position, WebCore::EAffinity affinity); static bool isLtr(const WebCore::Position& position); + static WebCore::Position trimSelectionPosition( + const WebCore::Position& start, const WebCore::Position& stop); // called from constructor, to add this to a global list static void addInstance(WebViewCore*); |