~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebCore/platform/graphics/opengl/GLPlatformSurface.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#include "GLPlatformSurface.h"
 
28
 
 
29
#if USE(ACCELERATED_COMPOSITING)
 
30
 
 
31
#if HAVE(GLX)
 
32
#include "GLXSurface.h"
 
33
#endif
 
34
 
 
35
#include "NotImplemented.h"
 
36
 
 
37
namespace WebCore {
 
38
 
 
39
PassOwnPtr<GLPlatformSurface> GLPlatformSurface::createOffscreenSurface()
 
40
{
 
41
#if HAVE(GLX)
 
42
    OwnPtr<GLPlatformSurface> surface = adoptPtr(new GLXPBuffer());
 
43
 
 
44
    if (surface->handle())
 
45
        return surface.release();
 
46
#endif
 
47
 
 
48
    return nullptr;
 
49
}
 
50
 
 
51
PassOwnPtr<GLPlatformSurface> GLPlatformSurface::createTransportSurface()
 
52
{
 
53
#if HAVE(GLX)
 
54
    OwnPtr<GLPlatformSurface> surface = adoptPtr(new GLXTransportSurface());
 
55
 
 
56
    if (surface->handle())
 
57
        return surface.release();
 
58
#endif
 
59
 
 
60
    return nullptr;
 
61
}
 
62
 
 
63
GLPlatformSurface::GLPlatformSurface()
 
64
    : m_restoreNeeded(true)
 
65
    , m_fboId(0)
 
66
    , m_sharedDisplay(0)
 
67
    , m_drawable(0)
 
68
{
 
69
}
 
70
 
 
71
GLPlatformSurface::~GLPlatformSurface()
 
72
{
 
73
}
 
74
 
 
75
PlatformSurface GLPlatformSurface::handle() const
 
76
{
 
77
    return m_drawable;
 
78
}
 
79
 
 
80
const IntRect& GLPlatformSurface::geometry() const
 
81
{
 
82
    return m_rect;
 
83
}
 
84
 
 
85
PlatformDisplay GLPlatformSurface::sharedDisplay() const
 
86
{
 
87
    return m_sharedDisplay;
 
88
}
 
89
 
 
90
PlatformSurfaceConfig GLPlatformSurface::configuration()
 
91
{
 
92
    return 0;
 
93
}
 
94
 
 
95
void GLPlatformSurface::swapBuffers()
 
96
{
 
97
    notImplemented();
 
98
}
 
99
 
 
100
void GLPlatformSurface::copyTexture(uint32_t texture, const IntRect& sourceRect)
 
101
{
 
102
    if (!m_fboId)
 
103
        glGenFramebuffers(1, &m_fboId);
 
104
 
 
105
    m_restoreNeeded = true;
 
106
    int x = sourceRect.x();
 
107
    int y = sourceRect.y();
 
108
    int width = sourceRect.width();
 
109
    int height = sourceRect.height();
 
110
 
 
111
    glPushAttrib(GL_COLOR_BUFFER_BIT);
 
112
 
 
113
    GLint previousFBO;
 
114
    glGetIntegerv(GL_FRAMEBUFFER_BINDING, &previousFBO);
 
115
 
 
116
    glBindFramebuffer(GL_READ_FRAMEBUFFER, m_fboId);
 
117
 
 
118
    glBindTexture(GL_TEXTURE_2D, texture);
 
119
    glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
 
120
 
 
121
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
 
122
 
 
123
    glBlitFramebuffer(x, y, width, height, x, y, width, height, GL_COLOR_BUFFER_BIT, GL_LINEAR);
 
124
 
 
125
    glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
 
126
    glBindTexture(GL_TEXTURE_2D, 0);
 
127
    glBindFramebuffer(GL_FRAMEBUFFER, previousFBO);
 
128
 
 
129
    glPopAttrib();
 
130
}
 
131
 
 
132
void GLPlatformSurface::updateContents(uint32_t texture, const IntRect& sourceRect, const GLuint bindFboId)
 
133
{
 
134
    m_restoreNeeded = false;
 
135
 
 
136
    if (!m_fboId)
 
137
        glGenFramebuffers(1, &m_fboId);
 
138
 
 
139
    int x = sourceRect.x();
 
140
    int y = sourceRect.y();
 
141
    int width = sourceRect.width();
 
142
    int height = sourceRect.height();
 
143
 
 
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);
 
149
    swapBuffers();
 
150
    glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
 
151
    glBindTexture(GL_TEXTURE_2D, 0);
 
152
    glBindFramebuffer(GL_FRAMEBUFFER, bindFboId);
 
153
}
 
154
 
 
155
void GLPlatformSurface::setGeometry(const IntRect& newRect)
 
156
{
 
157
    m_rect = newRect;
 
158
}
 
159
 
 
160
void GLPlatformSurface::destroy()
 
161
{
 
162
    m_rect = IntRect();
 
163
 
 
164
    if (m_fboId)
 
165
        glDeleteFramebuffers(1, &m_fboId);
 
166
 
 
167
    m_fboId = 0;
 
168
}
 
169
 
 
170
}
 
171
 
 
172
#endif