Diff
Modified: trunk/Source/WebCore/ChangeLog (93795 => 93796)
--- trunk/Source/WebCore/ChangeLog 2011-08-25 17:13:59 UTC (rev 93795)
+++ trunk/Source/WebCore/ChangeLog 2011-08-25 17:24:06 UTC (rev 93796)
@@ -1,3 +1,46 @@
+2011-08-24 Adrienne Walker <[email protected]>
+
+ [chromium] Update VideoLayerChromium to not access GC3D on the main thread
+ https://bugs.webkit.org/show_bug.cgi?id=66434
+
+ Reviewed by James Robinson.
+
+ Covered by existing tests.
+
+ This change allows the main thread VideoLayerChromium to not depend on
+ compositor thread resources (GC3D, LayerRendererChromium). The texture
+ allocation in VideoLayerChromium was changed to use ManagedTexture so
+ that textures can now be evicted when there is texture memory pressure
+ and so that destruction can be automatically deferred until a GC3D is
+ available.
+
+ * platform/graphics/chromium/LayerRendererChromium.cpp:
+ * platform/graphics/chromium/LayerRendererChromium.h:
+ * platform/graphics/chromium/ManagedTexture.cpp:
+ * platform/graphics/chromium/ManagedTexture.h:
+ (WebCore::ManagedTexture::size):
+ (WebCore::ManagedTexture::format):
+ * platform/graphics/chromium/VideoLayerChromium.cpp:
+ (WebCore::VideoLayerChromium::VideoLayerChromium):
+ (WebCore::VideoLayerChromium::~VideoLayerChromium):
+ (WebCore::VideoLayerChromium::cleanupResources):
+ (WebCore::VideoLayerChromium::updateCompositorResources):
+ (WebCore::VideoLayerChromium::pushPropertiesTo):
+ (WebCore::VideoLayerChromium::setLayerTreeHost):
+ (WebCore::VideoLayerChromium::determineTextureFormat):
+ (WebCore::VideoLayerChromium::reserveTextures):
+ (WebCore::VideoLayerChromium::updateTexture):
+ (WebCore::VideoLayerChromium::releaseCurrentFrame):
+ * platform/graphics/chromium/VideoLayerChromium.h:
+ * platform/graphics/chromium/cc/CCLayerTreeHost.cpp:
+ (WebCore::CCLayerTreeHost::contentsTextureManager):
+ * platform/graphics/chromium/cc/CCLayerTreeHost.h:
+ * platform/graphics/chromium/cc/CCVideoLayerImpl.cpp:
+ (WebCore::CCVideoLayerImpl::setTexture):
+ (WebCore::CCVideoLayerImpl::drawYUV):
+ (WebCore::CCVideoLayerImpl::drawRGBA):
+ * platform/graphics/chromium/cc/CCVideoLayerImpl.h:
+
2011-08-25 Abhishek Arya <[email protected]>
Incorrect layout of :before and :after content, with display
Modified: trunk/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp (93795 => 93796)
--- trunk/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp 2011-08-25 17:13:59 UTC (rev 93795)
+++ trunk/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp 2011-08-25 17:24:06 UTC (rev 93796)
@@ -1060,14 +1060,6 @@
return true;
}
-// Checks whether a given size is within the maximum allowed texture size range.
-bool LayerRendererChromium::checkTextureSize(const IntSize& textureSize)
-{
- if (textureSize.width() > m_maxTextureSize || textureSize.height() > m_maxTextureSize)
- return false;
- return true;
-}
-
// Sets the coordinate range of content that ends being drawn onto the target render surface.
// The target render surface is assumed to have an origin at 0, 0 and the width and height of
// of the drawRect.
Modified: trunk/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.h (93795 => 93796)
--- trunk/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.h 2011-08-25 17:13:59 UTC (rev 93795)
+++ trunk/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.h 2011-08-25 17:24:06 UTC (rev 93796)
@@ -115,7 +115,6 @@
const TransformationMatrix& projectionMatrix() const { return m_projectionMatrix; }
const TransformationMatrix& windowMatrix() const { return m_windowMatrix; }
- bool checkTextureSize(const IntSize&);
int maxTextureSize() const { return m_maxTextureSize; }
const GeometryBinding* sharedGeometry() const { return m_sharedGeometry.get(); }
Modified: trunk/Source/WebCore/platform/graphics/chromium/ManagedTexture.cpp (93795 => 93796)
--- trunk/Source/WebCore/platform/graphics/chromium/ManagedTexture.cpp 2011-08-25 17:13:59 UTC (rev 93795)
+++ trunk/Source/WebCore/platform/graphics/chromium/ManagedTexture.cpp 2011-08-25 17:24:06 UTC (rev 93796)
@@ -101,4 +101,3 @@
}
#endif // USE(ACCELERATED_COMPOSITING)
-
Modified: trunk/Source/WebCore/platform/graphics/chromium/ManagedTexture.h (93795 => 93796)
--- trunk/Source/WebCore/platform/graphics/chromium/ManagedTexture.h 2011-08-25 17:13:59 UTC (rev 93795)
+++ trunk/Source/WebCore/platform/graphics/chromium/ManagedTexture.h 2011-08-25 17:24:06 UTC (rev 93796)
@@ -47,7 +47,6 @@
}
~ManagedTexture();
- unsigned format() const { return m_format; }
bool isValid(const IntSize&, unsigned format);
bool reserve(const IntSize&, unsigned format);
void unreserve();
@@ -60,6 +59,8 @@
void bindTexture(GraphicsContext3D*);
void framebufferTexture2D(GraphicsContext3D*);
+ IntSize size() const { return m_size; }
+ unsigned format() const { return m_format; }
unsigned textureId() const { return m_textureId; }
private:
Modified: trunk/Source/WebCore/platform/graphics/chromium/VideoLayerChromium.cpp (93795 => 93796)
--- trunk/Source/WebCore/platform/graphics/chromium/VideoLayerChromium.cpp 2011-08-25 17:13:59 UTC (rev 93795)
+++ trunk/Source/WebCore/platform/graphics/chromium/VideoLayerChromium.cpp 2011-08-25 17:24:06 UTC (rev 93796)
@@ -56,15 +56,14 @@
, m_skipsDraw(true)
, m_frameFormat(VideoFrameChromium::Invalid)
, m_provider(provider)
+ , m_layerTreeHost(0)
, m_currentFrame(0)
{
- resetFrameParameters();
}
VideoLayerChromium::~VideoLayerChromium()
{
cleanupResources();
- deleteTexturesInUse();
}
PassRefPtr<CCLayerImpl> VideoLayerChromium::createCCLayerImpl()
@@ -72,26 +71,10 @@
return CCVideoLayerImpl::create(m_layerId);
}
-void VideoLayerChromium::deleteTexturesInUse()
-{
- if (!layerRenderer())
- return;
-
- GraphicsContext3D* context = layerRendererContext();
- for (unsigned plane = 0; plane < VideoFrameChromium::maxPlanes; plane++) {
- Texture texture = m_textures[plane];
- if (!texture.isEmpty && texture.ownedByLayerRenderer)
- GLC(context, context->deleteTexture(texture.id));
- }
-}
-
void VideoLayerChromium::cleanupResources()
{
LayerChromium::cleanupResources();
- if (m_currentFrame)
- releaseCurrentFrame();
- else
- resetFrameParameters();
+ releaseCurrentFrame();
}
void VideoLayerChromium::updateCompositorResources(GraphicsContext3D* context)
@@ -114,7 +97,7 @@
}
m_frameFormat = frame->format();
- unsigned textureFormat = determineTextureFormat(frame);
+ GC3Denum textureFormat = determineTextureFormat(frame);
if (textureFormat == GraphicsContext3D::INVALID_VALUE) {
// FIXME: Implement other paths.
notImplemented();
@@ -125,8 +108,8 @@
// Allocate textures for planes if they are not allocated already, or
// reallocate textures that are the wrong size for the frame.
- bool texturesAllocated = allocateTexturesIfNeeded(context, frame, textureFormat);
- if (!texturesAllocated) {
+ bool texturesReserved = reserveTextures(frame, textureFormat);
+ if (!texturesReserved) {
m_skipsDraw = true;
m_provider->putCurrentFrame(frame);
return;
@@ -134,9 +117,10 @@
// Update texture planes.
for (unsigned plane = 0; plane < frame->planes(); plane++) {
- Texture texture = m_textures[plane];
- ASSERT(frame->requiredTextureSize(plane) == texture.size);
- updateTexture(context, texture.id, texture.size, textureFormat, frame->data(plane));
+ Texture& texture = m_textures[plane];
+ ASSERT(texture.m_texture);
+ ASSERT(frame->requiredTextureSize(plane) == texture.m_texture->size());
+ updateTexture(context, texture, frame->data(plane));
}
m_dirtyRect.setSize(FloatSize());
@@ -152,12 +136,29 @@
CCVideoLayerImpl* videoLayer = static_cast<CCVideoLayerImpl*>(layer);
videoLayer->setSkipsDraw(m_skipsDraw);
videoLayer->setFrameFormat(m_frameFormat);
- for (size_t i = 0; i < 3; ++i)
- videoLayer->setTexture(i, m_textures[i]);
+ for (size_t i = 0; i < 3; ++i) {
+ if (!m_textures[i].m_texture) {
+ videoLayer->setSkipsDraw(true);
+ break;
+ }
+ videoLayer->setTexture(i, m_textures[i].m_texture->textureId(), m_textures[i].m_texture->size(), m_textures[i].m_visibleSize);
+ }
}
+void VideoLayerChromium::setLayerTreeHost(CCLayerTreeHost* layerTreeHost)
+{
+ if (m_layerTreeHost == layerTreeHost)
+ return;
-unsigned VideoLayerChromium::determineTextureFormat(const VideoFrameChromium* frame)
+ m_layerTreeHost = layerTreeHost;
+
+ for (size_t i = 0; i < 3; ++i) {
+ m_textures[i].m_visibleSize = IntSize();
+ m_textures[i].m_texture = ManagedTexture::create(layerTreeHost->contentsTextureManager());
+ }
+}
+
+GC3Denum VideoLayerChromium::determineTextureFormat(const VideoFrameChromium* frame)
{
switch (frame->format()) {
case VideoFrameChromium::YV12:
@@ -171,32 +172,29 @@
return GraphicsContext3D::INVALID_VALUE;
}
-bool VideoLayerChromium::allocateTexturesIfNeeded(GraphicsContext3D* context, const VideoFrameChromium* frame, unsigned textureFormat)
+bool VideoLayerChromium::reserveTextures(const VideoFrameChromium* frame, GC3Denum textureFormat)
{
- ASSERT(context);
+ ASSERT(m_layerTreeHost);
ASSERT(frame);
+ ASSERT(textureFormat != GraphicsContext3D::INVALID_VALUE);
+ int maxTextureSize = m_layerTreeHost->maxTextureSize();
+
for (unsigned plane = 0; plane < frame->planes(); plane++) {
IntSize requiredTextureSize = frame->requiredTextureSize(plane);
- Texture texture = m_textures[plane];
// If the renderer cannot handle this large of a texture, return false.
// FIXME: Remove this test when tiled layers are implemented.
- if (!layerRenderer()->checkTextureSize(requiredTextureSize))
+ if (requiredTextureSize.isZero() || requiredTextureSize.width() > maxTextureSize || requiredTextureSize.height() > maxTextureSize)
return false;
- if (texture.isEmpty) {
- texture.id = layerRenderer()->createLayerTexture();
- texture.ownedByLayerRenderer = true;
- texture.isEmpty = false;
- }
+ if (!m_textures[plane].m_texture)
+ return false;
- if (!requiredTextureSize.isZero() && requiredTextureSize != texture.size) {
- allocateTexture(context, texture.id, requiredTextureSize, textureFormat);
- texture.size = requiredTextureSize;
- texture.visibleSize = computeVisibleSize(frame, plane);
- }
- m_textures[plane] = texture;
+ if (m_textures[plane].m_texture->size() != requiredTextureSize)
+ m_textures[plane].m_visibleSize = computeVisibleSize(frame, plane);
+
+ m_textures[plane].m_texture->reserve(requiredTextureSize, textureFormat);
}
return true;
@@ -226,16 +224,16 @@
return IntSize(visibleWidth, visibleHeight);
}
-void VideoLayerChromium::allocateTexture(GraphicsContext3D* context, unsigned textureId, const IntSize& dimensions, unsigned textureFormat) const
+void VideoLayerChromium::updateTexture(GraphicsContext3D* context, Texture& texture, const void* data) const
{
- GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, textureId));
- GLC(context, context->texImage2DResourceSafe(GraphicsContext3D::TEXTURE_2D, 0, textureFormat, dimensions.width(), dimensions.height(), 0, textureFormat, GraphicsContext3D::UNSIGNED_BYTE));
-}
-
-void VideoLayerChromium::updateTexture(GraphicsContext3D* context, unsigned textureId, const IntSize& dimensions, unsigned format, const void* data) const
-{
ASSERT(context);
- GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, textureId));
+ ASSERT(texture.m_texture);
+
+ texture.m_texture->bindTexture(context);
+
+ GC3Denum format = texture.m_texture->format();
+ IntSize dimensions = texture.m_texture->size();
+
void* mem = static_cast<Extensions3DChromium*>(context->getExtensions())->mapTexSubImage2DCHROMIUM(GraphicsContext3D::TEXTURE_2D, 0, 0, 0, dimensions.width(), dimensions.height(), format, GraphicsContext3D::UNSIGNED_BYTE, Extensions3DChromium::WRITE_ONLY);
if (mem) {
memcpy(mem, data, dimensions.width() * dimensions.height());
@@ -255,21 +253,8 @@
m_provider->putCurrentFrame(m_currentFrame);
m_currentFrame = 0;
- resetFrameParameters();
}
-void VideoLayerChromium::resetFrameParameters()
-{
- deleteTexturesInUse();
- for (unsigned plane = 0; plane < VideoFrameChromium::maxPlanes; plane++) {
- m_textures[plane].id = 0;
- m_textures[plane].size = IntSize();
- m_textures[plane].visibleSize = IntSize();
- m_textures[plane].ownedByLayerRenderer = false;
- m_textures[plane].isEmpty = true;
- }
-}
-
} // namespace WebCore
#endif // USE(ACCELERATED_COMPOSITING)
Modified: trunk/Source/WebCore/platform/graphics/chromium/VideoLayerChromium.h (93795 => 93796)
--- trunk/Source/WebCore/platform/graphics/chromium/VideoLayerChromium.h 2011-08-25 17:13:59 UTC (rev 93795)
+++ trunk/Source/WebCore/platform/graphics/chromium/VideoLayerChromium.h 2011-08-25 17:24:06 UTC (rev 93796)
@@ -35,6 +35,7 @@
#if USE(ACCELERATED_COMPOSITING)
#include "LayerChromium.h"
+#include "ManagedTexture.h"
#include "VideoFrameProvider.h"
namespace WebCore {
@@ -42,13 +43,6 @@
// A Layer that contains a Video element.
class VideoLayerChromium : public LayerChromium {
public:
- struct Texture {
- unsigned id;
- IntSize size;
- IntSize visibleSize;
- bool ownedByLayerRenderer;
- bool isEmpty;
- };
static PassRefPtr<VideoLayerChromium> create(GraphicsLayerChromium* owner = 0,
VideoFrameProvider* = 0);
@@ -65,27 +59,31 @@
virtual void pushPropertiesTo(CCLayerImpl*);
+ virtual void setLayerTreeHost(CCLayerTreeHost*);
+
protected:
virtual void cleanupResources();
virtual const char* layerTypeAsString() const { return "VideoLayer"; }
private:
+ struct Texture {
+ IntSize m_visibleSize;
+ OwnPtr<ManagedTexture> m_texture;
+ };
+
VideoLayerChromium(GraphicsLayerChromium* owner, VideoFrameProvider*);
- static unsigned determineTextureFormat(const VideoFrameChromium*);
+ static GC3Denum determineTextureFormat(const VideoFrameChromium*);
static IntSize computeVisibleSize(const VideoFrameChromium*, unsigned plane);
- void deleteTexturesInUse();
+ bool reserveTextures(const VideoFrameChromium*, GC3Denum textureFormat);
+ void updateTexture(GraphicsContext3D*, Texture&, const void*) const;
- bool allocateTexturesIfNeeded(GraphicsContext3D*, const VideoFrameChromium*, unsigned textureFormat);
- void allocateTexture(GraphicsContext3D*, unsigned textureId, const IntSize& dimensions, unsigned textureFormat) const;
-
- void updateTexture(GraphicsContext3D*, unsigned textureId, const IntSize& dimensions, unsigned textureFormat, const void* data) const;
-
void resetFrameParameters();
bool m_skipsDraw;
VideoFrameChromium::Format m_frameFormat;
VideoFrameProvider* m_provider;
+ CCLayerTreeHost* m_layerTreeHost;
Texture m_textures[3];
Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.cpp (93795 => 93796)
--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.cpp 2011-08-25 17:13:59 UTC (rev 93795)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.cpp 2011-08-25 17:24:06 UTC (rev 93796)
@@ -229,6 +229,14 @@
return layerRenderer;
}
+TextureManager* CCLayerTreeHost::contentsTextureManager() const
+{
+ // FIXME: this class should own the contents texture manager
+ if (!m_layerRenderer)
+ return 0;
+ return m_layerRenderer->contentsTextureManager();
+}
+
#if !USE(THREADED_COMPOSITING)
void CCLayerTreeHost::doComposite()
{
Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.h (93795 => 93796)
--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.h 2011-08-25 17:13:59 UTC (rev 93795)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.h 2011-08-25 17:24:06 UTC (rev 93796)
@@ -45,6 +45,7 @@
class LayerRendererChromium;
class GraphicsLayer;
class NonCompositedContentHost;
+class TextureManager;
class CCLayerTreeHostClient {
public:
@@ -112,6 +113,7 @@
void setViewport(const IntSize& viewportSize, const IntSize& contentsSize, const IntPoint& scrollPosition);
const IntSize& viewportSize() const { return m_viewportSize; }
+ TextureManager* contentsTextureManager() const;
void setVisible(bool);
Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCVideoLayerImpl.cpp (93795 => 93796)
--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCVideoLayerImpl.cpp 2011-08-25 17:13:59 UTC (rev 93795)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCVideoLayerImpl.cpp 2011-08-25 17:24:06 UTC (rev 93796)
@@ -32,7 +32,6 @@
#include "GraphicsContext3D.h"
#include "LayerRendererChromium.h"
#include "NotImplemented.h"
-#include "VideoLayerChromium.h"
#include "cc/CCLayerTreeHostImplProxy.h"
#include <wtf/text/WTFString.h>
@@ -70,10 +69,12 @@
cleanupResources();
}
-void CCVideoLayerImpl::setTexture(size_t i, VideoLayerChromium::Texture texture)
+void CCVideoLayerImpl::setTexture(size_t index, Platform3DObject textureId, const IntSize& size, const IntSize& visibleSize)
{
- ASSERT(i < 3);
- m_textures[i] = texture;
+ ASSERT(index < 3);
+ m_textures[index].id = textureId;
+ m_textures[index].size = size;
+ m_textures[index].visibleSize = visibleSize;
}
void CCVideoLayerImpl::draw()
@@ -107,9 +108,9 @@
void CCVideoLayerImpl::drawYUV(const CCVideoLayerImpl::YUVProgram* program) const
{
GraphicsContext3D* context = layerRenderer()->context();
- VideoLayerChromium::Texture yTexture = m_textures[VideoFrameChromium::yPlane];
- VideoLayerChromium::Texture uTexture = m_textures[VideoFrameChromium::uPlane];
- VideoLayerChromium::Texture vTexture = m_textures[VideoFrameChromium::vPlane];
+ CCVideoLayerImpl::Texture yTexture = m_textures[VideoFrameChromium::yPlane];
+ CCVideoLayerImpl::Texture uTexture = m_textures[VideoFrameChromium::uPlane];
+ CCVideoLayerImpl::Texture vTexture = m_textures[VideoFrameChromium::vPlane];
GLC(context, context->activeTexture(GraphicsContext3D::TEXTURE1));
GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, yTexture.id));
@@ -145,7 +146,7 @@
void CCVideoLayerImpl::drawRGBA(const CCVideoLayerImpl::RGBAProgram* program) const
{
GraphicsContext3D* context = layerRenderer()->context();
- VideoLayerChromium::Texture texture = m_textures[VideoFrameChromium::rgbPlane];
+ CCVideoLayerImpl::Texture texture = m_textures[VideoFrameChromium::rgbPlane];
GLC(context, context->activeTexture(GraphicsContext3D::TEXTURE0));
GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, texture.id));
Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCVideoLayerImpl.h (93795 => 93796)
--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCVideoLayerImpl.h 2011-08-25 17:13:59 UTC (rev 93795)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCVideoLayerImpl.h 2011-08-25 17:24:06 UTC (rev 93796)
@@ -53,11 +53,17 @@
void setSkipsDraw(bool skipsDraw) { m_skipsDraw = skipsDraw; }
void setFrameFormat(VideoFrameChromium::Format format) { m_frameFormat = format; }
- void setTexture(size_t, VideoLayerChromium::Texture);
+ void setTexture(size_t, Platform3DObject textureId, const IntSize&, const IntSize& visibleSize);
private:
explicit CCVideoLayerImpl(int);
+ struct Texture {
+ Platform3DObject id;
+ IntSize size;
+ IntSize visibleSize;
+ };
+
void drawYUV(const YUVProgram*) const;
void drawRGBA(const RGBAProgram*) const;
@@ -66,7 +72,7 @@
bool m_skipsDraw;
VideoFrameChromium::Format m_frameFormat;
- VideoLayerChromium::Texture m_textures[3];
+ Texture m_textures[3];
};
}