Changeset 21517 in webkit


Ignore:
Timestamp:
May 16, 2007 6:53:52 AM (17 years ago)
Author:
zack
Message:

Implement Canvas element in the Qt port.

Implementation of Context2D was completely missing in the
Qt port. This commit adds bigger parts of it.
r=Lars

Location:
trunk/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r21516 r21517  
     12007-05-16  Zack Rusin  <zrusin@trolltech.com>
     2
     3        Reviewed by Lars.
     4
     5        Implement bigger parts of the Canvas element in the
     6        Qt port. Gradients and patterns are missing.
     7
     8        * WebCore/html/CanvasRenderingContext2D.cpp:
     9        * WebCore/html/CanvasStyle.cpp:
     10        * WebCore/html/HTMLCanvasElement.cpp:
     11        * WebCore/html/HTMLCanvasElement:
     12
    1132007-05-16  Zack Rusin  <zrusin@trolltech.com>
    214
  • trunk/WebCore/html/CanvasRenderingContext2D.cpp

    r21294 r21517  
    11/*
    22 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.  All rights reserved.
     3 * Copyright (C) 2007 Trolltech ASA
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    4445#include <wtf/MathExtras.h>
    4546
     47#if PLATFORM(QT)
     48#include <QPainter>
     49#include <QPixmap>
     50#include <QPainterPath>
     51#endif
     52
    4653namespace WebCore {
    4754
     
    446453        CGContextFillPath(c->platformContext());
    447454    }
     455#elif PLATFORM(QT)
     456    QPainterPath* path = state().m_path.platformPath();
     457    QPainter* p = static_cast<QPainter*>(c->platformContext());
     458    willDraw(path->controlPointRect());
     459    if (state().m_fillStyle->gradient()) {
     460        fprintf(stderr, "FIXME: CanvasRenderingContext2D::fill\n");
     461    } else {
     462        if (state().m_fillStyle->pattern())
     463            applyFillPattern();
     464        p->fillPath(*path, p->brush());
     465    }
    448466#endif
    449467}
     
    477495        CGContextStrokePath(c->platformContext());
    478496    }
     497#elif PLATFORM(QT)
     498    QPainterPath* path = state().m_path.platformPath();
     499    QPainter* p = static_cast<QPainter*>(c->platformContext());
     500    willDraw(path->controlPointRect());
     501    if (state().m_strokeStyle->gradient()) {
     502        fprintf(stderr, "FIXME: CanvasRenderingContext2D::stroke\n");
     503    } else {
     504        if (state().m_strokeStyle->pattern())
     505            applyStrokePattern();
     506        p->strokePath(*path, p->pen());
     507    }
    479508#endif
    480509
     
    534563            applyFillPattern();
    535564        CGContextFillRect(c->platformContext(), rect);
     565    }
     566#elif PLATFORM(QT)
     567    QRectF rect(x, y, width, height);
     568    willDraw(rect);
     569    QPainter* p = static_cast<QPainter*>(c->platformContext());
     570    if (state().m_fillStyle->gradient()) {
     571        fprintf(stderr, "FIXME: Canvas gradients\n");
     572    } else {
     573        if (state().m_fillStyle->pattern())
     574            applyFillPattern();
     575        p->fillRect(rect, p->brush());
    536576    }
    537577#endif
     
    853893
    854894    CGImageRelease(platformImage);
     895#elif PLATFORM(QT)
     896    QPixmap px = canvas->createPlatformImage();
     897    if (px.isNull())
     898        return;
     899    willDraw(dstRect);
     900    QPainter* painter = static_cast<QPainter*>(c->platformContext());
     901    painter->drawPixmap(dstRect, px, srcRect);
    855902#endif
    856903}
     
    927974    CGImageRelease(image);
    928975    return pattern;
    929 #else
     976#elif PLATFORM(QT)
     977    fprintf(stderr, "FIXME: CanvasRenderingContext2D::createPattern patterns not implemented\n");
     978#endif
    930979    return 0;
    931 #endif
    932980}
    933981
     
    9761024
    9771025    state().m_strokeStylePatternTransform = m;
     1026#elif PLATFORM(QT)
     1027    fprintf(stderr, "FIXME: CanvasRenderingContext2D::applyStrokePattern\n");
    9781028#endif
    9791029    state().m_appliedStrokePattern = true;
     
    10101060
    10111061    state().m_fillStylePatternTransform = m;
     1062#elif PLATFORM(QT)
     1063    fprintf(stderr, "FIXME: CanvasRenderingContext2D::applyStrokePattern\n");
    10121064#endif
    10131065    state().m_appliedFillPattern = true;
  • trunk/WebCore/html/CanvasStyle.cpp

    r16952 r21517  
    11/*
    22 * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
     3 * Copyright (C) 2007 Trolltech ASA
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3334#include <wtf/PassRefPtr.h>
    3435
     36#if PLATFORM(QT)
     37#include <QPainter>
     38#include <QBrush>
     39#include <QPen>
     40#include <QColor>
     41#endif
     42
    3543namespace WebCore {
    3644
     
    7987    if (!context)
    8088        return;
     89#if PLATFORM(QT)
     90    QPainter* p = static_cast<QPainter*>(context->platformContext());
     91#endif
    8192    switch (m_type) {
    8293        case ColorString: {
     
    89100                (color & 0xFF) / 255.0,
    90101                ((color >> 24) & 0xFF) / 255.0);
     102#elif PLATFORM(QT)
     103            p->setPen(QPen(QColor(QRgb(color))));
    91104#endif
    92105            break;
     
    101114                (color & 0xFF) / 255.0,
    102115                m_alpha);
    103 #endif
    104             break;
    105         }
    106         case GrayLevel:
     116#elif PLATFORM(QT)
     117            QColor clr = QColor(QRgb(color));
     118            clr.setAlphaF(m_alpha);
     119            p->setPen(clr);
     120#endif
     121            break;
     122        }
     123        case GrayLevel: {
    107124            // FIXME: Do this through platform-independent GraphicsContext API.
    108125#if PLATFORM(CG)
    109126            CGContextSetGrayStrokeColor(context->platformContext(), m_grayLevel, m_alpha);
    110 #endif
    111             break;
    112         case RGBA:
     127#elif PLATFORM(QT)
     128            QColor clr;
     129            clr.setRgbF(m_grayLevel, m_grayLevel, m_grayLevel, m_alpha);
     130            p->setPen(clr);
     131#endif
     132            break;
     133        }
     134        case RGBA: {
    113135            // FIXME: Do this through platform-independent GraphicsContext API.
    114136#if PLATFORM(CG)
    115137            CGContextSetRGBStrokeColor(context->platformContext(), m_red, m_green, m_blue, m_alpha);
    116 #endif
    117             break;
    118         case CMYKA:
     138#elif PLATFORM(QT)
     139            QColor clr; clr.setRgbF(m_red, m_green, m_blue, m_alpha);
     140            p->setPen(clr);
     141#endif
     142            break;
     143        }
     144        case CMYKA: {
    119145            // FIXME: Do this through platform-independent GraphicsContext API.
    120146#if PLATFORM(CG)
    121147            CGContextSetCMYKStrokeColor(context->platformContext(), m_cyan, m_magenta, m_yellow, m_black, m_alpha);
    122 #endif
    123             break;
     148#elif PLATFORM(QT)
     149            QColor clr;
     150            clr.setCmykF(m_cyan, m_magenta, m_yellow, m_black, m_alpha);
     151            p->setPen(clr);
     152#endif
     153            break;
     154        }
    124155        case Gradient:
    125156        case ImagePattern:
     
    132163    if (!context)
    133164        return;
     165#if PLATFORM(QT)
     166    QPainter* p = static_cast<QPainter*>(context->platformContext());
     167#endif
    134168    switch (m_type) {
    135169        case ColorString: {
     
    142176                (color & 0xFF) / 255.0,
    143177                ((color >> 24) & 0xFF) / 255.0);
     178#elif PLATFORM(QT)
     179            p->setBrush(QColor(QRgb(color)));
    144180#endif
    145181            break;
     
    154190                (color & 0xFF) / 255.0,
    155191                m_alpha);
    156 #endif
    157             break;
    158         }
    159         case GrayLevel:
     192#elif PLATFORM(QT)
     193            QColor clr = QColor(QRgb(color));
     194            clr.setAlphaF(m_alpha);
     195            p->setBrush(clr);
     196#endif
     197            break;
     198        }
     199        case GrayLevel: {
    160200            // FIXME: Do this through platform-independent GraphicsContext API.
    161201#if PLATFORM(CG)
    162202            CGContextSetGrayFillColor(context->platformContext(), m_grayLevel, m_alpha);
    163 #endif
    164             break;
    165         case RGBA:
     203#elif PLATFORM(QT)
     204            QColor clr; clr.setRgbF(m_grayLevel, m_grayLevel, m_grayLevel, m_alpha);
     205            p->setBrush(clr);
     206#endif
     207            break;
     208        }
     209        case RGBA: {
    166210            // FIXME: Do this through platform-independent GraphicsContext API.
    167211#if PLATFORM(CG)
    168212            CGContextSetRGBFillColor(context->platformContext(), m_red, m_green, m_blue, m_alpha);
    169 #endif
    170             break;
    171         case CMYKA:
     213#elif PLATFORM(QT)
     214            QColor clr; clr.setRgbF(m_red, m_green, m_blue, m_alpha);
     215            p->setBrush(clr);
     216#endif
     217            break;
     218        }
     219        case CMYKA: {
    172220            // FIXME: Do this through platform-independent GraphicsContext API.
    173221#if PLATFORM(CG)
    174222            CGContextSetCMYKFillColor(context->platformContext(), m_cyan, m_magenta, m_yellow, m_black, m_alpha);
    175 #endif
    176             break;
     223#elif PLATFORM(QT)
     224            QColor clr;
     225            clr.setCmykF(m_cyan, m_magenta, m_yellow, m_black, m_alpha);
     226            p->setBrush(clr);
     227#endif
     228            break;
     229        }
    177230        case Gradient:
    178231        case ImagePattern:
  • trunk/WebCore/html/HTMLCanvasElement.cpp

    r21211 r21517  
    3939#include "RenderHTMLCanvas.h"
    4040#include "Settings.h"
     41
     42#if PLATFORM(QT)
     43#include <QPainter>
     44#include <QPixmap>
     45#endif
     46
    4147#include <math.h>
     48
    4249
    4350namespace WebCore {
     
    5966    , m_createdDrawingContext(false)
    6067    , m_data(0)
     68#if PLATFORM(QT)
     69    , m_painter(0)
     70#endif
    6171    , m_drawingContext(0)
    6272{
     
    6777    if (m_2DContext)
    6878        m_2DContext->detachCanvas();
     79#if PLATFORM(CG)
    6980    fastFree(m_data);
     81#elif PLATFORM(QT)
     82    delete m_painter;
     83    delete m_data;
     84#endif
    7085    delete m_drawingContext;
    7186}
     
    151166    bool hadDrawingContext = m_createdDrawingContext;
    152167    m_createdDrawingContext = false;
     168#if PLATFORM(QT)
    153169    fastFree(m_data);
     170#elif PLATFORM(QT)
     171    delete m_painter;
     172    delete m_data;
     173#endif
    154174    m_data = 0;
    155175    delete m_drawingContext;
     
    174194        CGImageRelease(image);
    175195    }
     196#elif PLATFORM(QT)
     197    if (m_data) {
     198        if (m_painter->isActive())
     199            m_painter->end();
     200        static_cast<QPainter*>(p->platformContext())->drawPixmap(r, *m_data);
     201    }
    176202#endif
    177203}
     
    199225    if (bytesPerRow / 4 != w) // check for overflow
    200226        return;
     227#if PLATFORM(CG)
    201228    m_data = fastCalloc(h, bytesPerRow);
     229#elif PLATFORM(QT)
     230    m_data = new QPixmap(w, h);
     231#endif
    202232    if (!m_data)
    203233        return;
     
    209239    m_drawingContext = new GraphicsContext(bitmapContext);
    210240    CGContextRelease(bitmapContext);
     241#elif PLATFORM(QT)
     242    m_data->fill(Qt::white);
     243    m_painter = new QPainter(m_data);
     244    m_drawingContext = new GraphicsContext(m_painter);
    211245#endif
    212246}
     
    235269    return CGBitmapContextCreateImage(contextRef);
    236270}
    237 
    238 #endif
    239 
    240 }
     271#elif PLATFORM(QT)
     272QPixmap HTMLCanvasElement::createPlatformImage() const
     273{
     274    if (m_data)
     275        return *m_data;
     276    return QPixmap();
     277}
     278
     279#endif
     280
     281}
  • trunk/WebCore/html/HTMLCanvasElement.h

    r20170 r21517  
    3434typedef struct CGContext* CGContextRef;
    3535typedef struct CGImage* CGImageRef;
     36#elif PLATFORM(QT)
     37class QPixmap;
     38class QPainter;
    3639#endif
    3740
     
    7174#if PLATFORM(CG)
    7275    CGImageRef createPlatformImage() const;
     76#elif PLATFORM(QT)
     77    QPixmap createPlatformImage() const;
    7378#endif
    7479
     
    8691
    8792    mutable bool m_createdDrawingContext;
     93#if PLATFORM(CG)
    8894    mutable void* m_data;
     95#elif PLATFORM(QT)
     96    mutable QPixmap* m_data;
     97    mutable QPainter* m_painter;
     98#endif
    8999    mutable GraphicsContext* m_drawingContext;
    90100};
Note: See TracChangeset for help on using the changeset viewer.