2
* Copyright (C) 2012 Intel Corporation. All rights reserved.
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 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.
27
#include "GLPlatformSurface.h"
29
#if USE(ACCELERATED_COMPOSITING)
32
#include "GLXSurface.h"
35
#include "NotImplemented.h"
39
PassOwnPtr<GLPlatformSurface> GLPlatformSurface::createOffscreenSurface()
42
OwnPtr<GLPlatformSurface> surface = adoptPtr(new GLXPBuffer());
44
if (surface->handle())
45
return surface.release();
51
PassOwnPtr<GLPlatformSurface> GLPlatformSurface::createTransportSurface()
54
OwnPtr<GLPlatformSurface> surface = adoptPtr(new GLXTransportSurface());
56
if (surface->handle())
57
return surface.release();
63
GLPlatformSurface::GLPlatformSurface()
64
: m_restoreNeeded(true)
71
GLPlatformSurface::~GLPlatformSurface()
75
PlatformSurface GLPlatformSurface::handle() const
80
const IntRect& GLPlatformSurface::geometry() const
85
PlatformDisplay GLPlatformSurface::sharedDisplay() const
87
return m_sharedDisplay;
90
PlatformSurfaceConfig GLPlatformSurface::configuration()
95
void GLPlatformSurface::swapBuffers()
100
void GLPlatformSurface::copyTexture(uint32_t texture, const IntRect& sourceRect)
103
glGenFramebuffers(1, &m_fboId);
105
m_restoreNeeded = true;
106
int x = sourceRect.x();
107
int y = sourceRect.y();
108
int width = sourceRect.width();
109
int height = sourceRect.height();
111
glPushAttrib(GL_COLOR_BUFFER_BIT);
114
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &previousFBO);
116
glBindFramebuffer(GL_READ_FRAMEBUFFER, m_fboId);
118
glBindTexture(GL_TEXTURE_2D, texture);
119
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
121
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
123
glBlitFramebuffer(x, y, width, height, x, y, width, height, GL_COLOR_BUFFER_BIT, GL_LINEAR);
125
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
126
glBindTexture(GL_TEXTURE_2D, 0);
127
glBindFramebuffer(GL_FRAMEBUFFER, previousFBO);
132
void GLPlatformSurface::updateContents(uint32_t texture, const IntRect& sourceRect, const GLuint bindFboId)
134
m_restoreNeeded = false;
137
glGenFramebuffers(1, &m_fboId);
139
int x = sourceRect.x();
140
int y = sourceRect.y();
141
int width = sourceRect.width();
142
int height = sourceRect.height();
144
glBindFramebuffer(GL_READ_FRAMEBUFFER, m_fboId);
145
glBindTexture(GL_TEXTURE_2D, texture);
146
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
147
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
148
glBlitFramebuffer(x, y, width, height, x, y, width, height, GL_COLOR_BUFFER_BIT, GL_LINEAR);
150
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
151
glBindTexture(GL_TEXTURE_2D, 0);
152
glBindFramebuffer(GL_FRAMEBUFFER, bindFboId);
155
void GLPlatformSurface::setGeometry(const IntRect& newRect)
160
void GLPlatformSurface::destroy()
165
glDeleteFramebuffers(1, &m_fboId);