Changeset 189730 in webkit


Ignore:
Timestamp:
Sep 14, 2015 6:59:52 AM (9 years ago)
Author:
Carlos Garcia Campos
Message:

Merge r189216 - [Cairo][WebGL] Upload the accelerated canvas as a texture by copying via GPU directly
https://bugs.webkit.org/show_bug.cgi?id=148631

Patch by Jinyoung Hur <hur.ims@navercorp.com> on 2015-09-01
Reviewed by Dean Jackson.

When an accelerated canvas needs to be uploaded as a gl texture, it would be better to copy it to
texture directly via GPU using glCopyTexImage2D.
Note that GPU copy can not always be enabled because, with premultiplyAlpha and flipY unpack option,
it seems hard to be implemented in a way of direct GPU copy.

No new tests because there is no behavior change.

  • html/canvas/WebGLRenderingContextBase.cpp:

(WebCore::WebGLRenderingContextBase::texImage2D):

  • platform/graphics/ImageBuffer.cpp:

(WebCore::ImageBuffer::copyToPlatformTexture):

  • platform/graphics/ImageBuffer.h:
  • platform/graphics/cairo/ImageBufferCairo.cpp:

(WebCore::ImageBuffer::copyToPlatformTexture):

Location:
releases/WebKitGTK/webkit-2.10/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • releases/WebKitGTK/webkit-2.10/Source/WebCore/ChangeLog

    r189729 r189730  
     12015-09-01  Jinyoung Hur  <hur.ims@navercorp.com>
     2
     3        [Cairo][WebGL] Upload the accelerated canvas as a texture by copying via GPU directly
     4        https://bugs.webkit.org/show_bug.cgi?id=148631
     5
     6        Reviewed by Dean Jackson.
     7
     8        When an accelerated canvas needs to be uploaded as a gl texture, it would be better to copy it to
     9        texture directly via GPU using glCopyTexImage2D.
     10        Note that GPU copy can not always be enabled because, with premultiplyAlpha and flipY unpack option,
     11        it seems hard to be implemented in a way of direct GPU copy.
     12
     13        No new tests because there is no behavior change.
     14
     15        * html/canvas/WebGLRenderingContextBase.cpp:
     16        (WebCore::WebGLRenderingContextBase::texImage2D):
     17        * platform/graphics/ImageBuffer.cpp:
     18        (WebCore::ImageBuffer::copyToPlatformTexture):
     19        * platform/graphics/ImageBuffer.h:
     20        * platform/graphics/cairo/ImageBufferCairo.cpp:
     21        (WebCore::ImageBuffer::copyToPlatformTexture):
     22
    1232015-08-31  Chris Dumez  <cdumez@apple.com>
    224
  • releases/WebKitGTK/webkit-2.10/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp

    r189687 r189730  
    32203220    // FIXME: restriction of (RGB || RGBA)/UNSIGNED_BYTE should be lifted when
    32213221    // ImageBuffer::copyToPlatformTexture implementations are fully functional.
    3222     if (GraphicsContext3D::TEXTURE_2D == target && texture && type == texture->getType(target, level)
    3223         && (format == GraphicsContext3D::RGB || format == GraphicsContext3D::RGBA) && type == GraphicsContext3D::UNSIGNED_BYTE) {
     3222    if (texture
     3223        && (format == GraphicsContext3D::RGB || format == GraphicsContext3D::RGBA)
     3224        && type == GraphicsContext3D::UNSIGNED_BYTE
     3225        && (texture->getType(target, level) == GraphicsContext3D::UNSIGNED_BYTE || !texture->isValid(target, level))) {
    32243226        ImageBuffer* buffer = canvas->buffer();
    3225         if (buffer && buffer->copyToPlatformTexture(*m_context.get(), texture->object(), internalformat, m_unpackPremultiplyAlpha, m_unpackFlipY)) {
     3227        if (buffer && buffer->copyToPlatformTexture(*m_context.get(), target, texture->object(), internalformat, m_unpackPremultiplyAlpha, m_unpackFlipY)) {
    32263228            texture->setLevelInfo(target, level, internalformat, canvas->width(), canvas->height(), type);
    32273229            return;
  • releases/WebKitGTK/webkit-2.10/Source/WebCore/platform/graphics/ImageBuffer.cpp

    r183960 r189730  
    152152    return 0;
    153153}
    154 #endif
    155154
    156 bool ImageBuffer::copyToPlatformTexture(GraphicsContext3D&, Platform3DObject, GC3Denum, bool, bool)
     155bool ImageBuffer::copyToPlatformTexture(GraphicsContext3D&, GC3Denum, Platform3DObject, GC3Denum, bool, bool)
    157156{
    158157    return false;
    159158}
     159#endif
    160160
    161161std::unique_ptr<ImageBuffer> ImageBuffer::createCompatibleBuffer(const FloatSize& size, float resolutionScale, ColorSpace colorSpace, const GraphicsContext* context, bool)
  • releases/WebKitGTK/webkit-2.10/Source/WebCore/platform/graphics/ImageBuffer.h

    r187274 r189730  
    123123    // FIXME: current implementations of this method have the restriction that they only work
    124124    // with textures that are RGB or RGBA format, and UNSIGNED_BYTE type.
    125     bool copyToPlatformTexture(GraphicsContext3D&, Platform3DObject, GC3Denum, bool, bool);
     125    bool copyToPlatformTexture(GraphicsContext3D&, GC3Denum, Platform3DObject, GC3Denum, bool, bool);
    126126
    127127    FloatSize spaceSize() const { return m_space; }
  • releases/WebKitGTK/webkit-2.10/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp

    r189706 r189730  
    432432}
    433433
     434bool ImageBuffer::copyToPlatformTexture(GraphicsContext3D&, GC3Denum target, Platform3DObject destinationTexture, GC3Denum internalformat, bool premultiplyAlpha, bool flipY)
     435{
     436#if ENABLE(ACCELERATED_2D_CANVAS)
     437    if (premultiplyAlpha || flipY)
     438        return false;
     439
     440    if (!m_data.m_texture)
     441        return false;
     442
     443    GC3Denum bindTextureTarget;
     444    switch (target) {
     445    case GL_TEXTURE_2D:
     446        bindTextureTarget = GL_TEXTURE_2D;
     447        break;
     448    case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
     449    case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
     450    case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
     451    case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
     452    case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
     453    case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
     454        bindTextureTarget = GL_TEXTURE_CUBE_MAP;
     455        break;
     456    default:
     457        return false;
     458    }
     459
     460    cairo_surface_flush(m_data.m_surface.get());
     461
     462    std::unique_ptr<GLContext> context = GLContext::createContextForWindow(0, GLContext::sharingContext());
     463    context->makeContextCurrent();
     464    uint32_t fbo;
     465    glGenFramebuffers(1, &fbo);
     466    glBindFramebuffer(GL_FRAMEBUFFER, fbo);
     467    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_data.m_texture, 0);
     468    glBindTexture(bindTextureTarget, destinationTexture);
     469    glCopyTexImage2D(target, 0, internalformat, 0, 0, m_size.width(), m_size.height(), 0);
     470    glBindTexture(bindTextureTarget, 0);
     471    glBindFramebuffer(GL_FRAMEBUFFER, 0);
     472    glFlush();
     473    glDeleteFramebuffers(1, &fbo);
     474    return true;
     475#else
     476    UNUSED_PARAM(target);
     477    UNUSED_PARAM(destinationTexture);
     478    UNUSED_PARAM(internalformat);
     479    UNUSED_PARAM(premultiplyAlpha);
     480    UNUSED_PARAM(flipY);
     481    return false;
     482#endif
     483}
     484
    434485} // namespace WebCore
    435486
Note: See TracChangeset for help on using the changeset viewer.