1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef INCLUDED_CANVAS_IRENDERMODULE_HXX 25 #define INCLUDED_CANVAS_IRENDERMODULE_HXX 26 27 #include <sal/types.h> 28 29 #include <boost/shared_ptr.hpp> 30 #include <boost/utility.hpp> 31 32 33 namespace basegfx 34 { 35 class B2DRange; 36 class B2IRange; 37 class B2IVector; 38 class B2IPoint; 39 } 40 41 namespace canvas 42 { 43 struct ISurface; 44 45 struct Vertex 46 { 47 float r,g,b,a; 48 float u,v; 49 float x,y,z; 50 }; 51 52 /** Output module interface for backend render implementations. 53 54 Implement this interface for each operating system- or 55 library-specific rendering backend, which needs coupling with 56 the canvas rendering framework (which can be shared between 57 all backend implementations). 58 */ 59 struct IRenderModule 60 { 61 /** Type of primitive passed to the render module via 62 pushVertex() 63 */ 64 enum PrimitiveType 65 { 66 PRIMITIVE_TYPE_UNKNOWN, 67 PRIMITIVE_TYPE_TRIANGLE, 68 PRIMITIVE_TYPE_QUAD 69 }; 70 ~IRenderModulecanvas::IRenderModule71 virtual ~IRenderModule() {} 72 73 /// Lock rendermodule against concurrent access 74 virtual void lock() const = 0; 75 76 /// Unlock rendermodule for concurrent access 77 virtual void unlock() const = 0; 78 79 /** Maximal size of VRAM pages available 80 81 This is typically the maximum texture size of the 82 hardware, or some arbitrary limit if the backend is 83 software. 84 */ 85 virtual ::basegfx::B2IVector getPageSize() = 0; 86 87 /** Create a (possibly hardware-accelerated) surface 88 89 @return a pointer to a surface, which is an abstraction of 90 a piece of (possibly hardware-accelerated) texture memory. 91 */ 92 virtual ::boost::shared_ptr<ISurface> createSurface( const ::basegfx::B2IVector& surfaceSize ) = 0; 93 94 /** Begin rendering the given primitive. 95 96 Each beginPrimitive() call must be matched with an 97 endPrimitive() call. 98 */ 99 virtual void beginPrimitive( PrimitiveType eType ) = 0; 100 101 /** Finish rendering a primitive. 102 103 Each beginPrimitive() call must be matched with an 104 endPrimitive() call. 105 */ 106 virtual void endPrimitive() = 0; 107 108 /** Add given vertex to current primitive 109 110 After issuing a beginPrimitive(), each pushVertex() adds a 111 vertex to the active primitive. 112 */ 113 virtual void pushVertex( const Vertex& vertex ) = 0; 114 115 /** Query error status 116 117 @returns true, if an error occurred during primitive 118 construction. 119 */ 120 virtual bool isError() = 0; 121 }; 122 123 typedef ::boost::shared_ptr< IRenderModule > IRenderModuleSharedPtr; 124 125 /// Little RAII wrapper for guarding access to IRenderModule interface 126 class RenderModuleGuard : private ::boost::noncopyable 127 { 128 public: RenderModuleGuard(const IRenderModuleSharedPtr & rRenderModule)129 explicit RenderModuleGuard( const IRenderModuleSharedPtr& rRenderModule ) : 130 mpRenderModule( rRenderModule ) 131 { 132 mpRenderModule->lock(); 133 } 134 ~RenderModuleGuard()135 ~RenderModuleGuard() 136 { 137 mpRenderModule->unlock(); 138 } 139 140 private: 141 const IRenderModuleSharedPtr mpRenderModule; 142 }; 143 } 144 145 #endif /* INCLUDED_CANVAS_IRENDERMODULE_HXX */ 146