Changeset 64881 in webkit


Ignore:
Timestamp:
Aug 6, 2010 4:29:27 PM (14 years ago)
Author:
jamesr@google.com
Message:

2010-08-06 James Robinson <jamesr@chromium.org>

Reviewed by Simon Fraser.

Accelerated 2d canvases should get compositing layers
https://bugs.webkit.org/show_bug.cgi?id=43362

Allows for 2d canvas rendering contexts to use a GraphicsContext3D for
accelerated rendering. The rendering context holds the GraphicsContext3D
alive and exposes it to the compositor. The 3d context itself is passed
down through the GraphicsContext to use for actual rendering:
https://bug-43362-attachments.webkit.org/attachment.cgi?id=63557

This approach will let us simultaneously prototype accelerated techniques
for canvas 2d and revise the design of canvas elements without destabilizing
all ports.

  • html/HTMLCanvasElement.cpp: (WebCore::HTMLCanvasElement::getContext): (WebCore::HTMLCanvasElement::willDraw): (WebCore::HTMLCanvasElement::makeRenderingResultsAvailable):
  • html/canvas/CanvasRenderingContext.h: (WebCore::CanvasRenderingContext::paintRenderingResultsToCanvas):
  • html/canvas/CanvasRenderingContext2D.cpp: (WebCore::CanvasRenderingContext2D::CanvasRenderingContext2D): (WebCore::CanvasRenderingContext2D::isAccelerated): (WebCore::CanvasRenderingContext2D::reset): (WebCore::CanvasRenderingContext2D::willDraw): (WebCore::CanvasRenderingContext2D::paintRenderingResultsToCanvas):
  • html/canvas/CanvasRenderingContext2D.h: (WebCore::CanvasRenderingContext2D::graphicsContext3D):
  • html/canvas/WebGLRenderingContext.cpp: (WebCore::WebGLRenderingContext::paintRenderingResultsToCanvas):
  • html/canvas/WebGLRenderingContext.h:
  • platform/graphics/GraphicsContext.h:
  • platform/graphics/skia/GraphicsContextSkia.cpp: (WebCore::GraphicsContext::syncSoftwareCanvas):
Location:
trunk/WebCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r64874 r64881  
     12010-08-06  James Robinson  <jamesr@chromium.org>
     2
     3        Reviewed by Simon Fraser.
     4
     5        Accelerated 2d canvases should get compositing layers
     6        https://bugs.webkit.org/show_bug.cgi?id=43362
     7
     8        Allows for 2d canvas rendering contexts to use a GraphicsContext3D for
     9        accelerated rendering.  The rendering context holds the GraphicsContext3D
     10        alive and exposes it to the compositor.  The 3d context itself is passed
     11        down through the GraphicsContext to use for actual rendering:
     12        https://bug-43362-attachments.webkit.org/attachment.cgi?id=63557
     13
     14        This approach will let us simultaneously prototype accelerated techniques
     15        for canvas 2d and revise the design of canvas elements without destabilizing
     16        all ports.
     17
     18        * html/HTMLCanvasElement.cpp:
     19        (WebCore::HTMLCanvasElement::getContext):
     20        (WebCore::HTMLCanvasElement::willDraw):
     21        (WebCore::HTMLCanvasElement::makeRenderingResultsAvailable):
     22        * html/canvas/CanvasRenderingContext.h:
     23        (WebCore::CanvasRenderingContext::paintRenderingResultsToCanvas):
     24        * html/canvas/CanvasRenderingContext2D.cpp:
     25        (WebCore::CanvasRenderingContext2D::CanvasRenderingContext2D):
     26        (WebCore::CanvasRenderingContext2D::isAccelerated):
     27        (WebCore::CanvasRenderingContext2D::reset):
     28        (WebCore::CanvasRenderingContext2D::willDraw):
     29        (WebCore::CanvasRenderingContext2D::paintRenderingResultsToCanvas):
     30        * html/canvas/CanvasRenderingContext2D.h:
     31        (WebCore::CanvasRenderingContext2D::graphicsContext3D):
     32        * html/canvas/WebGLRenderingContext.cpp:
     33        (WebCore::WebGLRenderingContext::paintRenderingResultsToCanvas):
     34        * html/canvas/WebGLRenderingContext.h:
     35        * platform/graphics/GraphicsContext.h:
     36        * platform/graphics/skia/GraphicsContextSkia.cpp:
     37        (WebCore::GraphicsContext::syncSoftwareCanvas):
     38
    1392010-08-06  Eric Seidel  <eric@webkit.org>
    240
  • trunk/WebCore/html/HTMLCanvasElement.cpp

    r63606 r64881  
    170170#endif
    171171            m_context = new CanvasRenderingContext2D(this, document()->inCompatMode(), usesDashbardCompatibilityMode);
     172#if ENABLE(ACCELERATED_2D_CANVAS) && USE(ACCELERATED_COMPOSITING)
     173            if (m_context) {
     174                // Need to make sure a RenderLayer and compositing layer get created for the Canvas
     175                setNeedsStyleRecalc(SyntheticStyleChange);
     176            }
     177#endif
    172178        }
    173179        return m_context.get();
     
    217223        ro->repaintRectangle(enclosingIntRect(m_dirtyRect));
    218224    }
    219    
     225
    220226    if (m_observer)
    221227        m_observer->canvasChanged(this, rect);
     
    300306void HTMLCanvasElement::makeRenderingResultsAvailable()
    301307{
    302 #if ENABLE(3D_CANVAS)
    303     if (is3D()) {
    304         WebGLRenderingContext* context3d = reinterpret_cast<WebGLRenderingContext*>(renderingContext());
    305         context3d->paintRenderingResultsToCanvas();
    306     }
    307 #endif
     308    if (m_context)
     309        m_context->paintRenderingResultsToCanvas();
    308310}
    309311
  • trunk/WebCore/html/canvas/CanvasRenderingContext.h

    r64685 r64881  
    5454        virtual GraphicsContext3D* graphicsContext3D() const { return 0; }
    5555
     56        virtual void paintRenderingResultsToCanvas() {}
     57
    5658    private:
    5759        HTMLCanvasElement* m_canvas;
  • trunk/WebCore/html/canvas/CanvasRenderingContext2D.cpp

    r64407 r64881  
    5959#include "TextMetrics.h"
    6060
    61 #include <stdio.h>
     61#if ENABLE(ACCELERATED_2D_CANVAS)
     62#include "FrameView.h"
     63#include "GraphicsContext3D.h"
     64#if USE(ACCELERATED_COMPOSITING)
     65#include "RenderLayer.h"
     66#endif
     67#endif
    6268
    6369#include <wtf/ByteArray.h>
     
    101107    , m_usesDashboardCompatibilityMode(usesDashboardCompatibilityMode)
    102108#endif
     109#if ENABLE(ACCELERATED_2D_CANVAS)
     110    , m_context3D(0)
     111#endif
    103112{
    104113#if !ENABLE(DASHBOARD_SUPPORT)
     
    109118    // thickness, it is in sync with the canvas thickness.
    110119    setLineWidth(lineWidth());
     120
     121#if ENABLE(ACCELERATED_2D_CANVAS)
     122    Page* p = canvas->document()->page();
     123    if (!p)
     124        return;
     125    if (!p->settings()->accelerated2dCanvasEnabled())
     126        return;
     127    if (FrameView* view = canvas->document()->view()) {
     128        if (ScrollView* rootView = view->root()) {
     129            if (HostWindow* hostWindow = view->root()->hostWindow()) {
     130                // Set up our context
     131                GraphicsContext3D::Attributes attr;
     132                attr.stencil = true;
     133                m_context3D = GraphicsContext3D::create(attr, hostWindow);
     134                if (m_context3D)
     135                    if (GraphicsContext* c = drawingContext())
     136                        c->setGraphicsContext3D(m_context3D.get(), IntSize(canvas->width(), canvas->height()));
     137            }
     138        }
     139    }
     140#endif
    111141}
    112142
    113143CanvasRenderingContext2D::~CanvasRenderingContext2D()
    114144{
     145}
     146
     147bool CanvasRenderingContext2D::isAccelerated() const
     148{
     149#if ENABLE(ACCELERATED_2D_CANVAS)
     150    return m_context3D;
     151#else
     152    return false;
     153#endif
    115154}
    116155
     
    120159    m_stateStack.first() = State();
    121160    m_path.clear();
     161#if ENABLE(ACCELERATED_2D_CANVAS)
     162    if (m_context3D) {
     163        if (GraphicsContext* c = drawingContext())
     164            c->setGraphicsContext3D(m_context3D.get(), IntSize(canvas()->width(), canvas()->height()));
     165    }
     166#endif
    122167}
    123168
     
    14351480    }
    14361481
    1437     canvas()->willDraw(dirtyRect);
     1482#if ENABLE(ACCELERATED_2D_CANVAS) && USE(ACCELERATED_COMPOSITING)
     1483    // If we are drawing to hardware and we have a composited layer, just call rendererContentChanged().
     1484    RenderBox* renderBox = canvas()->renderBox();
     1485    if (m_context3D && renderBox && renderBox->hasLayer() && renderBox->layer()->hasAcceleratedCompositing())
     1486        renderBox->layer()->rendererContentChanged();
     1487    else
     1488#endif
     1489        canvas()->willDraw(dirtyRect);
    14381490}
    14391491
     
    17731825}
    17741826
     1827void CanvasRenderingContext2D::paintRenderingResultsToCanvas()
     1828{
     1829#if ENABLE(ACCELERATED_2D_CANVAS)
     1830    drawingContext()->syncSoftwareCanvas();
     1831#endif
     1832}
     1833
    17751834} // namespace WebCore
  • trunk/WebCore/html/canvas/CanvasRenderingContext2D.h

    r64407 r64881  
    4343#endif
    4444
     45#if USE(ACCELERATED_COMPOSITING)
     46#include "GraphicsLayer.h"
     47#endif
     48
    4549namespace WebCore {
    4650
     
    5761class TextMetrics;
    5862
     63#if ENABLE(ACCELERATED_2D_CANVAS)
     64class GraphicsContext3D;
     65#endif
     66
    5967typedef int ExceptionCode;
    6068
     
    6674
    6775    virtual bool is2d() const { return true; }
     76    virtual bool isAccelerated() const;
    6877
    6978    CanvasStyle* strokeStyle() const;
     
    212221    LineCap getLineCap() const { return state().m_lineCap; }
    213222    LineJoin getLineJoin() const { return state().m_lineJoin; }
     223
     224    virtual void paintRenderingResultsToCanvas();
     225
     226#if ENABLE(ACCELERATED_2D_CANVAS)
     227    virtual GraphicsContext3D* graphicsContext3D() const { return m_context3D.get(); }
     228#endif
    214229
    215230private:
     
    282297    bool m_usesDashboardCompatibilityMode;
    283298#endif
     299
     300#if ENABLE(ACCELERATED_2D_CANVAS)
     301    OwnPtr<GraphicsContext3D> m_context3D;
     302#endif
    284303};
    285304
  • trunk/WebCore/html/canvas/WebGLRenderingContext.cpp

    r64767 r64881  
    157157}
    158158
    159 bool WebGLRenderingContext::paintRenderingResultsToCanvas()
     159void WebGLRenderingContext::paintRenderingResultsToCanvas()
    160160{
    161161    if (m_markedCanvasDirty) {
     
    165165        m_markedCanvasDirty = false;
    166166        m_context->paintRenderingResultsToCanvas(this);
    167         return true;
    168     }
    169     return false;
     167    }
    170168}
    171169
  • trunk/WebCore/html/canvas/WebGLRenderingContext.h

    r64767 r64881  
    308308    void reshape(int width, int height);
    309309
    310     // Return value true indicates canvas is updated during the call,
    311     // false indicates no updates.
    312     bool paintRenderingResultsToCanvas();
     310    virtual void paintRenderingResultsToCanvas();
    313311
    314312    // Helpers for notification about paint events.
  • trunk/WebCore/platform/graphics/GraphicsContext.h

    r64584 r64881  
    117117    class Generator;
    118118    class Gradient;
     119    class GraphicsContext3D;
    119120    class GraphicsContextPlatformPrivate;
    120121    class GraphicsContextPrivate;
     
    394395#endif
    395396
     397#if PLATFORM(SKIA)
     398        void setGraphicsContext3D(GraphicsContext3D*, const IntSize&);
     399        void syncSoftwareCanvas();
     400#endif
     401
    396402    private:
    397403        void savePlatformState();
  • trunk/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp

    r64872 r64881  
    12771277}
    12781278
     1279void GraphicsContext::setGraphicsContext3D(GraphicsContext3D* context3D, const IntSize& size)
     1280{
     1281#if USE(GLES2_RENDERING)
     1282    platformContext()->setGraphicsContext3D(context3D, size);
     1283#else
     1284    UNUSED_PARAM(context3D);
     1285    UNUSED_PARAM(size);
     1286#endif
     1287}
     1288
     1289void GraphicsContext::syncSoftwareCanvas()
     1290{
     1291#if USE(GLES2_RENDERING)
     1292    platformContext()->syncSoftwareCanvas();
     1293#endif
     1294}
     1295
    12791296}  // namespace WebCore
Note: See TracChangeset for help on using the changeset viewer.