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 | #pragma once |
30 | |
31 | #if USE(TEXTURE_MAPPER) |
32 | |
33 | #include "CoordinatedBackingStore.h" |
34 | #include "NicosiaPlatformLayer.h" |
35 | #include "SurfaceUpdateInfo.h" |
36 | #include "TiledBackingStore.h" |
37 | #include "TiledBackingStoreClient.h" |
38 | #include <memory> |
39 | #include <wtf/Lock.h> |
40 | |
41 | namespace Nicosia { |
42 | |
43 | class BackingStoreTextureMapperImpl final : public BackingStore::Impl, public WebCore::TiledBackingStoreClient { |
44 | public: |
45 | static Factory createFactory(); |
46 | |
47 | BackingStoreTextureMapperImpl(); |
48 | virtual ~BackingStoreTextureMapperImpl(); |
49 | bool isTextureMapperImpl() const override { return true; } |
50 | |
51 | // A move-only tile update container. |
52 | struct TileUpdate { |
53 | TileUpdate() = default; |
54 | TileUpdate(const TileUpdate&) = delete; |
55 | TileUpdate& operator=(const TileUpdate&) = delete; |
56 | TileUpdate(TileUpdate&&) = default; |
57 | TileUpdate& operator=(TileUpdate&&) = default; |
58 | |
59 | struct CreationData { |
60 | uint32_t tileID; |
61 | float scale; |
62 | }; |
63 | Vector<CreationData> tilesToCreate; |
64 | |
65 | struct UpdateData { |
66 | uint32_t tileID; |
67 | WebCore::IntRect tileRect; |
68 | WebCore::SurfaceUpdateInfo updateInfo; |
69 | }; |
70 | Vector<UpdateData> tilesToUpdate; |
71 | |
72 | struct RemovalData { |
73 | uint32_t tileID; |
74 | }; |
75 | Vector<RemovalData> tilesToRemove; |
76 | }; |
77 | |
78 | // An immutable layer-side state object. flushUpdate() prepares |
79 | // the current update for consumption by the composition-side. |
80 | struct LayerState { |
81 | LayerState() = default; |
82 | LayerState(const LayerState&) = delete; |
83 | LayerState& operator=(const LayerState&) = delete; |
84 | LayerState(LayerState&&) = delete; |
85 | LayerState& operator=(LayerState&&) = delete; |
86 | |
87 | std::unique_ptr<WebCore::TiledBackingStore> mainBackingStore; |
88 | |
89 | TileUpdate update; |
90 | bool isFlushing { false }; |
91 | bool isPurging { false }; |
92 | bool hasPendingTileCreation { false }; |
93 | }; |
94 | LayerState& layerState() { return m_layerState; } |
95 | |
96 | void flushUpdate(); |
97 | |
98 | // An immutable composition-side state object. takeUpdate() returns the accumulated |
99 | // tile update information that's to be fed to the CoordinatedBackingStore object. |
100 | struct CompositionState { |
101 | CompositionState() = default; |
102 | CompositionState(const CompositionState&) = delete; |
103 | CompositionState& operator=(const CompositionState&) = delete; |
104 | CompositionState(CompositionState&&) = delete; |
105 | CompositionState& operator=(CompositionState&&) = delete; |
106 | |
107 | RefPtr<WebCore::CoordinatedBackingStore> backingStore; |
108 | }; |
109 | CompositionState& compositionState() { return m_compositionState; } |
110 | |
111 | TileUpdate takeUpdate(); |
112 | |
113 | // TiledBackingStoreClient |
114 | // FIXME: Move these to private once updateTile() is not called from CoordinatedGrahpicsLayer. |
115 | void tiledBackingStoreHasPendingTileCreation() override; |
116 | void createTile(uint32_t, float) override; |
117 | void updateTile(uint32_t, const WebCore::SurfaceUpdateInfo&, const WebCore::IntRect&) override; |
118 | void removeTile(uint32_t) override; |
119 | |
120 | private: |
121 | LayerState m_layerState; |
122 | CompositionState m_compositionState; |
123 | |
124 | struct { |
125 | Lock lock; |
126 | TileUpdate pending; |
127 | } m_update; |
128 | }; |
129 | |
130 | } // namespace Nicosia |
131 | |
132 | SPECIALIZE_TYPE_TRAITS_NICOSIA_BACKINGSTORE_IMPL(BackingStoreTextureMapperImpl, isTextureMapperImpl()); |
133 | |
134 | #endif // USE(TEXTURE_MAPPER) |
135 | |