2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef _LIBRENDER_WINDOW_SURFACE_H
17 #define _LIBRENDER_WINDOW_SURFACE_H
19 #include "anbox/graphics/emugl/ColorBuffer.h"
20 #include "anbox/graphics/emugl/RenderContext.h"
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.
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,
40 // Retrieve the host EGLSurface of the WindowSurface's Pbuffer.
41 EGLSurface getEGLSurface() const { return mSurface; }
43 // Attach a ColorBuffer to this WindowSurface.
44 // Once attached, calling flushColorBuffer() will copy the Pbuffer's
45 // pixels to the color buffer.
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);
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();
56 // Used by bind() below.
57 enum BindType { BIND_READ,
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.
67 // Bind a context to the WindowSurface (huh? Normally you would bind a
68 // surface to the context, not the other way around)
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);
78 WindowSurface(const WindowSurface& other);
80 explicit WindowSurface(EGLDisplay display, EGLConfig config);
82 bool resize(unsigned int p_width, unsigned int p_height);
86 ColorBufferPtr mAttachedColorBuffer;
87 RenderContextPtr mReadContext;
88 RenderContextPtr mDrawContext;
95 typedef std::shared_ptr<WindowSurface> WindowSurfacePtr;
97 #endif // _LIBRENDER_WINDOW_SURFACE_H