1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef INCLUDED_CANVAS_IRENDERMODULE_HXX 29 #define INCLUDED_CANVAS_IRENDERMODULE_HXX 30 31 #include <sal/types.h> 32 33 #include <boost/shared_ptr.hpp> 34 #include <boost/utility.hpp> 35 36 37 namespace basegfx 38 { 39 class B2DRange; 40 class B2IRange; 41 class B2IVector; 42 class B2IPoint; 43 } 44 45 namespace canvas 46 { 47 struct ISurface; 48 49 struct Vertex 50 { 51 float r,g,b,a; 52 float u,v; 53 float x,y,z; 54 }; 55 56 /** Output module interface for backend render implementations. 57 58 Implement this interface for each operating system- or 59 library-specific rendering backend, which needs coupling with 60 the canvas rendering framework (which can be shared between 61 all backend implementations). 62 */ 63 struct IRenderModule 64 { 65 /** Type of primitive passed to the render module via 66 pushVertex() 67 */ 68 enum PrimitiveType 69 { 70 PRIMITIVE_TYPE_UNKNOWN, 71 PRIMITIVE_TYPE_TRIANGLE, 72 PRIMITIVE_TYPE_QUAD 73 }; 74 75 virtual ~IRenderModule() {} 76 77 /// Lock rendermodule against concurrent access 78 virtual void lock() const = 0; 79 80 /// Unlock rendermodule for concurrent access 81 virtual void unlock() const = 0; 82 83 /** Maximal size of VRAM pages available 84 85 This is typically the maximum texture size of the 86 hardware, or some arbitrary limit if the backend is 87 software. 88 */ 89 virtual ::basegfx::B2IVector getPageSize() = 0; 90 91 /** Create a (possibly hardware-accelerated) surface 92 93 @return a pointer to a surface, which is an abstraction of 94 a piece of (possibly hardware-accelerated) texture memory. 95 */ 96 virtual ::boost::shared_ptr<ISurface> createSurface( const ::basegfx::B2IVector& surfaceSize ) = 0; 97 98 /** Begin rendering the given primitive. 99 100 Each beginPrimitive() call must be matched with an 101 endPrimitive() call. 102 */ 103 virtual void beginPrimitive( PrimitiveType eType ) = 0; 104 105 /** Finish rendering a primitive. 106 107 Each beginPrimitive() call must be matched with an 108 endPrimitive() call. 109 */ 110 virtual void endPrimitive() = 0; 111 112 /** Add given vertex to current primitive 113 114 After issuing a beginPrimitive(), each pushVertex() adds a 115 vertex to the active primitive. 116 */ 117 virtual void pushVertex( const Vertex& vertex ) = 0; 118 119 /** Query error status 120 121 @returns true, if an error occured during primitive 122 construction. 123 */ 124 virtual bool isError() = 0; 125 }; 126 127 typedef ::boost::shared_ptr< IRenderModule > IRenderModuleSharedPtr; 128 129 /// Little RAII wrapper for guarding access to IRenderModule interface 130 class RenderModuleGuard : private ::boost::noncopyable 131 { 132 public: 133 explicit RenderModuleGuard( const IRenderModuleSharedPtr& rRenderModule ) : 134 mpRenderModule( rRenderModule ) 135 { 136 mpRenderModule->lock(); 137 } 138 139 ~RenderModuleGuard() 140 { 141 mpRenderModule->unlock(); 142 } 143 144 private: 145 const IRenderModuleSharedPtr mpRenderModule; 146 }; 147 } 148 149 #endif /* INCLUDED_CANVAS_IRENDERMODULE_HXX */ 150