2 * Copyright (C) 2016 Igalia S.L.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "WebPageProxy.h"
31 #include <WebCore/RefPtrCairo.h>
32 #include <WebCore/WlUniquePtr.h>
33 #include <wtf/HashMap.h>
34 #include <wtf/NeverDestroyed.h>
35 #include <wtf/Noncopyable.h>
36 #include <wtf/WeakPtr.h>
37 #include <wtf/glib/GRefPtr.h>
38 #include <wtf/text/WTFString.h>
40 typedef void *EGLImageKHR;
50 class WaylandCompositor {
51 WTF_MAKE_NONCOPYABLE(WaylandCompositor);
52 friend class NeverDestroyed<WaylandCompositor>;
54 static WaylandCompositor& singleton();
57 WTF_MAKE_NONCOPYABLE(Buffer); WTF_MAKE_FAST_ALLOCATED;
59 static Buffer* getOrCreate(struct wl_resource*);
65 EGLImageKHR createImage() const;
66 WebCore::IntSize size() const;
68 WeakPtr<Buffer> createWeakPtr() { return m_weakPtrFactory.createWeakPtr(); }
71 Buffer(struct wl_resource*);
72 static void destroyListenerCallback(struct wl_listener*, void*);
74 struct wl_resource* m_resource { nullptr };
75 struct wl_listener m_destroyListener;
76 uint32_t m_busyCount { 0 };
77 WeakPtrFactory<Buffer> m_weakPtrFactory;
81 WTF_MAKE_NONCOPYABLE(Surface); WTF_MAKE_FAST_ALLOCATED;
86 void attachBuffer(struct wl_resource*);
87 void requestFrame(struct wl_resource*);
90 void setWebPage(WebPageProxy* webPage) { m_webPage = webPage; }
91 bool prepareTextureForPainting(unsigned&, WebCore::IntSize&);
94 void makePendingBufferCurrent();
96 WeakPtr<Buffer> m_buffer;
97 WeakPtr<Buffer> m_pendingBuffer;
100 Vector<wl_resource*> m_frameCallbackList;
101 WebPageProxy* m_webPage { nullptr };
104 bool isRunning() const { return !!m_display; }
105 String displayName() const { return m_displayName; }
107 void bindSurfaceToWebPage(Surface*, uint64_t pageID);
108 void registerWebPage(WebPageProxy&);
109 void unregisterWebPage(WebPageProxy&);
111 bool getTexture(WebPageProxy&, unsigned&, WebCore::IntSize&);
116 bool initializeEGL();
118 String m_displayName;
119 WebCore::WlUniquePtr<struct wl_display> m_display;
120 WebCore::WlUniquePtr<struct wl_global> m_compositorGlobal;
121 WebCore::WlUniquePtr<struct wl_global> m_webkitgtkGlobal;
122 GRefPtr<GSource> m_eventSource;
123 std::unique_ptr<WebCore::GLContext> m_eglContext;
124 HashMap<WebPageProxy*, Surface*> m_pageMap;
127 } // namespace WebKit
129 #endif // PLATFORM(WAYLAND)