1 | /* |
2 | * Copyright (C) 2018 Metrological Group B.V. |
3 | * Copyright (C) 2018 Igalia S.L. |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
8 | * |
9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * 2. Redistributions in binary form must reproduce the above |
12 | * copyright notice, this list of conditions and the following |
13 | * disclaimer in the documentation and/or other materials provided |
14 | * with the distribution. |
15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 | * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
28 | |
29 | #include "config.h" |
30 | #include "NicosiaBackingStoreTextureMapperImpl.h" |
31 | |
32 | #if USE(TEXTURE_MAPPER) |
33 | |
34 | namespace Nicosia { |
35 | |
36 | auto BackingStoreTextureMapperImpl::createFactory() -> Factory |
37 | { |
38 | return Factory( |
39 | [](BackingStore&) { |
40 | return std::make_unique<BackingStoreTextureMapperImpl>(); |
41 | }); |
42 | } |
43 | |
44 | BackingStoreTextureMapperImpl::BackingStoreTextureMapperImpl() = default; |
45 | BackingStoreTextureMapperImpl::~BackingStoreTextureMapperImpl() = default; |
46 | |
47 | void BackingStoreTextureMapperImpl::tiledBackingStoreHasPendingTileCreation() |
48 | { |
49 | m_layerState.hasPendingTileCreation = true; |
50 | } |
51 | |
52 | void BackingStoreTextureMapperImpl::createTile(uint32_t tileID, float scale) |
53 | { |
54 | ASSERT(m_layerState.isFlushing); |
55 | auto& update = m_layerState.update; |
56 | |
57 | // Assert no tile with this ID has been registered yet. |
58 | #if !ASSERT_DISABLED |
59 | auto matchesTile = [tileID](auto& tile) { return tile.tileID == tileID; }; |
60 | #endif |
61 | ASSERT(std::none_of(update.tilesToCreate.begin(), update.tilesToCreate.end(), matchesTile)); |
62 | ASSERT(std::none_of(update.tilesToUpdate.begin(), update.tilesToUpdate.end(), matchesTile)); |
63 | ASSERT(std::none_of(update.tilesToRemove.begin(), update.tilesToRemove.end(), matchesTile)); |
64 | |
65 | update.tilesToCreate.append({ tileID, scale }); |
66 | } |
67 | |
68 | void BackingStoreTextureMapperImpl::updateTile(uint32_t tileID, const WebCore::SurfaceUpdateInfo& updateInfo, const WebCore::IntRect& tileRect) |
69 | { |
70 | ASSERT(m_layerState.isFlushing); |
71 | auto& update = m_layerState.update; |
72 | |
73 | // Assert no tile with this ID has been registered for removal yet. It might have |
74 | // already been created in a previous update, so it makes no sense to check tilesToCreate. |
75 | ASSERT(std::none_of(update.tilesToRemove.begin(), update.tilesToRemove.end(), |
76 | [tileID](auto& tile) { return tile.tileID == tileID; })); |
77 | |
78 | update.tilesToUpdate.append({ tileID, tileRect, updateInfo }); |
79 | } |
80 | |
81 | void BackingStoreTextureMapperImpl::removeTile(uint32_t tileID) |
82 | { |
83 | ASSERT(m_layerState.isFlushing || m_layerState.isPurging); |
84 | auto& update = m_layerState.update; |
85 | |
86 | // Remove any creations or updates registered for this tile ID. |
87 | auto matchesTile = [tileID](auto& tile) { return tile.tileID == tileID; }; |
88 | update.tilesToCreate.removeAllMatching(matchesTile); |
89 | update.tilesToUpdate.removeAllMatching(matchesTile); |
90 | |
91 | // Assert no tile with this ID has been registered for removal yet. |
92 | ASSERT(std::none_of(update.tilesToRemove.begin(), update.tilesToRemove.end(), matchesTile)); |
93 | |
94 | update.tilesToRemove.append(TileUpdate::RemovalData { tileID }); |
95 | } |
96 | |
97 | void BackingStoreTextureMapperImpl::flushUpdate() |
98 | { |
99 | ASSERT(!m_layerState.isFlushing); |
100 | m_layerState.hasPendingTileCreation = false; |
101 | |
102 | // Incrementally store updates as they are being flushed from the layer-side. |
103 | { |
104 | LockHolder locker(m_update.lock); |
105 | m_update.pending.tilesToCreate.appendVector(m_layerState.update.tilesToCreate); |
106 | m_update.pending.tilesToUpdate.appendVector(m_layerState.update.tilesToUpdate); |
107 | m_update.pending.tilesToRemove.appendVector(m_layerState.update.tilesToRemove); |
108 | } |
109 | |
110 | m_layerState.update = { }; |
111 | } |
112 | |
113 | auto BackingStoreTextureMapperImpl::takeUpdate() -> TileUpdate |
114 | { |
115 | LockHolder locker(m_update.lock); |
116 | return WTFMove(m_update.pending); |
117 | } |
118 | |
119 | } // namespace Nicosia |
120 | |
121 | #endif // USE(TEXTURE_MAPPER) |
122 | |