From 09dfd2f9699f17de78d6fcaa7a36a5ceb667df36 Mon Sep 17 00:00:00 2001 From: Chris Craik Date: Tue, 10 Apr 2012 17:07:55 -0700 Subject: Sort surface drawing order by Z value bug:6275189 Change-Id: Ib9cabadb77777244c6ef707c32ce53db3ebf3181 --- .../platform/graphics/android/rendering/Surface.h | 2 +- .../graphics/android/rendering/SurfaceCollection.cpp | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'Source/WebCore') diff --git a/Source/WebCore/platform/graphics/android/rendering/Surface.h b/Source/WebCore/platform/graphics/android/rendering/Surface.h index 27c997e..756fabd 100644 --- a/Source/WebCore/platform/graphics/android/rendering/Surface.h +++ b/Source/WebCore/platform/graphics/android/rendering/Surface.h @@ -56,7 +56,7 @@ public: void computeTexturesAmount(TexturesResult* result); - LayerAndroid* getFirstLayer() { return m_layers[0]; } + LayerAndroid* getFirstLayer() const { return m_layers[0]; } bool needsTexture() { return m_needsTexture; } bool hasText() { return m_hasText; } bool isBase(); diff --git a/Source/WebCore/platform/graphics/android/rendering/SurfaceCollection.cpp b/Source/WebCore/platform/graphics/android/rendering/SurfaceCollection.cpp index 0bbaf91..cd5ceef 100644 --- a/Source/WebCore/platform/graphics/android/rendering/SurfaceCollection.cpp +++ b/Source/WebCore/platform/graphics/android/rendering/SurfaceCollection.cpp @@ -95,6 +95,15 @@ void SurfaceCollection::prepareGL(const SkRect& visibleRect) m_surfaces[i]->prepareGL(layerTilesDisabled); } +static inline bool compareSurfaceZ(const Surface* a, const Surface* b) +{ + const LayerAndroid* la = a->getFirstLayer(); + const LayerAndroid* lb = b->getFirstLayer(); + + // swap drawing order if zValue suggests it AND the layers are in the same stacking context + return (la->zValue() > lb->zValue()) && (la->getParent() == lb->getParent()); +} + bool SurfaceCollection::drawGL(const SkRect& visibleRect) { #ifdef DEBUG_COUNT @@ -105,8 +114,16 @@ bool SurfaceCollection::drawGL(const SkRect& visibleRect) updateLayerPositions(visibleRect); bool layerTilesDisabled = m_compositedRoot->state()->layersRenderingMode() > GLWebViewState::kClippedTextures; + + // create a duplicate vector of surfaces, sorted by z value + Vector surfaces; + for (unsigned int i = 0; i < m_surfaces.size(); i++) + surfaces.append(m_surfaces[i]); + std::stable_sort(surfaces.begin()+1, surfaces.end(), compareSurfaceZ); + + // draw the sorted vector for (unsigned int i = 0; i < m_surfaces.size(); i++) - needsRedraw |= m_surfaces[i]->drawGL(layerTilesDisabled); + needsRedraw |= surfaces[i]->drawGL(layerTilesDisabled); return needsRedraw; } -- cgit v1.1