• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef TENSORFLOW_LITE_DELEGATES_GPU_GL_EGL_SURFACE_H_
17 #define TENSORFLOW_LITE_DELEGATES_GPU_GL_EGL_SURFACE_H_
18 
19 #include <cstdint>
20 
21 #include "tensorflow/lite/delegates/gpu/common/status.h"
22 #include "tensorflow/lite/delegates/gpu/gl/portable_egl.h"
23 
24 namespace tflite {
25 namespace gpu {
26 namespace gl {
27 
28 // An RAII wrapper for EGLSurface.
29 // See https://www.khronos.org/registry/EGL/sdk/docs/man/html/eglIntro.xhtml for
30 // an introduction to the concepts.
31 //
32 // EglSurface is moveable but not copyable.
33 class EglSurface {
34  public:
35   // Creates an invalid EglSurface.
EglSurface()36   EglSurface() : surface_(EGL_NO_SURFACE), display_(EGL_NO_DISPLAY) {}
37 
EglSurface(EGLSurface surface,EGLDisplay display)38   EglSurface(EGLSurface surface, EGLDisplay display)
39       : surface_(surface), display_(display) {}
40 
41   // Move-only
42   EglSurface(EglSurface&& other);
43   EglSurface& operator=(EglSurface&& other);
44   EglSurface(const EglSurface&) = delete;
45   EglSurface& operator=(const EglSurface&) = delete;
46 
~EglSurface()47   ~EglSurface() { Invalidate(); }
48 
surface()49   EGLSurface surface() const { return surface_; }
50 
51  private:
52   void Invalidate();
53 
54   EGLSurface surface_;
55   EGLDisplay display_;
56 };
57 
58 // Creates off-screen pbuffer-based surface of the given height and width.
59 absl::Status CreatePbufferRGBSurface(EGLConfig config, EGLDisplay display,
60                                      uint32_t height, uint32_t width,
61                                      EglSurface* egl_surface);
62 
63 }  // namespace gl
64 }  // namespace gpu
65 }  // namespace tflite
66 
67 #endif  // TENSORFLOW_LITE_DELEGATES_GPU_GL_EGL_SURFACE_H_
68