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 "NicosiaBuffer.h"
35#include "NicosiaPlatformLayer.h"
36#include <wtf/Lock.h>
37
38namespace WebCore {
39class Image;
40}
41
42namespace Nicosia {
43
44class ImageBackingTextureMapperImpl final : public ImageBacking::Impl {
45public:
46 static Factory createFactory();
47
48 ImageBackingTextureMapperImpl();
49 virtual ~ImageBackingTextureMapperImpl();
50 bool isTextureMapperImpl() const override { return true; }
51
52 // A move-only update container.
53 struct Update {
54 Update() = default;
55 Update(const Update&) = delete;
56 Update& operator=(const Update&) = delete;
57 Update(Update&&) = default;
58 Update& operator=(Update&&) = default;
59
60 bool isVisible { false };
61 RefPtr<Nicosia::Buffer> buffer;
62 };
63
64 // An immutable layer-side state object. flushUpdate() prepares
65 // the current update for consumption by the composition-side.
66 struct LayerState {
67 LayerState() = default;
68 LayerState(const LayerState&) = delete;
69 LayerState& operator=(const LayerState&) = delete;
70 LayerState(LayerState&&) = delete;
71 LayerState& operator=(LayerState&&) = delete;
72
73 uintptr_t imageID { 0 };
74 uintptr_t nativeImageID { 0 };
75 Update update;
76 };
77 LayerState& layerState() { return m_layerState; }
78
79 void flushUpdate();
80
81 // An immutable composition-side state object. takeUpdate() returns the update
82 // information that's to be fed to the CoordinatedBackingStore object.
83 struct CompositionState {
84 CompositionState() = default;
85 CompositionState(const CompositionState&) = delete;
86 CompositionState& operator=(const CompositionState&) = delete;
87 CompositionState(CompositionState&&) = delete;
88 CompositionState& operator=(CompositionState&&) = delete;
89
90 RefPtr<WebCore::CoordinatedBackingStore> backingStore;
91 };
92 CompositionState& compositionState() { return m_compositionState; }
93
94 Update takeUpdate();
95
96private:
97 LayerState m_layerState;
98 CompositionState m_compositionState;
99
100 struct {
101 Lock lock;
102 Update update;
103 } m_update;
104};
105
106} // namespace Nicosia
107
108SPECIALIZE_TYPE_TRAITS_NICOSIA_IMAGEBACKING_IMPL(ImageBackingTextureMapperImpl, isTextureMapperImpl());
109
110#endif // USE(TEXTURE_MAPPER)
111