1 module awebview.wrapper.cpp.bitmapsurface; 2 3 import awebview.wrapper.cpp; 4 import awebview.wrapper.cpp.surface; 5 6 mixin template Awesomium() 7 { 8 interface BitmapSurface : Awesomium.Surface {} 9 interface BitmapSurfaceFactory : SurfaceFactory {} 10 } 11 12 mixin template Awesomium4D() 13 { 14 extern(C++, BitmapSurfaceMember) 15 { 16 size_t sizeOfInstance(); 17 void ctor(Awesomium.BitmapSurface p, int width, int height); 18 Awesomium.BitmapSurface newCtor(int width, int height); 19 void dtor(Awesomium.BitmapSurface p); 20 void deleteDtor(Awesomium.BitmapSurface p); 21 const(char)* buffer(const Awesomium.BitmapSurface p) ; 22 int width(const Awesomium.BitmapSurface p); 23 int height(const Awesomium.BitmapSurface p); 24 int row_span(const Awesomium.BitmapSurface p); 25 void set_is_dirty(Awesomium.BitmapSurface p, bool is_dirty); 26 bool is_dirty(const Awesomium.BitmapSurface p); 27 28 void CopyTo(const Awesomium.BitmapSurface p, char* dest_buffer, 29 int dest_row_span, 30 int dest_depth, 31 bool convert_to_rgba, 32 bool flip_y); 33 34 bool SaveToPNG(const Awesomium.BitmapSurface p, const WebString file_path, 35 bool preserve_transparency); 36 37 char GetAlphaAtPoint(const Awesomium.BitmapSurface p, int x, int y); 38 39 void Paint(Awesomium.BitmapSurface p, char* src_buffer, 40 int src_row_span, 41 const(Rect)* src_rect, 42 const(Rect)* dest_rect); 43 44 void Scroll(Awesomium.BitmapSurface p, int dx, int dy, const(Rect)* clip_rect); 45 } 46 47 48 extern(C++, BitmapSurfaceFactoryMember) 49 { 50 size_t sizeOfInstance(); 51 void ctor(Awesomium.BitmapSurfaceFactory p); 52 Awesomium.BitmapSurfaceFactory newCtor(); 53 void dtor(Awesomium.BitmapSurfaceFactory p); 54 void deleteDtor(Awesomium.BitmapSurfaceFactory p); 55 Awesomium.Surface CreateSurface(Awesomium.BitmapSurfaceFactory p, Awesomium.WebView view, int width, int height); 56 void DestroySurface(Awesomium.BitmapSurfaceFactory p, Awesomium.Surface surface); 57 } 58 } 59 60 /* 61 final class BitmapSurface : ISurface 62 { 63 alias CppObjType = Awesomium.BitmapSurface; 64 65 this(CppObjType cppObj, bool manage) { _obj = cppObj; _manage = manage; } 66 this(int width, int height) { this(AweBmSurfMem.newCtor(width, height), true); } 67 ~this() { if(_manage) AweBmSurfMem.deleteDtor(_obj); } 68 69 const(char)* bufferPtr() const @property { return AweBmSurfMem.buffer(_obj); } 70 const(char)[] buffer() const @property { return this.bufferPtr[0 .. 4 * this.width * this.height]; } 71 72 size_t width() const @property 73 { 74 int w = AweBmSurfMem.width(_obj); 75 assert(w >= 0); 76 return w; 77 } 78 79 size_t height() const @property 80 { 81 int h = AweBmSurfMem.height(_obj); 82 assert(h >= 0); 83 return h; 84 } 85 86 size_t rowSpan() const @property 87 { 88 int ws = AweBmSurfMem.row_span(_obj); 89 assert(ws >= 0); 90 return ws; 91 } 92 93 void isDirty(bool b) @property { AweBmSurfMem.set_is_dirty(_obj, b); } 94 bool isDirty(bool b) const @property { return AweBmSurfMem.is_dirty(_obj); } 95 96 void copyTo(const(char)* dst, int dstRowSpan, int dstDepth, bool convToRGBA, bool flipY) const 97 { AweBmSurfMem.CopyTo(_obj, dst, dstRowSpan, dstDepth, convToRGBA, flipY); } 98 99 bool saveToPNG(string path, bool presTrans = false) const 100 { 101 auto str = WebString(path); 102 return AweBmSurfMem.SaveToPNG(str.cppObj, presTrans); 103 } 104 105 bool saveToJPEG(string path, uint quality = 90) const 106 { 107 auto str = WebString(path); 108 return AweBmSurfMem.SaveToJPEG(str.cppObj, quality); 109 } 110 111 override 112 { 113 void print(const(char)* src, int srcRowSpan, const(Rect)* sr, const(Rect)* dr) 114 { AweBmSurfMem.Paint(src, srcRowSpan, sr, dr); } 115 116 void scroll(int dx, int dy, const(Rect)* cr) 117 { AweBmSurfMem.Scroll(dx, dy, cr); } 118 119 inout(Awesomium.BitmapSurface) cppObj() inout @property { return _obj; } 120 121 void paint(const(char)* src, uint srcRowSpan, Rect srcR, Rect dstR) 122 { AweBmSurfMem.Paint(src, srcRowSpan, &srcR, &dstR); } 123 124 void scroll(int dx, int dy, Rect clipR) 125 { AweBmSurfMem.Scroll(dx, dy, &clipR); } 126 } 127 128 private: 129 CppObjType _obj; 130 alias AweBmSurfMem = awebview.BitmapSurfaceMember; 131 } 132 133 134 final class BitmapSurfaceFactory : ISurfaceFactory 135 { 136 alias CppObjType = Awesomium.BitmapSurfaceFactory; 137 138 this() { _obj = AweBSFM.newCtor(); } 139 ~this() { AweBSFM.deleteDtor(_obj); } 140 141 142 ISurface createSurface(IWebView view, size_t width, size_t height) 143 in{ 144 assert(width <= int.max); 145 assert(height <= int.max); 146 } 147 body{ 148 Awesomium.Awesomium.Surface cppS = AweBSFM.CreateSurface(_obj, view.cppObj, width, height); 149 return new BitmapSurface(cast(Awesomium.BitmapSurface)cppS); 150 } 151 152 153 void destroySurface(ISurface surf) 154 { 155 AweBSFM.DestroySurface(_obj, surf.cppObj); 156 } 157 158 159 private: 160 CppObjType _obj; 161 alias AweBSFM = awebview.BitmapSurfaceFactoryMember; 162 } 163 */