1 //
2 // Copyright (c) 2016 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 // SurfaceEGL.cpp: EGL implementation of egl::Surface
8
9 #include "libANGLE/renderer/gl/egl/SurfaceEGL.h"
10
11 #include "common/debug.h"
12
13 namespace rx
14 {
15
SurfaceEGL(const egl::SurfaceState & state,const FunctionsEGL * egl,EGLConfig config,const std::vector<EGLint> & attribList,EGLContext context,RendererGL * renderer)16 SurfaceEGL::SurfaceEGL(const egl::SurfaceState &state,
17 const FunctionsEGL *egl,
18 EGLConfig config,
19 const std::vector<EGLint> &attribList,
20 EGLContext context,
21 RendererGL *renderer)
22 : SurfaceGL(state, renderer),
23 mEGL(egl),
24 mConfig(config),
25 mAttribList(attribList),
26 mSurface(EGL_NO_SURFACE),
27 mContext(context)
28 {
29 }
30
~SurfaceEGL()31 SurfaceEGL::~SurfaceEGL()
32 {
33 if (mSurface != EGL_NO_SURFACE)
34 {
35 EGLBoolean success = mEGL->destroySurface(mSurface);
36 ASSERT(success == EGL_TRUE);
37 }
38 }
39
makeCurrent()40 egl::Error SurfaceEGL::makeCurrent()
41 {
42 EGLBoolean success = mEGL->makeCurrent(mSurface, mContext);
43 if (success == EGL_FALSE)
44 {
45 return egl::Error(mEGL->getError(), "eglMakeCurrent failed");
46 }
47 return egl::Error(EGL_SUCCESS);
48 }
49
swap()50 egl::Error SurfaceEGL::swap()
51 {
52 EGLBoolean success = mEGL->swapBuffers(mSurface);
53 if (success == EGL_FALSE)
54 {
55 return egl::Error(mEGL->getError(), "eglSwapBuffers failed");
56 }
57 return egl::Error(EGL_SUCCESS);
58 }
59
postSubBuffer(EGLint x,EGLint y,EGLint width,EGLint height)60 egl::Error SurfaceEGL::postSubBuffer(EGLint x, EGLint y, EGLint width, EGLint height)
61 {
62 UNIMPLEMENTED();
63 return egl::Error(EGL_BAD_SURFACE);
64 }
65
querySurfacePointerANGLE(EGLint attribute,void ** value)66 egl::Error SurfaceEGL::querySurfacePointerANGLE(EGLint attribute, void **value)
67 {
68 UNIMPLEMENTED();
69 return egl::Error(EGL_BAD_SURFACE);
70 }
71
bindTexImage(gl::Texture * texture,EGLint buffer)72 egl::Error SurfaceEGL::bindTexImage(gl::Texture *texture, EGLint buffer)
73 {
74 EGLBoolean success = mEGL->bindTexImage(mSurface, buffer);
75 if (success == EGL_FALSE)
76 {
77 return egl::Error(mEGL->getError(), "eglBindTexImage failed");
78 }
79 return egl::Error(EGL_SUCCESS);
80 }
81
releaseTexImage(EGLint buffer)82 egl::Error SurfaceEGL::releaseTexImage(EGLint buffer)
83 {
84 EGLBoolean success = mEGL->releaseTexImage(mSurface, buffer);
85 if (success == EGL_FALSE)
86 {
87 return egl::Error(mEGL->getError(), "eglReleaseTexImage failed");
88 }
89 return egl::Error(EGL_SUCCESS);
90 }
91
setSwapInterval(EGLint interval)92 void SurfaceEGL::setSwapInterval(EGLint interval)
93 {
94 EGLBoolean success = mEGL->swapInterval(interval);
95 if (success == EGL_FALSE)
96 {
97 ERR("eglSwapInterval error 0x%04x", mEGL->getError());
98 ASSERT(false);
99 }
100 }
101
getWidth() const102 EGLint SurfaceEGL::getWidth() const
103 {
104 EGLint value;
105 EGLBoolean success = mEGL->querySurface(mSurface, EGL_WIDTH, &value);
106 ASSERT(success == EGL_TRUE);
107 return value;
108 }
109
getHeight() const110 EGLint SurfaceEGL::getHeight() const
111 {
112 EGLint value;
113 EGLBoolean success = mEGL->querySurface(mSurface, EGL_HEIGHT, &value);
114 ASSERT(success == EGL_TRUE);
115 return value;
116 }
117
isPostSubBufferSupported() const118 EGLint SurfaceEGL::isPostSubBufferSupported() const
119 {
120 UNIMPLEMENTED();
121 return 0;
122 }
123
getSwapBehavior() const124 EGLint SurfaceEGL::getSwapBehavior() const
125 {
126 EGLint value;
127 EGLBoolean success = mEGL->querySurface(mSurface, EGL_SWAP_BEHAVIOR, &value);
128 ASSERT(success == EGL_TRUE);
129 return value;
130 }
131
132 } // namespace rx
133