4b35ddb7a6bfb8b4e5cb61a9b934c92dc54a2a1d
[iec.git] / src / type3_AndroidCloud / anbox-master / src / anbox / graphics / emugl / WindowSurface.h
1 /*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #ifndef _LIBRENDER_WINDOW_SURFACE_H
17 #define _LIBRENDER_WINDOW_SURFACE_H
18
19 #include "anbox/graphics/emugl/ColorBuffer.h"
20 #include "anbox/graphics/emugl/RenderContext.h"
21
22 #include <EGL/egl.h>
23 #include <GLES/gl.h>
24
25 // A class used to model a guest-side window surface. The implementation
26 // uses a host Pbuffer to act as the EGL rendering surface instead.
27 class WindowSurface {
28  public:
29   // Create a new WindowSurface instance.
30   // |display| is the host EGLDisplay value.
31   // |config| is the host EGLConfig value.
32   // |width| and |height| are the initial size of the Pbuffer.
33   // Return a new WindowSurface instance on success, or NULL on failure.
34   static WindowSurface* create(EGLDisplay display, EGLConfig config, int width,
35                                int height);
36
37   // Destructor.
38   ~WindowSurface();
39
40   // Retrieve the host EGLSurface of the WindowSurface's Pbuffer.
41   EGLSurface getEGLSurface() const { return mSurface; }
42
43   // Attach a ColorBuffer to this WindowSurface.
44   // Once attached, calling flushColorBuffer() will copy the Pbuffer's
45   // pixels to the color buffer.
46   //
47   // IMPORTANT: This automatically resizes the Pbuffer's to the ColorBuffer's
48   // dimensions. Potentially losing pixel values in the process.
49   void setColorBuffer(ColorBufferPtr p_colorBuffer);
50
51   // Copy the Pbuffer's pixels to the attached color buffer.
52   // Returns true on success, or false on error (e.g. if there is no
53   // attached color buffer).
54   bool flushColorBuffer();
55
56   // Used by bind() below.
57   enum BindType { BIND_READ,
58                   BIND_DRAW,
59                   BIND_READDRAW };
60
61   // TODO(digit): What is this used for exactly? For example, the
62   // mReadContext is never used by this class. The mDrawContext is only
63   // used temporarily during flushColorBuffer() operation, and could be
64   // passed as a parameter to the function instead. Maybe this is only used
65   // to increment reference counts on the smart pointers.
66   //
67   // Bind a context to the WindowSurface (huh? Normally you would bind a
68   // surface to the context, not the other way around)
69   //
70   // |p_ctx| is a RenderContext pointer.
71   // |p_bindType| is the type of bind. For BIND_READ, this assigns |p_ctx|
72   // to mReadContext, for BIND_DRAW, it assigns it to mDrawContext, and for
73   // for BIND_READDRAW, it assigns it to both.
74   void bind(RenderContextPtr p_ctx, BindType p_bindType);
75
76  private:
77   WindowSurface();
78   WindowSurface(const WindowSurface& other);
79
80   explicit WindowSurface(EGLDisplay display, EGLConfig config);
81
82   bool resize(unsigned int p_width, unsigned int p_height);
83
84  private:
85   EGLSurface mSurface;
86   ColorBufferPtr mAttachedColorBuffer;
87   RenderContextPtr mReadContext;
88   RenderContextPtr mDrawContext;
89   GLuint mWidth;
90   GLuint mHeight;
91   EGLConfig mConfig;
92   EGLDisplay mDisplay;
93 };
94
95 typedef std::shared_ptr<WindowSurface> WindowSurfacePtr;
96
97 #endif  // _LIBRENDER_WINDOW_SURFACE_H