rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 Dirk Mueller <mueller@kde.org> |
| 3 | * Copyright (C) 2006 Zack Rusin <zack@kde.org> |
| 4 | * Copyright (C) 2006 Simon Hausmann <hausmann@kde.org> |
treat@webkit.org | f793b27 | 2009-03-02 15:37:02 +0000 | [diff] [blame] | 5 | * Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ |
commit-queue@webkit.org | 580b2cb | 2010-11-23 08:00:30 +0000 | [diff] [blame] | 6 | * Copyright (C) 2010 Sencha, Inc. |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 7 | * |
| 8 | * All rights reserved. |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or without |
| 11 | * modification, are permitted provided that the following conditions |
| 12 | * are met: |
| 13 | * 1. Redistributions of source code must retain the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer. |
| 15 | * 2. Redistributions in binary form must reproduce the above copyright |
| 16 | * notice, this list of conditions and the following disclaimer in the |
| 17 | * documentation and/or other materials provided with the distribution. |
| 18 | * |
| 19 | * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
| 20 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
| 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 27 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | */ |
| 31 | |
| 32 | #include "config.h" |
| 33 | #include "Image.h" |
| 34 | |
krit@webkit.org | 2b95a9a | 2010-02-08 20:30:42 +0000 | [diff] [blame] | 35 | #include "AffineTransform.h" |
eseidel | 6195285 | 2006-12-29 01:57:44 +0000 | [diff] [blame] | 36 | #include "BitmapImage.h" |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 37 | #include "FloatRect.h" |
| 38 | #include "GraphicsContext.h" |
commit-queue@webkit.org | 580b2cb | 2010-11-23 08:00:30 +0000 | [diff] [blame] | 39 | #include "ImageObserver.h" |
commit-queue@webkit.org | d1e03a7 | 2011-07-05 21:29:42 +0000 | [diff] [blame] | 40 | #include "ShadowBlur.h" |
hausmann@webkit.org | edf3513 | 2008-05-08 14:58:01 +0000 | [diff] [blame] | 41 | #include "StillImageQt.h" |
weinig@apple.com | 3f5ab02 | 2012-09-06 17:36:48 +0000 | [diff] [blame] | 42 | #include <wtf/text/WTFString.h> |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 43 | |
hausmann@webkit.org | ea04d9f | 2012-02-15 14:14:27 +0000 | [diff] [blame] | 44 | #include <QCoreApplication> |
hausmann@webkit.org | 71c57c7 | 2011-11-17 14:22:48 +0000 | [diff] [blame] | 45 | #include <QDebug> |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 46 | #include <QImage> |
| 47 | #include <QImageReader> |
hausmann@webkit.org | 71c57c7 | 2011-11-17 14:22:48 +0000 | [diff] [blame] | 48 | #include <QPainter> |
| 49 | #include <QPixmap> |
lars | f6076a4 | 2007-01-17 19:04:39 +0000 | [diff] [blame] | 50 | #include <QTransform> |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 51 | |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 52 | #include <math.h> |
| 53 | |
hausmann@webkit.org | 2d2e535 | 2012-08-07 12:06:52 +0000 | [diff] [blame] | 54 | #if OS(WINDOWS) |
ossy@webkit.org | 618d62e3 | 2012-06-12 13:30:54 +0000 | [diff] [blame] | 55 | Q_GUI_EXPORT QPixmap qt_pixmapFromWinHBITMAP(HBITMAP, int hbitmapFormat = 0); |
| 56 | #endif |
| 57 | |
zoltan@webkit.org | b4e6b15 | 2012-10-08 13:44:14 +0000 | [diff] [blame^] | 58 | typedef QHash<QByteArray, QPixmap> WebGraphicHash; |
hausmann@webkit.org | 71c57c7 | 2011-11-17 14:22:48 +0000 | [diff] [blame] | 59 | Q_GLOBAL_STATIC(WebGraphicHash, _graphics) |
| 60 | |
| 61 | static void earlyClearGraphics() |
| 62 | { |
| 63 | _graphics()->clear(); |
| 64 | } |
| 65 | |
| 66 | static WebGraphicHash* graphics() |
| 67 | { |
| 68 | WebGraphicHash* hash = _graphics(); |
| 69 | |
| 70 | if (hash->isEmpty()) { |
| 71 | |
zoltan@webkit.org | b4e6b15 | 2012-10-08 13:44:14 +0000 | [diff] [blame^] | 72 | // prevent ~QPixmap running after ~QApplication (leaks native pixmaps) |
hausmann@webkit.org | 71c57c7 | 2011-11-17 14:22:48 +0000 | [diff] [blame] | 73 | qAddPostRoutine(earlyClearGraphics); |
| 74 | |
| 75 | // QWebSettings::MissingImageGraphic |
zoltan@webkit.org | b4e6b15 | 2012-10-08 13:44:14 +0000 | [diff] [blame^] | 76 | hash->insert("missingImage", QPixmap(QLatin1String(":webkit/resources/missingImage.png"))); |
hausmann@webkit.org | 71c57c7 | 2011-11-17 14:22:48 +0000 | [diff] [blame] | 77 | // QWebSettings::MissingPluginGraphic |
zoltan@webkit.org | b4e6b15 | 2012-10-08 13:44:14 +0000 | [diff] [blame^] | 78 | hash->insert("nullPlugin", QPixmap(QLatin1String(":webkit/resources/nullPlugin.png"))); |
hausmann@webkit.org | 71c57c7 | 2011-11-17 14:22:48 +0000 | [diff] [blame] | 79 | // QWebSettings::DefaultFrameIconGraphic |
zoltan@webkit.org | b4e6b15 | 2012-10-08 13:44:14 +0000 | [diff] [blame^] | 80 | hash->insert("urlIcon", QPixmap(QLatin1String(":webkit/resources/urlIcon.png"))); |
hausmann@webkit.org | 71c57c7 | 2011-11-17 14:22:48 +0000 | [diff] [blame] | 81 | // QWebSettings::TextAreaSizeGripCornerGraphic |
zoltan@webkit.org | b4e6b15 | 2012-10-08 13:44:14 +0000 | [diff] [blame^] | 82 | hash->insert("textAreaResizeCorner", QPixmap(QLatin1String(":webkit/resources/textAreaResizeCorner.png"))); |
hausmann@webkit.org | 71c57c7 | 2011-11-17 14:22:48 +0000 | [diff] [blame] | 83 | // QWebSettings::DeleteButtonGraphic |
zoltan@webkit.org | b4e6b15 | 2012-10-08 13:44:14 +0000 | [diff] [blame^] | 84 | hash->insert("deleteButton", QPixmap(QLatin1String(":webkit/resources/deleteButton.png"))); |
hausmann@webkit.org | 71c57c7 | 2011-11-17 14:22:48 +0000 | [diff] [blame] | 85 | // QWebSettings::InputSpeechButtonGraphic |
zoltan@webkit.org | b4e6b15 | 2012-10-08 13:44:14 +0000 | [diff] [blame^] | 86 | hash->insert("inputSpeech", QPixmap(QLatin1String(":webkit/resources/inputSpeech.png"))); |
hausmann@webkit.org | 71c57c7 | 2011-11-17 14:22:48 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | return hash; |
| 90 | } |
| 91 | |
staikos | cdc883d | 2007-06-22 03:29:41 +0000 | [diff] [blame] | 92 | // This function loads resources into WebKit |
zoltan@webkit.org | b4e6b15 | 2012-10-08 13:44:14 +0000 | [diff] [blame^] | 93 | static QPixmap loadResourcePixmap(const char *name) |
hausmann | 15e7c0e | 2007-11-07 14:30:50 +0000 | [diff] [blame] | 94 | { |
hausmann@webkit.org | 71c57c7 | 2011-11-17 14:22:48 +0000 | [diff] [blame] | 95 | return graphics()->value(name); |
hausmann | 15e7c0e | 2007-11-07 14:30:50 +0000 | [diff] [blame] | 96 | } |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 97 | |
| 98 | namespace WebCore { |
| 99 | |
pkasting@chromium.org | a2910e1 | 2009-01-09 18:46:51 +0000 | [diff] [blame] | 100 | bool FrameData::clear(bool clearMetadata) |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 101 | { |
pkasting@chromium.org | a2910e1 | 2009-01-09 18:46:51 +0000 | [diff] [blame] | 102 | if (clearMetadata) |
| 103 | m_haveMetadata = false; |
| 104 | |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 105 | if (m_frame) { |
hausmann@webkit.org | 88b3eb3 | 2009-10-06 14:14:10 +0000 | [diff] [blame] | 106 | delete m_frame; |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 107 | m_frame = 0; |
pkasting@chromium.org | a2910e1 | 2009-01-09 18:46:51 +0000 | [diff] [blame] | 108 | return true; |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 109 | } |
pkasting@chromium.org | a2910e1 | 2009-01-09 18:46:51 +0000 | [diff] [blame] | 110 | return false; |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 111 | } |
| 112 | |
lars | f6076a4 | 2007-01-17 19:04:39 +0000 | [diff] [blame] | 113 | |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 114 | // ================================================ |
| 115 | // Image Class |
| 116 | // ================================================ |
| 117 | |
eric@webkit.org | ac3f666 | 2008-08-14 01:15:50 +0000 | [diff] [blame] | 118 | PassRefPtr<Image> Image::loadPlatformResource(const char* name) |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 119 | { |
zoltan@webkit.org | b4e6b15 | 2012-10-08 13:44:14 +0000 | [diff] [blame^] | 120 | return StillImage::create(loadResourcePixmap(name)); |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 121 | } |
| 122 | |
zoltan@webkit.org | b4e6b15 | 2012-10-08 13:44:14 +0000 | [diff] [blame^] | 123 | void Image::setPlatformResource(const char* name, const QPixmap& pixmap) |
hausmann@webkit.org | 71c57c7 | 2011-11-17 14:22:48 +0000 | [diff] [blame] | 124 | { |
| 125 | WebGraphicHash* h = graphics(); |
zoltan@webkit.org | b4e6b15 | 2012-10-08 13:44:14 +0000 | [diff] [blame^] | 126 | if (pixmap.isNull()) |
hausmann@webkit.org | 71c57c7 | 2011-11-17 14:22:48 +0000 | [diff] [blame] | 127 | h->remove(name); |
| 128 | else |
zoltan@webkit.org | b4e6b15 | 2012-10-08 13:44:14 +0000 | [diff] [blame^] | 129 | h->insert(name, pixmap); |
hausmann@webkit.org | 71c57c7 | 2011-11-17 14:22:48 +0000 | [diff] [blame] | 130 | } |
| 131 | |
krit@webkit.org | 2b95a9a | 2010-02-08 20:30:42 +0000 | [diff] [blame] | 132 | void Image::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRect, const AffineTransform& patternTransform, |
eric@webkit.org | dabc7d2 | 2009-12-17 00:41:04 +0000 | [diff] [blame] | 133 | const FloatPoint& phase, ColorSpace, CompositeOperator op, const FloatRect& destRect) |
lars | f6076a4 | 2007-01-17 19:04:39 +0000 | [diff] [blame] | 134 | { |
zoltan@webkit.org | b4e6b15 | 2012-10-08 13:44:14 +0000 | [diff] [blame^] | 135 | QPixmap* framePixmap = nativeImageForCurrentFrame(); |
| 136 | if (!framePixmap) // If it's too early we won't have an image yet. |
hausmann@webkit.org | 42009bb | 2009-02-07 15:33:19 +0000 | [diff] [blame] | 137 | return; |
| 138 | |
commit-queue@webkit.org | cbfbe55 | 2012-05-30 18:48:52 +0000 | [diff] [blame] | 139 | #if ENABLE(IMAGE_DECODER_DOWN_SAMPLING) |
| 140 | FloatRect tileRectAdjusted = adjustSourceRectForDownSampling(tileRect, framePixmap->size()); |
| 141 | #else |
| 142 | FloatRect tileRectAdjusted = tileRect; |
| 143 | #endif |
| 144 | |
benjamin.poulain@nokia.com | be697bf | 2010-11-19 21:15:43 +0000 | [diff] [blame] | 145 | // Qt interprets 0 width/height as full width/height so just short circuit. |
commit-queue@webkit.org | 6d767de | 2010-11-09 08:04:24 +0000 | [diff] [blame] | 146 | QRectF dr = QRectF(destRect).normalized(); |
commit-queue@webkit.org | cbfbe55 | 2012-05-30 18:48:52 +0000 | [diff] [blame] | 147 | QRect tr = QRectF(tileRectAdjusted).toRect().normalized(); |
benjamin.poulain@nokia.com | be697bf | 2010-11-19 21:15:43 +0000 | [diff] [blame] | 148 | if (!dr.width() || !dr.height() || !tr.width() || !tr.height()) |
commit-queue@webkit.org | 6d767de | 2010-11-09 08:04:24 +0000 | [diff] [blame] | 149 | return; |
| 150 | |
zoltan@webkit.org | b4e6b15 | 2012-10-08 13:44:14 +0000 | [diff] [blame^] | 151 | QPixmap pixmap = *framePixmap; |
| 152 | if (tr.x() || tr.y() || tr.width() != pixmap.width() || tr.height() != pixmap.height()) |
| 153 | pixmap = pixmap.copy(tr); |
hausmann@webkit.org | 42009bb | 2009-02-07 15:33:19 +0000 | [diff] [blame] | 154 | |
andreas.kling@nokia.com | a43c709 | 2010-12-14 17:49:06 +0000 | [diff] [blame] | 155 | CompositeOperator previousOperator = ctxt->compositeOperation(); |
commit-queue@webkit.org | 6d767de | 2010-11-09 08:04:24 +0000 | [diff] [blame] | 156 | |
zoltan@webkit.org | b4e6b15 | 2012-10-08 13:44:14 +0000 | [diff] [blame^] | 157 | ctxt->setCompositeOperation(!pixmap.hasAlpha() && op == CompositeSourceOver ? CompositeCopy : op); |
commit-queue@webkit.org | 6d767de | 2010-11-09 08:04:24 +0000 | [diff] [blame] | 158 | |
andreas.kling@nokia.com | bbef9f5 | 2011-01-22 01:45:14 +0000 | [diff] [blame] | 159 | QPainter* p = ctxt->platformContext(); |
commit-queue@webkit.org | 6d767de | 2010-11-09 08:04:24 +0000 | [diff] [blame] | 160 | QTransform transform(patternTransform); |
noam.rosenthal@nokia.com | 6cbc924 | 2011-01-17 08:50:11 +0000 | [diff] [blame] | 161 | |
zoltan@webkit.org | b4e6b15 | 2012-10-08 13:44:14 +0000 | [diff] [blame^] | 162 | // If this would draw more than one scaled tile, we scale the pixmap first and then use the result to draw. |
noam.rosenthal@nokia.com | 6cbc924 | 2011-01-17 08:50:11 +0000 | [diff] [blame] | 163 | if (transform.type() == QTransform::TxScale) { |
| 164 | QRectF tileRectInTargetCoords = (transform * QTransform().translate(phase.x(), phase.y())).mapRect(tr); |
| 165 | |
| 166 | bool tileWillBePaintedOnlyOnce = tileRectInTargetCoords.contains(dr); |
| 167 | if (!tileWillBePaintedOnlyOnce) { |
zoltan@webkit.org | b4e6b15 | 2012-10-08 13:44:14 +0000 | [diff] [blame^] | 168 | QSizeF scaledSize(float(pixmap.width()) * transform.m11(), float(pixmap.height()) * transform.m22()); |
| 169 | QPixmap scaledPixmap(scaledSize.toSize()); |
| 170 | if (pixmap.hasAlpha()) |
| 171 | scaledPixmap.fill(Qt::transparent); |
noam.rosenthal@nokia.com | 6cbc924 | 2011-01-17 08:50:11 +0000 | [diff] [blame] | 172 | { |
zoltan@webkit.org | b4e6b15 | 2012-10-08 13:44:14 +0000 | [diff] [blame^] | 173 | QPainter painter(&scaledPixmap); |
noam.rosenthal@nokia.com | 6cbc924 | 2011-01-17 08:50:11 +0000 | [diff] [blame] | 174 | painter.setCompositionMode(QPainter::CompositionMode_Source); |
| 175 | painter.setRenderHints(p->renderHints()); |
zoltan@webkit.org | b4e6b15 | 2012-10-08 13:44:14 +0000 | [diff] [blame^] | 176 | painter.drawPixmap(QRect(0, 0, scaledPixmap.width(), scaledPixmap.height()), pixmap); |
noam.rosenthal@nokia.com | 6cbc924 | 2011-01-17 08:50:11 +0000 | [diff] [blame] | 177 | } |
zoltan@webkit.org | b4e6b15 | 2012-10-08 13:44:14 +0000 | [diff] [blame^] | 178 | pixmap = scaledPixmap; |
noam.rosenthal@nokia.com | 6cbc924 | 2011-01-17 08:50:11 +0000 | [diff] [blame] | 179 | transform = QTransform::fromTranslate(transform.dx(), transform.dy()); |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | /* Translate the coordinates as phase is not in world matrix coordinate space but the tile rect origin is. */ |
commit-queue@webkit.org | 6d767de | 2010-11-09 08:04:24 +0000 | [diff] [blame] | 184 | transform *= QTransform().translate(phase.x(), phase.y()); |
| 185 | transform.translate(tr.x(), tr.y()); |
| 186 | |
zoltan@webkit.org | b4e6b15 | 2012-10-08 13:44:14 +0000 | [diff] [blame^] | 187 | QBrush b(pixmap); |
commit-queue@webkit.org | 6d767de | 2010-11-09 08:04:24 +0000 | [diff] [blame] | 188 | b.setTransform(transform); |
| 189 | p->fillRect(dr, b); |
| 190 | |
andreas.kling@nokia.com | a43c709 | 2010-12-14 17:49:06 +0000 | [diff] [blame] | 191 | ctxt->setCompositeOperation(previousOperator); |
hausmann@webkit.org | 60de1ee | 2009-05-20 08:22:23 +0000 | [diff] [blame] | 192 | |
| 193 | if (imageObserver()) |
| 194 | imageObserver()->didDraw(this); |
lars | f6076a4 | 2007-01-17 19:04:39 +0000 | [diff] [blame] | 195 | } |
| 196 | |
zoltan@webkit.org | b4e6b15 | 2012-10-08 13:44:14 +0000 | [diff] [blame^] | 197 | BitmapImage::BitmapImage(QPixmap* pixmap, ImageObserver* observer) |
eric@webkit.org | 1e2dd43 | 2009-11-02 18:17:18 +0000 | [diff] [blame] | 198 | : Image(observer) |
| 199 | , m_currentFrame(0) |
| 200 | , m_frames(0) |
| 201 | , m_frameTimer(0) |
| 202 | , m_repetitionCount(cAnimationNone) |
| 203 | , m_repetitionCountStatus(Unknown) |
| 204 | , m_repetitionsComplete(0) |
commit-queue@webkit.org | 191451a | 2011-12-09 01:31:12 +0000 | [diff] [blame] | 205 | , m_decodedSize(0) |
| 206 | , m_frameCount(1) |
eric@webkit.org | 1e2dd43 | 2009-11-02 18:17:18 +0000 | [diff] [blame] | 207 | , m_isSolidColor(false) |
| 208 | , m_checkedForSolidColor(false) |
| 209 | , m_animationFinished(true) |
| 210 | , m_allDataReceived(true) |
| 211 | , m_haveSize(true) |
| 212 | , m_sizeAvailable(true) |
eric@webkit.org | 1e2dd43 | 2009-11-02 18:17:18 +0000 | [diff] [blame] | 213 | , m_haveFrameCount(true) |
eric@webkit.org | 1e2dd43 | 2009-11-02 18:17:18 +0000 | [diff] [blame] | 214 | { |
zoltan@webkit.org | b4e6b15 | 2012-10-08 13:44:14 +0000 | [diff] [blame^] | 215 | int width = pixmap->width(); |
| 216 | int height = pixmap->height(); |
eric@webkit.org | 1e2dd43 | 2009-11-02 18:17:18 +0000 | [diff] [blame] | 217 | m_decodedSize = width * height * 4; |
| 218 | m_size = IntSize(width, height); |
| 219 | |
| 220 | m_frames.grow(1); |
zoltan@webkit.org | b4e6b15 | 2012-10-08 13:44:14 +0000 | [diff] [blame^] | 221 | m_frames[0].m_frame = pixmap; |
| 222 | m_frames[0].m_hasAlpha = pixmap->hasAlpha(); |
eric@webkit.org | 1e2dd43 | 2009-11-02 18:17:18 +0000 | [diff] [blame] | 223 | m_frames[0].m_haveMetadata = true; |
| 224 | checkForSolidColor(); |
| 225 | } |
| 226 | |
lars | f6076a4 | 2007-01-17 19:04:39 +0000 | [diff] [blame] | 227 | void BitmapImage::invalidatePlatformData() |
| 228 | { |
| 229 | } |
kenneth@webkit.org | f86e4e1 | 2009-07-21 12:02:38 +0000 | [diff] [blame] | 230 | |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 231 | // Drawing Routines |
eseidel | 6195285 | 2006-12-29 01:57:44 +0000 | [diff] [blame] | 232 | void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dst, |
bdakin@apple.com | 62711a6 | 2009-11-19 23:36:58 +0000 | [diff] [blame] | 233 | const FloatRect& src, ColorSpace styleColorSpace, CompositeOperator op) |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 234 | { |
commit-queue@webkit.org | 580b2cb | 2010-11-23 08:00:30 +0000 | [diff] [blame] | 235 | QRectF normalizedDst = dst.normalized(); |
| 236 | QRectF normalizedSrc = src.normalized(); |
commit-queue@webkit.org | 70777c8 | 2010-07-02 18:47:54 +0000 | [diff] [blame] | 237 | |
pkasting@chromium.org | e8a5a6b | 2008-10-15 20:38:13 +0000 | [diff] [blame] | 238 | startAnimation(); |
| 239 | |
benjamin.poulain@nokia.com | 194e50b | 2010-11-19 17:34:14 +0000 | [diff] [blame] | 240 | if (normalizedSrc.isEmpty() || normalizedDst.isEmpty()) |
| 241 | return; |
| 242 | |
zoltan@webkit.org | b4e6b15 | 2012-10-08 13:44:14 +0000 | [diff] [blame^] | 243 | QPixmap* image = nativeImageForCurrentFrame(); |
lars | f6076a4 | 2007-01-17 19:04:39 +0000 | [diff] [blame] | 244 | if (!image) |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 245 | return; |
kenneth@webkit.org | f86e4e1 | 2009-07-21 12:02:38 +0000 | [diff] [blame] | 246 | |
lars | f6076a4 | 2007-01-17 19:04:39 +0000 | [diff] [blame] | 247 | if (mayFillWithSolidColor()) { |
commit-queue@webkit.org | 70777c8 | 2010-07-02 18:47:54 +0000 | [diff] [blame] | 248 | fillWithSolidColor(ctxt, normalizedDst, solidColor(), styleColorSpace, op); |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 249 | return; |
lars | f6076a4 | 2007-01-17 19:04:39 +0000 | [diff] [blame] | 250 | } |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 251 | |
commit-queue@webkit.org | cbfbe55 | 2012-05-30 18:48:52 +0000 | [diff] [blame] | 252 | #if ENABLE(IMAGE_DECODER_DOWN_SAMPLING) |
| 253 | normalizedSrc = adjustSourceRectForDownSampling(normalizedSrc, image->size()); |
| 254 | #endif |
| 255 | |
andreas.kling@nokia.com | bbef9f5 | 2011-01-22 01:45:14 +0000 | [diff] [blame] | 256 | CompositeOperator previousOperator = ctxt->compositeOperation(); |
zoltan@webkit.org | b4e6b15 | 2012-10-08 13:44:14 +0000 | [diff] [blame^] | 257 | ctxt->setCompositeOperation(!image->hasAlpha() && op == CompositeSourceOver ? CompositeCopy : op); |
treat@webkit.org | 66c012f | 2009-02-27 20:47:04 +0000 | [diff] [blame] | 258 | |
commit-queue@webkit.org | d1e03a7 | 2011-07-05 21:29:42 +0000 | [diff] [blame] | 259 | if (ctxt->hasShadow()) { |
| 260 | ShadowBlur* shadow = ctxt->shadowBlur(); |
| 261 | GraphicsContext* shadowContext = shadow->beginShadowLayer(ctxt, normalizedDst); |
| 262 | if (shadowContext) { |
| 263 | QPainter* shadowPainter = shadowContext->platformContext(); |
zoltan@webkit.org | b4e6b15 | 2012-10-08 13:44:14 +0000 | [diff] [blame^] | 264 | shadowPainter->drawPixmap(normalizedDst, *image, normalizedSrc); |
commit-queue@webkit.org | 6a1fb1a | 2011-01-04 00:21:05 +0000 | [diff] [blame] | 265 | shadow->endShadowLayer(ctxt); |
commit-queue@webkit.org | 580b2cb | 2010-11-23 08:00:30 +0000 | [diff] [blame] | 266 | } |
eric@webkit.org | fabc550 | 2010-06-02 08:30:39 +0000 | [diff] [blame] | 267 | } |
| 268 | |
zoltan@webkit.org | b4e6b15 | 2012-10-08 13:44:14 +0000 | [diff] [blame^] | 269 | ctxt->platformContext()->drawPixmap(normalizedDst, *image, normalizedSrc); |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 270 | |
andreas.kling@nokia.com | bbef9f5 | 2011-01-22 01:45:14 +0000 | [diff] [blame] | 271 | ctxt->setCompositeOperation(previousOperator); |
hausmann@webkit.org | 60de1ee | 2009-05-20 08:22:23 +0000 | [diff] [blame] | 272 | |
| 273 | if (imageObserver()) |
| 274 | imageObserver()->didDraw(this); |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 275 | } |
| 276 | |
eseidel | 6195285 | 2006-12-29 01:57:44 +0000 | [diff] [blame] | 277 | void BitmapImage::checkForSolidColor() |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 278 | { |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 279 | m_isSolidColor = false; |
treat@webkit.org | f793b27 | 2009-03-02 15:37:02 +0000 | [diff] [blame] | 280 | m_checkedForSolidColor = true; |
| 281 | |
| 282 | if (frameCount() > 1) |
| 283 | return; |
| 284 | |
zoltan@webkit.org | b4e6b15 | 2012-10-08 13:44:14 +0000 | [diff] [blame^] | 285 | QPixmap* framePixmap = frameAtIndex(0); |
| 286 | if (!framePixmap || framePixmap->width() != 1 || framePixmap->height() != 1) |
treat@webkit.org | f793b27 | 2009-03-02 15:37:02 +0000 | [diff] [blame] | 287 | return; |
| 288 | |
| 289 | m_isSolidColor = true; |
zoltan@webkit.org | b4e6b15 | 2012-10-08 13:44:14 +0000 | [diff] [blame^] | 290 | m_solidColor = QColor::fromRgba(framePixmap->toImage().pixel(0, 0)); |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 291 | } |
| 292 | |
mjs@apple.com | acbcc28 | 2010-01-05 08:58:28 +0000 | [diff] [blame] | 293 | #if OS(WINDOWS) |
eric@webkit.org | 1e2dd43 | 2009-11-02 18:17:18 +0000 | [diff] [blame] | 294 | PassRefPtr<BitmapImage> BitmapImage::create(HBITMAP hBitmap) |
| 295 | { |
zoltan@webkit.org | b4e6b15 | 2012-10-08 13:44:14 +0000 | [diff] [blame^] | 296 | QPixmap* qPixmap = new QPixmap(qt_pixmapFromWinHBITMAP(hBitmap)); |
kbalazs@webkit.org | 4b6f855 | 2012-06-10 12:09:37 +0000 | [diff] [blame] | 297 | |
zoltan@webkit.org | b4e6b15 | 2012-10-08 13:44:14 +0000 | [diff] [blame^] | 298 | return BitmapImage::create(qPixmap); |
eric@webkit.org | 1e2dd43 | 2009-11-02 18:17:18 +0000 | [diff] [blame] | 299 | } |
| 300 | #endif |
| 301 | |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 302 | } |
| 303 | |
eseidel | 6195285 | 2006-12-29 01:57:44 +0000 | [diff] [blame] | 304 | |
rwlbuis | 9802198 | 2006-08-23 21:04:08 +0000 | [diff] [blame] | 305 | // vim: ts=4 sw=4 et |