Changeset 64731 in webkit


Ignore:
Timestamp:
Aug 5, 2010 4:15:10 AM (14 years ago)
Author:
commit-queue@webkit.org
Message:

2010-08-05 Victoria Kirst <vrk@google.com>

Reviewed by David Levin.

Added logic to use glMapTexSubImage2D to write video layer to GPU
texture. Also fixes CPU usage problem from previous patch.
https://bugs.webkit.org/show_bug.cgi?id=43101

No change in user-visible functionality (since it isn't turned on),
so no new tests.

  • platform/graphics/chromium/VideoLayerChromium.cpp: (WebCore::VideoLayerChromium::VideoLayerChromium): (WebCore::VideoLayerChromium::updateTextureContents): (WebCore::VideoLayerChromium::createTextureRect): (WebCore::VideoLayerChromium::updateTextureRect): (WebCore::VideoLayerChromium::updateCompleted):
  • platform/graphics/chromium/VideoLayerChromium.h:

2010-08-05 Victoria Kirst <vrk@google.com>

Reviewed by David Levin.

Added a repaint request so that VideoLayerChromium does not have
a flickering problem when playing video.
https://bugs.webkit.org/show_bug.cgi?id=43101

  • src/WebMediaPlayerClientImpl.cpp: (WebKit::WebMediaPlayerClientImpl::repaint):
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r64726 r64731  
     12010-08-05  Victoria Kirst  <vrk@google.com>
     2
     3        Reviewed by David Levin.
     4
     5        Added logic to use glMapTexSubImage2D to write video layer to GPU
     6        texture. Also fixes CPU usage problem from previous patch.
     7        https://bugs.webkit.org/show_bug.cgi?id=43101
     8
     9        No change in user-visible functionality (since it isn't turned on),
     10        so no new tests.
     11
     12        * platform/graphics/chromium/VideoLayerChromium.cpp:
     13        (WebCore::VideoLayerChromium::VideoLayerChromium):
     14        (WebCore::VideoLayerChromium::updateTextureContents):
     15        (WebCore::VideoLayerChromium::createTextureRect):
     16        (WebCore::VideoLayerChromium::updateTextureRect):
     17        (WebCore::VideoLayerChromium::updateCompleted):
     18        * platform/graphics/chromium/VideoLayerChromium.h:
     19
    1202010-08-05  Zoltan Horvath  <zoltan@webkit.org>
    221
  • trunk/WebCore/platform/graphics/chromium/VideoLayerChromium.cpp

    r63723 r64731  
    3232
    3333#if USE(ACCELERATED_COMPOSITING)
     34#include "VideoLayerChromium.h"
    3435
    35 #include "VideoLayerChromium.h"
     36#include "LayerRendererChromium.h"
     37#include "RenderLayerBacking.h"
     38#include "skia/ext/platform_canvas.h"
     39
     40#include <GLES2/gl2.h>
     41#define GL_GLEXT_PROTOTYPES
     42#include <GLES2/gl2ext.h>
     43
     44#if PLATFORM(SKIA)
     45#include "NativeImageSkia.h"
     46#include "PlatformContextSkia.h"
     47#endif
    3648
    3749namespace WebCore {
     
    4456VideoLayerChromium::VideoLayerChromium(GraphicsLayerChromium* owner)
    4557    : LayerChromium(owner)
     58    , m_allocatedTextureId(0)
     59    , m_canvas(0)
     60    , m_skiaContext(0)
     61    , m_graphicsContext(0)
    4662{
     63}
     64
     65void VideoLayerChromium::updateTextureContents(unsigned textureId)
     66{
     67    RenderLayerBacking* backing = static_cast<RenderLayerBacking*>(m_owner->client());
     68    if (!backing || backing->paintingGoesToWindow())
     69        return;
     70
     71    ASSERT(drawsContent());
     72
     73    IntRect dirtyRect(m_dirtyRect);
     74    IntSize requiredTextureSize;
     75
     76#if PLATFORM(SKIA)
     77    requiredTextureSize = m_bounds;
     78    IntRect boundsRect(IntPoint(0, 0), m_bounds);
     79
     80    // If the texture needs to be reallocated, then we must redraw the entire
     81    // contents of the layer.
     82    if (requiredTextureSize != m_allocatedTextureSize)
     83        dirtyRect = boundsRect;
     84    else {
     85        // Clip the dirtyRect to the size of the layer to avoid drawing outside
     86        // the bounds of the backing texture.
     87        dirtyRect.intersect(boundsRect);
     88    }
     89
     90    if (!m_canvas.get()
     91        || dirtyRect.width() != m_canvas->getDevice()->width()
     92        || dirtyRect.height() != m_canvas->getDevice()->height()) {
     93        m_canvas = new skia::PlatformCanvas(dirtyRect.width(), dirtyRect.height(), true);
     94        m_skiaContext = new PlatformContextSkia(m_canvas.get());
     95
     96#if OS(WINDOWS)
     97        // This is needed to get text to show up correctly. Without it,
     98        // GDI renders with zero alpha and the text becomes invisible.
     99        // Unfortunately, setting this to true disables cleartype.
     100        // FIXME: Does this take us down a very slow text rendering path?
     101        // FIXME: Why is this is a windows-only call?
     102        m_skiaContext->setDrawingToImageBuffer(true);
     103#endif
     104        m_graphicsContext = new GraphicsContext(reinterpret_cast<PlatformGraphicsContext*>(m_skiaContext.get()));
     105    }
     106
     107    // Bring the canvas into the coordinate system of the paint rect.
     108    m_canvas->translate(static_cast<SkScalar>(-dirtyRect.x()), static_cast<SkScalar>(-dirtyRect.y()));
     109
     110    // If the texture id or size changed since last time, then we need to tell GL
     111    // to re-allocate a texture.
     112    if (m_allocatedTextureId != textureId || requiredTextureSize != m_allocatedTextureSize)
     113        createTextureRect(requiredTextureSize, dirtyRect, textureId);
     114    else
     115        updateTextureRect(dirtyRect, textureId);
     116#else
     117#error "Need to implement for your platform."
     118#endif
     119}
     120
     121void VideoLayerChromium::createTextureRect(const IntSize& requiredTextureSize, const IntRect& updateRect, unsigned textureId)
     122{
     123    // Paint into graphics context and get bitmap.
     124    m_owner->paintGraphicsLayerContents(*m_graphicsContext, updateRect);
     125    const SkBitmap& bitmap = m_canvas->getDevice()->accessBitmap(false);
     126    const SkBitmap* skiaBitmap = &bitmap;
     127    ASSERT(skiaBitmap);
     128
     129    void* pixels = 0;
     130    IntSize bitmapSize;
     131    SkAutoLockPixels lock(*skiaBitmap);
     132    SkBitmap::Config skiaConfig = skiaBitmap->config();
     133    // FIXME: Do we need to support more image configurations?
     134    if (skiaConfig == SkBitmap::kARGB_8888_Config) {
     135        pixels = skiaBitmap->getPixels();
     136        bitmapSize = IntSize(skiaBitmap->width(), skiaBitmap->height());
     137    }
     138
     139    if (!pixels)
     140        return;
     141
     142    glBindTexture(GL_TEXTURE_2D, textureId);
     143    ASSERT(bitmapSize == requiredTextureSize);
     144    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, requiredTextureSize.width(), requiredTextureSize.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
     145
     146    m_allocatedTextureId = textureId;
     147    m_allocatedTextureSize = requiredTextureSize;
     148
     149    updateCompleted();
     150}
     151
     152void VideoLayerChromium::updateTextureRect(const IntRect& updateRect, unsigned textureId)
     153{
     154    const SkBitmap& bitmap = m_canvas->getDevice()->accessBitmap(true);
     155    SkBitmap* skiaBitmap = const_cast<SkBitmap*>(&bitmap);
     156    ASSERT(skiaBitmap);
     157
     158    SkAutoLockPixels lock(*skiaBitmap);
     159    SkBitmap::Config skiaConfig = skiaBitmap->config();
     160
     161    if (skiaConfig == SkBitmap::kARGB_8888_Config) {
     162        glBindTexture(GL_TEXTURE_2D, textureId);
     163        void* mem = glMapTexSubImage2D(GL_TEXTURE_2D, 0, updateRect.x(), updateRect.y(), updateRect.width(), updateRect.height(), GL_RGBA, GL_UNSIGNED_BYTE, GL_WRITE_ONLY);
     164        skiaBitmap->setPixels(mem);
     165        m_owner->paintGraphicsLayerContents(*m_graphicsContext, updateRect);
     166        glUnmapTexSubImage2D(mem);
     167    }
     168
     169    updateCompleted();
     170}
     171
     172void VideoLayerChromium::updateCompleted()
     173{
     174    m_dirtyRect.setSize(FloatSize());
     175    m_contentsDirty = false;
    47176}
    48177
  • trunk/WebCore/platform/graphics/chromium/VideoLayerChromium.h

    r63723 r64731  
    4444    static PassRefPtr<VideoLayerChromium> create(GraphicsLayerChromium* owner = 0);
    4545    virtual bool drawsContent() { return true; }
     46    virtual void updateTextureContents(unsigned textureId);
    4647
    4748private:
    4849    VideoLayerChromium(GraphicsLayerChromium* owner);
     50    void createTextureRect(const IntSize& requiredTextureSize, const IntRect& updateRect, unsigned textureId);
     51    void updateTextureRect(const IntRect& updateRect, unsigned textureId);
     52    void updateCompleted();
     53
     54    unsigned m_allocatedTextureId;
     55    IntSize m_allocatedTextureSize;
     56    OwnPtr<skia::PlatformCanvas> m_canvas;
     57    OwnPtr<PlatformContextSkia> m_skiaContext;
     58    OwnPtr<GraphicsContext> m_graphicsContext;
    4959};
    5060
  • trunk/WebKit/chromium/ChangeLog

    r64729 r64731  
     12010-08-05  Victoria Kirst  <vrk@google.com>
     2
     3        Reviewed by David Levin.
     4
     5        Added a repaint request so that VideoLayerChromium does not have
     6        a flickering problem when playing video.
     7        https://bugs.webkit.org/show_bug.cgi?id=43101
     8
     9        * src/WebMediaPlayerClientImpl.cpp:
     10        (WebKit::WebMediaPlayerClientImpl::repaint):
     11
    1122010-08-05  Pavel Feldman  <pfeldman@chromium.org>
    213
  • trunk/WebKit/chromium/src/WebMediaPlayerClientImpl.cpp

    r63859 r64731  
    127127{
    128128    ASSERT(m_mediaPlayer);
     129#if USE(ACCELERATED_COMPOSITING)
     130    if (m_videoLayer.get() && supportsAcceleratedRendering())
     131        m_videoLayer->setNeedsDisplay(FloatRect(0, 0, m_videoLayer->bounds().width(), m_videoLayer->bounds().height()));
     132#endif
    129133    m_mediaPlayer->repaint();
    130134}
Note: See TracChangeset for help on using the changeset viewer.