2
Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License as published by the Free Software Foundation; either
7
version 2 of the License, or (at your option) any later version.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Library General Public License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to
16
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
Boston, MA 02110-1301, USA.
23
#if USE(TILED_BACKING_STORE)
25
#include "GraphicsContext.h"
26
#include "TiledBackingStore.h"
27
#include "TiledBackingStoreClient.h"
34
static const unsigned checkerSize = 16;
35
static const unsigned checkerColor1 = 0xff555555;
36
static const unsigned checkerColor2 = 0xffaaaaaa;
38
static QPixmap& checkeredPixmap()
40
static QPixmap* pixmap;
42
pixmap = new QPixmap(checkerSize, checkerSize);
43
QPainter painter(pixmap);
44
QColor color1(checkerColor1);
45
QColor color2(checkerColor2);
46
for (unsigned y = 0; y < checkerSize; y += checkerSize / 2) {
47
bool alternate = y % checkerSize;
48
for (unsigned x = 0; x < checkerSize; x += checkerSize / 2) {
49
painter.fillRect(x, y, checkerSize / 2, checkerSize / 2, alternate ? color1 : color2);
50
alternate = !alternate;
57
TileQt::TileQt(TiledBackingStore* backingStore, const Coordinate& tileCoordinate)
58
: m_backingStore(backingStore)
59
, m_coordinate(tileCoordinate)
60
, m_rect(m_backingStore->tileRectForCoordinate(tileCoordinate))
63
, m_dirtyRegion(new QRegion(m_rect))
74
bool TileQt::isDirty() const
76
return !m_dirtyRegion->isEmpty();
79
bool TileQt::isReadyToPaint() const
84
void TileQt::invalidate(const IntRect& dirtyRect)
86
IntRect tileDirtyRect = intersection(dirtyRect, m_rect);
87
if (tileDirtyRect.isEmpty())
90
*m_dirtyRegion += tileDirtyRect;
93
Vector<IntRect> TileQt::updateBackBuffer()
95
if (m_buffer && !isDirty())
96
return Vector<IntRect>();
100
m_backBuffer = new QPixmap(m_backingStore->tileSize().width(), m_backingStore->tileSize().height());
101
m_backBuffer->fill(m_backingStore->client()->tiledBackingStoreBackgroundColor());
103
// Currently all buffers are updated synchronously at the same time so there is no real need
104
// to have separate back and front buffers. Just use the existing buffer.
105
m_backBuffer = m_buffer;
110
QVector<QRect> dirtyRects = m_dirtyRegion->rects();
111
*m_dirtyRegion = QRegion();
113
QPainter painter(m_backBuffer);
114
GraphicsContext context(&painter);
115
context.translate(-m_rect.x(), -m_rect.y());
117
Vector<IntRect> updatedRects;
118
int size = dirtyRects.size();
119
for (int n = 0; n < size; ++n) {
121
IntRect rect = dirtyRects[n];
122
updatedRects.append(rect);
123
context.clip(FloatRect(rect));
124
context.scale(FloatSize(m_backingStore->contentsScale(), m_backingStore->contentsScale()));
125
m_backingStore->client()->tiledBackingStorePaint(&context, m_backingStore->mapToContents(rect));
132
void TileQt::swapBackBufferToFront()
137
m_buffer = m_backBuffer;
141
void TileQt::paint(GraphicsContext* context, const IntRect& rect)
146
IntRect target = intersection(rect, m_rect);
147
IntRect source((target.x() - m_rect.x()),
148
(target.y() - m_rect.y()),
152
context->platformContext()->drawPixmap(target, *m_buffer, source);
155
void TileQt::resize(const IntSize& newSize)
157
IntRect oldRect = m_rect;
158
m_rect = IntRect(m_rect.location(), newSize);
159
if (m_rect.maxX() > oldRect.maxX())
160
invalidate(IntRect(oldRect.maxX(), oldRect.y(), m_rect.maxX() - oldRect.maxX(), m_rect.height()));
161
if (m_rect.maxY() > oldRect.maxY())
162
invalidate(IntRect(oldRect.x(), oldRect.maxY(), m_rect.width(), m_rect.maxY() - oldRect.maxY()));
165
void TiledBackingStoreBackend::paintCheckerPattern(GraphicsContext* context, const FloatRect& target)
167
QPainter* painter = context->platformContext();
168
QTransform worldTransform = painter->worldTransform();
169
qreal scaleX = worldTransform.m11();
170
qreal scaleY = worldTransform.m22();
172
QRect targetViewRect = QRectF(target.x() * scaleX,
174
target.width() * scaleX,
175
target.height() * scaleY).toAlignedRect();
177
QTransform adjustedTransform(1., worldTransform.m12(), worldTransform.m13(),
178
worldTransform.m21(), 1., worldTransform.m23(),
179
worldTransform.m31(), worldTransform.m32(), worldTransform.m33());
180
painter->setWorldTransform(adjustedTransform);
182
painter->drawTiledPixmap(targetViewRect,
184
QPoint(targetViewRect.left() % checkerSize,
185
targetViewRect.top() % checkerSize));
187
painter->setWorldTransform(worldTransform);
190
PassRefPtr<Tile> TiledBackingStoreBackend::createTile(TiledBackingStore* backingStore, const Tile::Coordinate& tileCoordinate)
192
return TileQt::create(backingStore, tileCoordinate);