1/*
2 * Copyright (C) 2012 Intel Corporation. All rights reserved.
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
28#if USE(3D_GRAPHICS)
29#include "GLPlatformSurface.h"
30
31#if USE(GLX)
32#include "GLXSurface.h"
33#endif
34
35#if USE(EGL)
36#include "EGLSurface.h"
37#endif
38
39#include "NotImplemented.h"
40
41namespace WebCore {
42
43static GLPlatformSurface* m_currentDrawable = 0;
44
45std::unique_ptr<GLPlatformSurface> GLPlatformSurface::createOffScreenSurface(SurfaceAttributes attributes)
46{
47    std::unique_ptr<GLPlatformSurface> surface;
48#if USE(GLX)
49    surface = std::make_unique<GLXOffScreenSurface>(attributes);
50#elif USE(EGL) && USE(GRAPHICS_SURFACE)
51    surface = EGLOffScreenSurface::createOffScreenSurface(attributes);
52#else
53    // FIXME: Need WGL implementation for Windows
54    notImplemented();
55#endif
56
57    if (surface && surface->drawable())
58        return surface;
59
60    return nullptr;
61}
62
63GLPlatformSurface::GLPlatformSurface(SurfaceAttributes)
64    : m_sharedDisplay(0)
65    , m_drawable(0)
66    , m_bufferHandle(0)
67{
68}
69
70GLPlatformSurface::~GLPlatformSurface()
71{
72    if (m_currentDrawable == this)
73        m_currentDrawable = 0;
74}
75
76PlatformBufferHandle GLPlatformSurface::handle() const
77{
78    return m_bufferHandle;
79}
80
81PlatformDrawable GLPlatformSurface::drawable() const
82{
83    return m_drawable;
84}
85
86const IntRect& GLPlatformSurface::geometry() const
87{
88    return m_rect;
89}
90
91PlatformDisplay GLPlatformSurface::sharedDisplay() const
92{
93    return m_sharedDisplay;
94}
95
96PlatformSurfaceConfig GLPlatformSurface::configuration()
97{
98    return 0;
99}
100
101void GLPlatformSurface::swapBuffers()
102{
103    notImplemented();
104}
105
106bool GLPlatformSurface::isCurrentDrawable() const
107{
108    return m_currentDrawable == this;
109}
110
111void GLPlatformSurface::onMakeCurrent()
112{
113    m_currentDrawable = this;
114}
115
116void GLPlatformSurface::updateContents(const uint32_t)
117{
118}
119
120void GLPlatformSurface::setGeometry(const IntRect&)
121{
122}
123
124void GLPlatformSurface::destroy()
125{
126    if (m_currentDrawable == this)
127        m_currentDrawable = 0;
128}
129
130GLPlatformSurface::SurfaceAttributes GLPlatformSurface::attributes() const
131{
132    return GLPlatformSurface::Default;
133}
134
135}
136
137#endif
138