1 module skia.SKPicture; 2 3 import skia.SKObject; 4 import skia.SkiaApi; 5 import skia.Definitions; 6 import skia.SKData; 7 import skia.SKShader; 8 import skia.SKStream; 9 import skia.MathTypes; 10 import skia.MathTypes; 11 import skia.SKMatrix; 12 import skia.Exceptions; 13 14 class SKPicture : SKObject { 15 this(void* h, bool owns) { 16 super(h, owns); 17 } 18 19 protected override void Dispose(bool disposing) { 20 return super.Dispose(disposing); 21 } 22 23 uint UniqueId() { 24 return SkiaApi.sk_picture_get_unique_id(cast(sk_picture_t*) Handle); 25 } 26 27 SKRect CullRect() { 28 SKRect rect; 29 SkiaApi.sk_picture_get_cull_rect(cast(sk_picture_t*) Handle, &rect); 30 return rect; 31 } 32 33 // Serialize 34 35 // SKData Serialize() { 36 // return SKData.GetObject(SkiaApi.sk_picture_serialize_to_data(cast(sk_picture_t*) Handle)); 37 // } 38 39 // void Serialize (Stream stream) 40 // { 41 // if (stream is null) 42 // throw new ArgumentNullException (stream.stringof); 43 44 // auto managed = new SKManagedWStream (stream); 45 // scope(exit) { 46 // managed.Dispose(); 47 // } 48 49 // Serialize (managed); 50 // } 51 52 // void Serialize(SKWStream stream) { 53 // if (stream is null) 54 // throw new ArgumentNullException(stream.stringof); 55 56 // SkiaApi.sk_picture_serialize_to_stream(cast(sk_picture_t*) Handle, 57 // cast(sk_wstream_t*) stream.Handle); 58 // } 59 60 // ToShader 61 62 SKShader ToShader() { 63 return ToShader(SKShaderTileMode.Clamp, SKShaderTileMode.Clamp); 64 } 65 66 SKShader ToShader(SKShaderTileMode tmx, SKShaderTileMode tmy) { 67 return SKShader.GetObject(SkiaApi.sk_picture_make_shader(cast(sk_picture_t*) Handle, 68 tmx, tmy, null, null)); 69 } 70 71 SKShader ToShader(SKShaderTileMode tmx, SKShaderTileMode tmy, SKRect tile) { 72 return SKShader.GetObject(SkiaApi.sk_picture_make_shader(cast(sk_picture_t*) Handle, 73 tmx, tmy, null, &tile)); 74 } 75 76 SKShader ToShader(SKShaderTileMode tmx, SKShaderTileMode tmy, SKMatrix localMatrix, SKRect tile) { 77 return SKShader.GetObject(SkiaApi.sk_picture_make_shader(cast(sk_picture_t*) Handle, 78 tmx, tmy, &localMatrix, &tile)); 79 } 80 81 // Deserialize 82 83 // static SKPicture Deserialize(void* data, int length) { 84 // if (data is null) 85 // throw new ArgumentNullException(data.stringof); 86 87 // if (length == 0) 88 // return null; 89 90 // return GetObject(SkiaApi.sk_picture_deserialize_from_memory(cast(void*) data, 91 // cast(void*) length)); 92 // } 93 94 // static SKPicture Deserialize(const(byte)[] data) { 95 // if (data.length == 0) 96 // return null; 97 98 // void* ptr = cast(void*) data; 99 // return GetObject(SkiaApi.sk_picture_deserialize_from_memory(ptr, cast(int) data.length)); 100 // } 101 102 // static SKPicture Deserialize(SKData data) { 103 // if (data is null) 104 // throw new ArgumentNullException(data.stringof); 105 106 // return GetObject(SkiaApi.sk_picture_deserialize_from_data(cast(sk_data_t*) data.Handle)); 107 // } 108 109 // static SKPicture Deserialize (Stream stream) 110 // { 111 // if (stream is null) 112 // throw new ArgumentNullException (stream.stringof); 113 114 // auto managed = new SKManagedStream (stream); 115 // scope(exit) { 116 // managed.Dispose(); 117 // } 118 119 // return Deserialize (managed); 120 // } 121 122 // static SKPicture Deserialize(SKStream stream) { 123 // if (stream is null) 124 // throw new ArgumentNullException(stream.stringof); 125 126 // return GetObject(SkiaApi.sk_picture_deserialize_from_stream( 127 // cast(sk_stream_t*) stream.Handle)); 128 // } 129 130 // 131 132 static SKPicture GetObject(void* handle, bool owns = true, bool unrefExisting = true) { 133 return GetOrAddObject!(SKPicture)(handle, delegate SKPicture(h, o) { 134 return new SKPicture(h, o); 135 }); 136 } 137 138 }