Home | History | Annotate | Download | only in libOpenglRender
      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_WINDOWSURFACE_H
     17 #define _LIBRENDER_WINDOWSURFACE_H
     18 
     19 #include "ColorBuffer.h"
     20 #include "RenderContext.h"
     21 #include "FBConfig.h"
     22 #include "SmartPtr.h"
     23 #include "FixedBuffer.h"
     24 #include <EGL/egl.h>
     25 #include <GLES/gl.h>
     26 
     27 enum SurfaceBindType {
     28     SURFACE_BIND_READ,
     29     SURFACE_BIND_DRAW,
     30     SURFACE_BIND_READDRAW
     31 };
     32 
     33 class WindowSurface
     34 {
     35 public:
     36     static WindowSurface *create(int p_config, int p_width, int p_height);
     37     ~WindowSurface();
     38     EGLSurface getEGLSurface() const { return m_eglSurface; }
     39 
     40     void setColorBuffer(ColorBufferPtr p_colorBuffer);
     41     void flushColorBuffer();
     42     void bind(RenderContextPtr p_ctx, SurfaceBindType p_bindType);
     43 
     44 private:
     45     WindowSurface();
     46 
     47     void copyToColorBuffer();  // copy pbuffer content with readback+download
     48     void blitToColorBuffer();  // copy pbuffer content with texload and blit
     49     bool resizePbuffer(unsigned int p_width, unsigned int p_height);
     50 
     51 private:
     52     GLuint m_fbObj;   // GLES Framebuffer object (when EGLimage is used)
     53     GLuint m_depthRB;
     54     GLuint m_stencilRB;
     55     EGLSurface m_eglSurface;
     56     ColorBufferPtr m_attachedColorBuffer;
     57     RenderContextPtr m_readContext;
     58     RenderContextPtr m_drawContext;
     59     GLuint m_width;
     60     GLuint m_height;
     61     GLuint m_pbufWidth;
     62     GLuint m_pbufHeight;
     63     bool m_useEGLImage;
     64     bool m_useBindToTexture;
     65     FixedBuffer m_xferBuffer;
     66     FixedBuffer m_xUpdateBuf;
     67     const FBConfig *m_fbconf;
     68 };
     69 
     70 typedef SmartPtr<WindowSurface> WindowSurfacePtr;
     71 
     72 #endif
     73