File: pixmapplane.cpp

package info (click to toggle)
khtml 5.78.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 19,012 kB
  • sloc: cpp: 206,167; java: 4,060; ansic: 2,829; perl: 2,317; yacc: 1,497; python: 339; sh: 116; xml: 37; makefile: 7
file content (146 lines) | stat: -rw-r--r-- 4,658 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
    Large image displaying library.

    Copyright (C) 2004,2005 Maks Orlovich (maksim@kde.org)

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
    AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
    AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
    CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

*/

#include "pixmapplane.h"

#include <QPainter>

namespace khtmlImLoad
{

void PixmapPlane::paint(int dx, int dy, QPainter *p,
                        int sx, int sy, int sWidth, int sHeight)
{
    //Do some basic clipping, discarding invalid requests and adjusting sizes of others.
    if (sy >= (int)height) {
        return;
    }
    if (sx >= (int)width) {
        return;
    }

    if (sWidth == -1) {
        sWidth = width;
    }

    if (sHeight == -1) {
        sHeight = height;
    }

    unsigned int ey = sy + sHeight - 1;
    if (ey > height - 1) {
        ey = height - 1;
    }

    unsigned int ex = sx + sWidth - 1;
    if (ex > width - 1) {
        ex = width - 1;
    }

    sHeight = ey - sy + 1;
    sWidth  = ex - sx + 1;

    //Calculate the range of tiles to paint, in both directions
    unsigned int startTileY = sy / Tile::TileSize;
    unsigned int endTileY   = ey / Tile::TileSize;

    unsigned int startTileX = sx / Tile::TileSize;
    unsigned int endTileX   = ex / Tile::TileSize;

    //Walk through all the rows
    unsigned int paintY = dy;
    for (unsigned int tileY = startTileY; tileY <= endTileY; ++tileY) {
        //see how much we have to paint -- end points are different
        unsigned int startY = 0;
        unsigned int endY   = Tile::TileSize - 1;

        if (tileY == startTileY) {
            startY = sy % Tile::TileSize;
        }

        if (tileY == endTileY) {
            endY   = ey % Tile::TileSize;
        }

        unsigned int paintHeight = endY - startY + 1;

        //Now through some columns
        unsigned int paintX = dx;
        for (unsigned int tileX = startTileX; tileX <= endTileX; ++tileX) {
            //calculate the horizontal size. Some redundancy here,
            //since these are the same for all rows, but I'd rather
            //avoid heap allocation or alloca..
            unsigned int startX = 0;
            unsigned int endX   = Tile::TileSize - 1;

            if (tileX == startTileX) {
                startX = sx % Tile::TileSize;
            }

            if (tileX == endTileX) {
                endX   = ex % Tile::TileSize;
            }

            int paintWidth = endX - startX + 1;

            //Update from image plane if need be
            PixmapTile &tile = tiles.at(tileX, tileY);
            if (!parent->isUpToDate(tileX, tileY, &tile)) {
                parent->ensureUpToDate(tileX, tileY, &tile);
            }

            //Draw as much as we have
            if (tile.pixmap) {
                //Scan the versions to see how much to paint.
                unsigned int h = 0;
                for (int checkY = startY; checkY < Tile::TileSize && tile.versions[checkY]; ++checkY) {
                    ++h;
                }

                //Draw it, if there is anything (note: Qt would interpret 0 as everything)
                if (h)
                    p->drawPixmap(paintX, paintY, *tile.pixmap, startX, startY,
                                  paintWidth, qMin(h, paintHeight));
            }
            paintX += paintWidth;
        }
        paintY += paintHeight;
    }
}

void PixmapPlane::flushCache()
{
    parent->flushCache();
    for (unsigned tileX = 0; tileX < tilesWidth; ++tileX) {
        for (unsigned tileY = 0; tileY < tilesHeight; ++tileY) {
            PixmapTile &pixTile = tiles.at(tileX, tileY);
            if (pixTile.pixmap) {
                ImageManager::pixmapCache()->removeEntry(&pixTile);
            }
        }
    }
}

}