Home | History | Annotate | Download | only in openvg
      1 /*
      2  * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
      3  *
      4  * This library is free software; you can redistribute it and/or
      5  * modify it under the terms of the GNU Library General Public
      6  * License as published by the Free Software Foundation; either
      7  * version 2 of the License, or (at your option) any later version.
      8  *
      9  * This library is distributed in the hope that it will be useful,
     10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     12  * Library General Public License for more details.
     13  *
     14  * You should have received a copy of the GNU Library General Public License
     15  * along with this library; see the file COPYING.LIB.  If not, write to
     16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     17  * Boston, MA 02110-1301, USA.
     18  */
     19 
     20 #ifndef EGLDisplayOpenVG_h
     21 #define EGLDisplayOpenVG_h
     22 
     23 #include <egl.h>
     24 #include <wtf/HashMap.h>
     25 
     26 namespace WebCore {
     27 
     28 class IntSize;
     29 class SurfaceOpenVG;
     30 
     31 class EGLDisplayOpenVG {
     32 public:
     33     friend class SurfaceOpenVG;
     34 
     35     static SurfaceOpenVG* currentSurface();
     36     static void setCurrentDisplay(const EGLDisplay&);
     37     static EGLDisplayOpenVG* current();
     38     static EGLDisplayOpenVG* forDisplay(const EGLDisplay&);
     39 
     40     void setDefaultPbufferConfig(const EGLConfig&);
     41     EGLConfig defaultPbufferConfig();
     42     void setDefaultWindowConfig(const EGLConfig&);
     43     EGLConfig defaultWindowConfig();
     44 
     45     EGLDisplay display() const { return m_display; }
     46     SurfaceOpenVG* sharedPlatformSurface();
     47 
     48     /** Creates a pbuffer surface using the given config. If no surface
     49      * could be created, EGL_NO_SURFACE is returned and errors can be
     50      * checked with the value that is written to the errorCode parameter
     51      * If no surface could be created and errorCode is zero, this method
     52      * will trigger an assertion by itself. */
     53     EGLSurface createPbufferSurface(const IntSize&, const EGLConfig&, EGLint* errorCode = 0);
     54     EGLSurface createPbufferFromClientBuffer(EGLClientBuffer, EGLenum bufferType, const EGLConfig&, EGLint* errorCode = 0);
     55 
     56     EGLSurface surfaceForWindow(EGLNativeWindowType, const EGLConfig&);
     57 
     58     bool surfacesCompatible(const EGLSurface&, const EGLSurface&);
     59 
     60     /** Destroy the surface and its corresponding context (unless another
     61      * surface is still using the same context, in which case the context
     62      * is not destroyed). */
     63     void destroySurface(const EGLSurface&);
     64 
     65     /** Return the context corresponding to the surface.
     66      * If no corresponding context exists, one is created automatically. */
     67     EGLContext contextForSurface(const EGLSurface&);
     68 
     69 private:
     70     static void registerPlatformSurface(SurfaceOpenVG*);
     71     static void unregisterPlatformSurface(SurfaceOpenVG*);
     72 
     73     EGLDisplayOpenVG(const EGLDisplay& display);
     74     ~EGLDisplayOpenVG();
     75 
     76     EGLDisplay m_display;
     77     SurfaceOpenVG* m_sharedPlatformSurface;
     78     EGLint m_pbufferConfigId;
     79     EGLint m_windowConfigId;
     80 
     81     HashMap<EGLSurface, SurfaceOpenVG*> m_platformSurfaces;
     82     HashMap<EGLNativeWindowType, EGLSurface> m_windowSurfaces;
     83     HashMap<EGLSurface, EGLint> m_surfaceConfigIds;
     84     HashMap<EGLint, EGLint> m_compatibleConfigIds;
     85     HashMap<EGLint, EGLContext> m_contexts;
     86 };
     87 
     88 }
     89 
     90 #endif
     91