1 | /* |
2 | * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies) |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #include "config.h" |
27 | #include "Tile.h" |
28 | |
29 | #if USE(COORDINATED_GRAPHICS) |
30 | |
31 | #include "SurfaceUpdateInfo.h" |
32 | #include "TiledBackingStore.h" |
33 | #include "TiledBackingStoreClient.h" |
34 | |
35 | namespace WebCore { |
36 | |
37 | static const uint32_t InvalidTileID = 0; |
38 | |
39 | Tile::Tile(TiledBackingStore& tiledBackingStore, const Coordinate& tileCoordinate) |
40 | : m_tiledBackingStore(tiledBackingStore) |
41 | , m_ID(InvalidTileID) |
42 | , m_coordinate(tileCoordinate) |
43 | , m_rect(tiledBackingStore.tileRectForCoordinate(tileCoordinate)) |
44 | , m_dirtyRect(m_rect) |
45 | { |
46 | } |
47 | |
48 | Tile::~Tile() |
49 | { |
50 | if (m_ID != InvalidTileID) |
51 | m_tiledBackingStore.client().removeTile(m_ID); |
52 | } |
53 | |
54 | void Tile::ensureTileID() |
55 | { |
56 | static uint32_t id = 1; |
57 | if (m_ID == InvalidTileID) { |
58 | m_ID = id++; |
59 | // We may get an invalid ID due to wrap-around on overflow. |
60 | if (m_ID == InvalidTileID) |
61 | m_ID = id++; |
62 | m_tiledBackingStore.client().createTile(m_ID, m_tiledBackingStore.contentsScale()); |
63 | } |
64 | } |
65 | |
66 | bool Tile::isDirty() const |
67 | { |
68 | return !m_dirtyRect.isEmpty(); |
69 | } |
70 | |
71 | bool Tile::isReadyToPaint() const |
72 | { |
73 | return m_ID != InvalidTileID; |
74 | } |
75 | |
76 | void Tile::invalidate(const IntRect& dirtyRect) |
77 | { |
78 | IntRect tileDirtyRect = intersection(dirtyRect, m_rect); |
79 | if (!tileDirtyRect.isEmpty()) |
80 | m_dirtyRect.unite(tileDirtyRect); |
81 | } |
82 | |
83 | void Tile::markClean() |
84 | { |
85 | m_dirtyRect = { }; |
86 | } |
87 | |
88 | void Tile::resize(const IntSize& newSize) |
89 | { |
90 | m_rect = IntRect(m_rect.location(), newSize); |
91 | m_dirtyRect = m_rect; |
92 | } |
93 | |
94 | } // namespace WebCore |
95 | |
96 | #endif // USE(COORDINATED_GRAPHICS) |
97 | |