summaryrefslogtreecommitdiffstats
path: root/Source/WebCore/platform/graphics/android
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/platform/graphics/android')
-rw-r--r--Source/WebCore/platform/graphics/android/LayerAndroid.cpp35
-rw-r--r--Source/WebCore/platform/graphics/android/LayerAndroid.h3
-rw-r--r--Source/WebCore/platform/graphics/android/MediaTexture.cpp14
-rw-r--r--Source/WebCore/platform/graphics/android/PaintedSurface.cpp8
-rw-r--r--Source/WebCore/platform/graphics/android/PaintedSurface.h2
-rw-r--r--Source/WebCore/platform/graphics/android/TilesManager.cpp16
6 files changed, 64 insertions, 14 deletions
diff --git a/Source/WebCore/platform/graphics/android/LayerAndroid.cpp b/Source/WebCore/platform/graphics/android/LayerAndroid.cpp
index 97ff692..65e0ec1 100644
--- a/Source/WebCore/platform/graphics/android/LayerAndroid.cpp
+++ b/Source/WebCore/platform/graphics/android/LayerAndroid.cpp
@@ -706,23 +706,38 @@ void LayerAndroid::showLayer(int indent)
this->getChild(i)->showLayer(indent + 1);
}
-void LayerAndroid::assignTexture(LayerAndroid* oldTree)
+// We go through our tree, and if we have layer in the new
+// tree that is similar, we tranfer our texture to it.
+// Otherwise, we remove ourselves from the texture so
+// that TilesManager::swapLayersTextures() have a chance
+// at deallocating the textures (PaintedSurfaces)
+void LayerAndroid::assignTextureTo(LayerAndroid* newTree)
{
int count = this->countChildren();
for (int i = 0; i < count; i++)
- this->getChild(i)->assignTexture(oldTree);
+ this->getChild(i)->assignTextureTo(newTree);
- if (oldTree) {
- LayerAndroid* oldLayer = oldTree->findById(uniqueId());
- if (oldLayer == this)
+ if (newTree) {
+ LayerAndroid* newLayer = newTree->findById(uniqueId());
+ if (newLayer == this)
return;
-
- if (oldLayer && oldLayer->texture()) {
- oldLayer->texture()->replaceLayer(this);
- m_texture = oldLayer->texture();
- SkSafeRef(m_texture);
+ if (newLayer && m_texture) {
+ m_texture->replaceLayer(newLayer);
+ newLayer->m_texture = m_texture;
+ SkSafeRef(newLayer->m_texture);
+ }
+ if (!newLayer && m_texture) {
+ m_texture->removeLayer(this);
+ m_texture = 0;
}
}
+}
+
+void LayerAndroid::createTexture()
+{
+ int count = this->countChildren();
+ for (int i = 0; i < count; i++)
+ this->getChild(i)->createTexture();
if (needsTexture() && !m_texture)
m_texture = new PaintedSurface(this);
diff --git a/Source/WebCore/platform/graphics/android/LayerAndroid.h b/Source/WebCore/platform/graphics/android/LayerAndroid.h
index c4ed9fe..8ad52e0 100644
--- a/Source/WebCore/platform/graphics/android/LayerAndroid.h
+++ b/Source/WebCore/platform/graphics/android/LayerAndroid.h
@@ -252,7 +252,8 @@ public:
friend LayerAndroid* android::deserializeLayer(SkStream* stream);
PaintedSurface* texture() { return m_texture; }
- void assignTexture(LayerAndroid* oldTree);
+ void assignTextureTo(LayerAndroid* newTree);
+ void createTexture();
protected:
virtual void onDraw(SkCanvas*, SkScalar opacity);
diff --git a/Source/WebCore/platform/graphics/android/MediaTexture.cpp b/Source/WebCore/platform/graphics/android/MediaTexture.cpp
index 3fecfb5..96d136a 100644
--- a/Source/WebCore/platform/graphics/android/MediaTexture.cpp
+++ b/Source/WebCore/platform/graphics/android/MediaTexture.cpp
@@ -104,10 +104,20 @@ void MediaTexture::drawContent(const TransformationMatrix& matrix)
m_surfaceTexture->updateTexImage();
- bool forceBlending = ANativeWindow_getFormat(m_surfaceTextureClient.get()) == WINDOW_FORMAT_RGB_565;
+ sp<GraphicBuffer> buf = m_surfaceTexture->getCurrentBuffer();
+
+ PixelFormat f = buf->getPixelFormat();
+ // only attempt to use alpha blending if alpha channel exists
+ bool forceAlphaBlending = !(
+ PIXEL_FORMAT_RGBX_8888 == f ||
+ PIXEL_FORMAT_RGB_888 == f ||
+ PIXEL_FORMAT_RGB_565 == f ||
+ PIXEL_FORMAT_RGB_332 == f);
+
TilesManager::instance()->shader()->drawLayerQuad(matrix, m_dimensions,
m_textureId, 1.0f,
- forceBlending, GL_TEXTURE_EXTERNAL_OES);
+ forceAlphaBlending,
+ GL_TEXTURE_EXTERNAL_OES);
}
void MediaTexture::drawVideo(const TransformationMatrix& matrix, const SkRect& parentBounds)
diff --git a/Source/WebCore/platform/graphics/android/PaintedSurface.cpp b/Source/WebCore/platform/graphics/android/PaintedSurface.cpp
index fe7044c..fd4475b 100644
--- a/Source/WebCore/platform/graphics/android/PaintedSurface.cpp
+++ b/Source/WebCore/platform/graphics/android/PaintedSurface.cpp
@@ -60,6 +60,7 @@ void PaintedSurface::removeLayer(LayerAndroid* layer)
android::Mutex::Autolock lock(m_layerLock);
if (m_layer != layer)
return;
+ SkSafeUnref(m_layer);
m_layer = 0;
}
@@ -72,6 +73,8 @@ void PaintedSurface::replaceLayer(LayerAndroid* layer)
if (m_layer && layer->uniqueId() != m_layer->uniqueId())
return;
+ SkSafeRef(layer);
+ SkSafeUnref(m_layer);
m_layer = layer;
}
@@ -140,6 +143,7 @@ bool PaintedSurface::paint(BaseTile* tile, SkCanvas* canvas, unsigned int* pictu
{
m_layerLock.lock();
LayerAndroid* layer = m_layer;
+ SkSafeRef(layer);
m_layerLock.unlock();
if (!layer)
@@ -148,6 +152,7 @@ bool PaintedSurface::paint(BaseTile* tile, SkCanvas* canvas, unsigned int* pictu
layer->contentDraw(canvas);
m_pictureUsed = layer->pictureUsed();
*pictureUsed = m_pictureUsed;
+ SkSafeUnref(layer);
return true;
}
@@ -156,10 +161,13 @@ void PaintedSurface::paintExtra(SkCanvas* canvas)
{
m_layerLock.lock();
LayerAndroid* layer = m_layer;
+ SkSafeRef(layer);
m_layerLock.unlock();
if (layer)
layer->extraDraw(canvas);
+
+ SkSafeUnref(layer);
}
float PaintedSurface::opacity() {
diff --git a/Source/WebCore/platform/graphics/android/PaintedSurface.h b/Source/WebCore/platform/graphics/android/PaintedSurface.h
index 84fe64c..6b6c74f 100644
--- a/Source/WebCore/platform/graphics/android/PaintedSurface.h
+++ b/Source/WebCore/platform/graphics/android/PaintedSurface.h
@@ -51,12 +51,14 @@ public:
, m_busy(false)
{
TilesManager::instance()->addPaintedSurface(this);
+ SkSafeRef(m_layer);
#ifdef DEBUG_COUNT
ClassTracker::instance()->increment("PaintedSurface");
#endif
}
virtual ~PaintedSurface()
{
+ SkSafeUnref(m_layer);
#ifdef DEBUG_COUNT
ClassTracker::instance()->decrement("PaintedSurface");
#endif
diff --git a/Source/WebCore/platform/graphics/android/TilesManager.cpp b/Source/WebCore/platform/graphics/android/TilesManager.cpp
index ba48111..4ada041 100644
--- a/Source/WebCore/platform/graphics/android/TilesManager.cpp
+++ b/Source/WebCore/platform/graphics/android/TilesManager.cpp
@@ -189,8 +189,22 @@ void TilesManager::resetTextureUsage(TiledPage* page)
void TilesManager::swapLayersTextures(LayerAndroid* oldTree, LayerAndroid* newTree)
{
+ if (oldTree)
+ oldTree->assignTextureTo(newTree);
+
if (newTree)
- newTree->assignTexture(oldTree);
+ newTree->createTexture();
+
+ WTF::Vector<PaintedSurface*> collect;
+ for (unsigned int i = 0; i < m_paintedSurfaces.size(); i++) {
+ PaintedSurface* surface = m_paintedSurfaces[i];
+ if (!surface->layer())
+ collect.append(surface);
+ }
+ for (unsigned int i = 0; i < collect.size(); i++) {
+ m_paintedSurfaces.remove(m_paintedSurfaces.find(collect[i]));
+ SkSafeUnref(collect[i]);
+ }
}
void TilesManager::addPaintedSurface(PaintedSurface* surface)