• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2015 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 // PbufferSurfaceGLX.cpp: GLX implementation of egl::Surface for PBuffers
8 
9 #include "libANGLE/renderer/gl/glx/PbufferSurfaceGLX.h"
10 
11 #include "common/debug.h"
12 #include "libANGLE/renderer/gl/glx/DisplayGLX.h"
13 #include "libANGLE/renderer/gl/glx/FunctionsGLX.h"
14 
15 namespace rx
16 {
17 
PbufferSurfaceGLX(const egl::SurfaceState & state,EGLint width,EGLint height,bool largest,const FunctionsGLX & glx,glx::FBConfig fbConfig)18 PbufferSurfaceGLX::PbufferSurfaceGLX(const egl::SurfaceState &state,
19                                      EGLint width,
20                                      EGLint height,
21                                      bool largest,
22                                      const FunctionsGLX &glx,
23                                      glx::FBConfig fbConfig)
24     : SurfaceGLX(state),
25       mWidth(width),
26       mHeight(height),
27       mLargest(largest),
28       mGLX(glx),
29       mFBConfig(fbConfig),
30       mPbuffer(0)
31 {}
32 
~PbufferSurfaceGLX()33 PbufferSurfaceGLX::~PbufferSurfaceGLX()
34 {
35     if (mPbuffer)
36     {
37         mGLX.destroyPbuffer(mPbuffer);
38     }
39 }
40 
initialize(const egl::Display * display)41 egl::Error PbufferSurfaceGLX::initialize(const egl::Display *display)
42 {
43     // Avoid creating 0-sized PBuffers as it fails on the Intel Mesa driver
44     // as commented on https://bugs.freedesktop.org/show_bug.cgi?id=38869 so we
45     // use (w, 1) or (1, h) instead.
46     int width  = std::max(1, static_cast<int>(mWidth));
47     int height = std::max(1, static_cast<int>(mHeight));
48 
49     const int attribs[] = {
50         GLX_PBUFFER_WIDTH, width, GLX_PBUFFER_HEIGHT, height, GLX_LARGEST_PBUFFER, mLargest, None};
51 
52     mPbuffer = mGLX.createPbuffer(mFBConfig, attribs);
53     if (!mPbuffer)
54     {
55         return egl::EglBadAlloc() << "Failed to create a native GLX pbuffer.";
56     }
57 
58     if (mLargest)
59     {
60         mGLX.queryDrawable(mPbuffer, GLX_WIDTH, &mWidth);
61         mGLX.queryDrawable(mPbuffer, GLX_HEIGHT, &mHeight);
62     }
63 
64     return egl::NoError();
65 }
66 
makeCurrent(const gl::Context * context)67 egl::Error PbufferSurfaceGLX::makeCurrent(const gl::Context *context)
68 {
69     return egl::NoError();
70 }
71 
swap(const gl::Context * context)72 egl::Error PbufferSurfaceGLX::swap(const gl::Context *context)
73 {
74     return egl::NoError();
75 }
76 
postSubBuffer(const gl::Context * context,EGLint x,EGLint y,EGLint width,EGLint height)77 egl::Error PbufferSurfaceGLX::postSubBuffer(const gl::Context *context,
78                                             EGLint x,
79                                             EGLint y,
80                                             EGLint width,
81                                             EGLint height)
82 {
83     return egl::NoError();
84 }
85 
querySurfacePointerANGLE(EGLint attribute,void ** value)86 egl::Error PbufferSurfaceGLX::querySurfacePointerANGLE(EGLint attribute, void **value)
87 {
88     UNIMPLEMENTED();
89     return egl::NoError();
90 }
91 
bindTexImage(const gl::Context * context,gl::Texture * texture,EGLint buffer)92 egl::Error PbufferSurfaceGLX::bindTexImage(const gl::Context *context,
93                                            gl::Texture *texture,
94                                            EGLint buffer)
95 {
96     UNIMPLEMENTED();
97     return egl::NoError();
98 }
99 
releaseTexImage(const gl::Context * context,EGLint buffer)100 egl::Error PbufferSurfaceGLX::releaseTexImage(const gl::Context *context, EGLint buffer)
101 {
102     UNIMPLEMENTED();
103     return egl::NoError();
104 }
105 
setSwapInterval(EGLint interval)106 void PbufferSurfaceGLX::setSwapInterval(EGLint interval) {}
107 
getWidth() const108 EGLint PbufferSurfaceGLX::getWidth() const
109 {
110     return mWidth;
111 }
112 
getHeight() const113 EGLint PbufferSurfaceGLX::getHeight() const
114 {
115     return mHeight;
116 }
117 
isPostSubBufferSupported() const118 EGLint PbufferSurfaceGLX::isPostSubBufferSupported() const
119 {
120     UNIMPLEMENTED();
121     return EGL_FALSE;
122 }
123 
getSwapBehavior() const124 EGLint PbufferSurfaceGLX::getSwapBehavior() const
125 {
126     return EGL_BUFFER_PRESERVED;
127 }
128 
checkForResize()129 egl::Error PbufferSurfaceGLX::checkForResize()
130 {
131     // The size of pbuffers never change
132     return egl::NoError();
133 }
134 
getDrawable() const135 glx::Drawable PbufferSurfaceGLX::getDrawable() const
136 {
137     return mPbuffer;
138 }
139 
140 }  // namespace rx
141