1/* 2 Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies) 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 GraphicsSurface_h 21#define GraphicsSurface_h 22 23#if USE(GRAPHICS_SURFACE) 24 25#include "GraphicsContext.h" 26#include "GraphicsContext3D.h" 27#include "GraphicsSurfaceToken.h" 28#include "IntRect.h" 29#include <wtf/OwnPtr.h> 30#include <wtf/PassOwnPtr.h> 31#include <wtf/RefCounted.h> 32#include <wtf/RefPtr.h> 33 34#if OS(DARWIN) 35typedef struct __IOSurface* IOSurfaceRef; 36typedef IOSurfaceRef PlatformGraphicsSurface; 37#endif 38 39#if OS(LINUX) 40typedef uint32_t PlatformGraphicsSurface; 41#endif 42 43#if OS(WINDOWS) 44typedef HANDLE PlatformGraphicsSurface; 45#endif 46 47namespace WebCore { 48 49class BitmapTexture; 50class TextureMapper; 51struct GraphicsSurfacePrivate; 52 53class GraphicsSurface : public RefCounted<GraphicsSurface> { 54public: 55 enum Flag { 56 SupportsAlpha = 0x01, 57 SupportsSoftwareWrite = 0x02, 58 SupportsSoftwareRead = 0x04, 59 SupportsTextureTarget = 0x08, 60 SupportsTextureSource = 0x10, 61 SupportsCopyToTexture = 0x20, 62 SupportsCopyFromTexture = 0x40, 63 SupportsSharing = 0x80, 64 SupportsSingleBuffered = 0x100 65 }; 66 67 enum LockOption { 68 RetainPixels = 0x01, 69 ReadOnly = 0x02 70 }; 71 72 typedef int Flags; 73 typedef int LockOptions; 74 75 Flags flags() const { return m_flags; } 76 IntSize size() const; 77 78 static PassRefPtr<GraphicsSurface> create(const IntSize&, Flags, const PlatformGraphicsContext3D shareContext = 0); 79 static PassRefPtr<GraphicsSurface> create(const IntSize&, Flags, const GraphicsSurfaceToken&); 80 void copyToGLTexture(uint32_t target, uint32_t texture, const IntRect& targetRect, const IntPoint& sourceOffset); 81 void copyFromTexture(uint32_t texture, const IntRect& sourceRect); 82 void paintToTextureMapper(TextureMapper*, const FloatRect& targetRect, const TransformationMatrix&, float opacity); 83 uint32_t frontBuffer(); 84 uint32_t swapBuffers(); 85 GraphicsSurfaceToken exportToken(); 86 uint32_t getTextureID(); 87 PassOwnPtr<GraphicsContext> beginPaint(const IntRect&, LockOptions); 88 PassRefPtr<Image> createReadOnlyImage(const IntRect&); 89 ~GraphicsSurface(); 90 91protected: 92 static PassRefPtr<GraphicsSurface> platformCreate(const IntSize&, Flags, const PlatformGraphicsContext3D); 93 static PassRefPtr<GraphicsSurface> platformImport(const IntSize&, Flags, const GraphicsSurfaceToken&); 94 GraphicsSurfaceToken platformExport(); 95 void platformDestroy(); 96 97 uint32_t platformGetTextureID(); 98 char* platformLock(const IntRect&, int* stride, LockOptions); 99 void platformUnlock(); 100 void platformCopyToGLTexture(uint32_t target, uint32_t texture, const IntRect&, const IntPoint&); 101 void platformCopyFromTexture(uint32_t texture, const IntRect& sourceRect); 102 void platformPaintToTextureMapper(TextureMapper*, const FloatRect& targetRect, const TransformationMatrix&, float opacity); 103 uint32_t platformFrontBuffer() const; 104 uint32_t platformSwapBuffers(); 105 IntSize platformSize() const; 106 107 PassOwnPtr<GraphicsContext> platformBeginPaint(const IntSize&, char* bits, int stride); 108 109protected: 110 LockOptions m_lockOptions; 111 Flags m_flags; 112 113private: 114 GraphicsSurface(const IntSize&, Flags); 115 116#if PLATFORM(QT) 117 static void didReleaseImage(void*); 118#endif 119 120private: 121 uint32_t m_fbo; 122 GraphicsSurfacePrivate* m_private; 123}; 124 125} 126#endif // USE(GRAPHICS_SURFACE) 127 128#endif // GraphicsSurface_h 129