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 SurfaceOpenVG_h 21 #define SurfaceOpenVG_h 22 23 #if PLATFORM(EGL) 24 #include <egl.h> 25 #endif 26 27 #include <wtf/Noncopyable.h> 28 29 namespace WebCore { 30 31 #if PLATFORM(EGL) 32 class EGLDisplayOpenVG; 33 #endif 34 class PainterOpenVG; 35 class IntSize; 36 37 /** 38 * SurfaceOpenVG provides the functionality of surfaces and contexts that are 39 * underlying the OpenVG implementation. In the vast majority of cases, that 40 * underlying technology is EGL, but OpenVG doesn't depend on EGL per se. 41 * Wrapping surface/context functionality into a separate class avoids lots 42 * of #ifdefs and should make it easy to add different surface/context 43 * implementations than EGL. 44 */ 45 class SurfaceOpenVG { 46 WTF_MAKE_NONCOPYABLE(SurfaceOpenVG); 47 public: 48 enum MakeCurrentMode { 49 ApplyPainterStateOnSurfaceSwitch, 50 DontApplyPainterState, 51 DontSaveOrApplyPainterState 52 }; 53 54 static SurfaceOpenVG* currentSurface(); 55 56 #if PLATFORM(EGL) 57 friend class EGLDisplayOpenVG; 58 59 /** 60 * Create a new EGL pbuffer surface with the specified size and config on 61 * the given display. If config is not specified, the display's default 62 * pbuffer config is used. 63 * 64 * This constructor will trigger an assertion if creation of the surface 65 * fails, unless you pledge to manually process the error code by passing 66 * a non-zero pointer as errorCode parameter. The error code returned by 67 * eglGetError() will be written to that variable. 68 */ 69 SurfaceOpenVG(const IntSize& size, const EGLDisplay& display, EGLConfig* config = 0, EGLint* errorCode = 0); 70 71 /** 72 * Create a new EGL pbuffer surface that will be bound to the given 73 * client buffer (read: VGImage), with the specified config on the 74 * given display. If config is not specified, the display's default 75 * pbuffer config is used. 76 * 77 * After the surface is created, you will only be able to access the 78 * client buffer image if the surface is not current. The recommended way 79 * to ensure this is to call surface->sharedSurface()->makeCurrent() if you 80 * simply want to access the image's pixel contents, or if you intend to 81 * draw the image directly, making the draw target surface current. 82 * 83 * This constructor will trigger an assertion if creation of the surface 84 * fails, unless you pledge to manually process the error code by passing 85 * a non-zero pointer as errorCode parameter. The error code returned by 86 * eglGetError() will be written to that variable. 87 */ 88 SurfaceOpenVG(EGLClientBuffer buffer, EGLenum bufferType, 89 const EGLDisplay& display, EGLConfig* config = 0, EGLint* errorCode = 0); 90 91 /** 92 * Create a new EGL window surface with the specified native window handle 93 * and config on the given display. If config is not specified, the 94 * display's default window config is used. 95 */ 96 SurfaceOpenVG(EGLNativeWindowType window, const EGLDisplay& display, EGLConfig* config = 0); 97 98 EGLDisplay eglDisplay() const { return m_eglDisplay; } 99 EGLSurface eglSurface() const { return m_eglSurface; } 100 EGLContext eglContext() const { return m_eglContext; } 101 #endif 102 103 ~SurfaceOpenVG(); 104 105 /** 106 * If a surface is invalid (could not be created), all method calls will 107 * crash horribly. 108 */ 109 bool isValid() const; 110 111 int width() const; 112 int height() const; 113 114 SurfaceOpenVG* sharedSurface() const; 115 116 /** 117 * Make the associated GL/EGL context the current one, so that subsequent 118 * OpenVG commands apply to it. 119 */ 120 void makeCurrent(MakeCurrentMode mode = ApplyPainterStateOnSurfaceSwitch); 121 122 /** 123 * Make a surface/context combination current that is "compatible" 124 * (i.e. can access its shared resources) to the given one. If no 125 * surface/context is current, the given one is made current. 126 * 127 * This method is meant to avoid context changes if they're not 128 * necessary, particularly tailored for the case where something 129 * compatible to the shared surface is requested while actual painting 130 * happens on another surface. 131 */ 132 void makeCompatibleCurrent(); 133 134 /** 135 * Empty the OpenVG pipeline and make sure all the performed paint 136 * operations show up on the surface as actual drawn pixels. 137 */ 138 void flush(); 139 140 void setActivePainter(PainterOpenVG*); 141 PainterOpenVG* activePainter(); 142 143 private: 144 PainterOpenVG* m_activePainter; 145 static PainterOpenVG* s_currentPainter; // global currently active painter 146 147 #if PLATFORM(EGL) 148 SurfaceOpenVG(); // for EGLDisplayOpenVG 149 150 EGLDisplay m_eglDisplay; 151 EGLSurface m_eglSurface; 152 EGLContext m_eglContext; 153 #endif 154 }; 155 156 } 157 158 #endif 159