2 * Copyright 2015 Xamarin Inc.
3 * Copyright 2017 Microsoft Corporation. All rights reserved.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
9 #include "SkManagedStream.h"
13 static read_delegate fRead = nullptr;
14 static peek_delegate fPeek = nullptr;
15 static isAtEnd_delegate fIsAtEnd = nullptr;
16 static hasPosition_delegate fHasPosition = nullptr;
17 static hasLength_delegate fHasLength = nullptr;
18 static rewind_delegate fRewind = nullptr;
19 static getPosition_delegate fGetPosition = nullptr;
20 static seek_delegate fSeek = nullptr;
21 static move_delegate fMove = nullptr;
22 static getLength_delegate fGetLength = nullptr;
23 static createNew_delegate fCreateNew = nullptr;
24 static destroy_delegate fDestroy = nullptr;
27 static write_delegate fWrite = nullptr;
28 static flush_delegate fFlush = nullptr;
29 static bytesWritten_delegate fBytesWritten = nullptr;
30 static wdestroy_delegate fWDestroy = nullptr;
35 SkManagedStream::SkManagedStream() {
36 this->address = (size_t)this;
39 SkManagedStream::~SkManagedStream() {
43 void SkManagedStream::setDelegates(const read_delegate pRead,
44 const peek_delegate pPeek,
45 const isAtEnd_delegate pIsAtEnd,
46 const hasPosition_delegate pHasPosition,
47 const hasLength_delegate pHasLength,
48 const rewind_delegate pRewind,
49 const getPosition_delegate pGetPosition,
50 const seek_delegate pSeek,
51 const move_delegate pMove,
52 const getLength_delegate pGetLength,
53 const createNew_delegate pCreateNew,
54 const destroy_delegate pDestroy)
58 ::fIsAtEnd = (pIsAtEnd);
59 ::fHasPosition = (pHasPosition);
60 ::fHasLength = (pHasLength);
61 ::fRewind = (pRewind);
62 ::fGetPosition = (pGetPosition);
65 ::fGetLength = (pGetLength);
66 ::fCreateNew = (pCreateNew);
67 ::fDestroy = (pDestroy);
71 size_t SkManagedStream::read(void* buffer, size_t size) {
72 return ::fRead(this, buffer, size);
75 size_t SkManagedStream::peek(void *buffer, size_t size) const {
76 SkManagedStream* nonConstThis = const_cast<SkManagedStream*>(this);
77 return ::fPeek(nonConstThis, buffer, size);
80 bool SkManagedStream::isAtEnd() const {
81 return ::fIsAtEnd(this);
84 bool SkManagedStream::hasPosition() const {
85 return ::fHasPosition(this);
88 bool SkManagedStream::hasLength() const {
89 return ::fHasLength(this);
92 bool SkManagedStream::rewind() {
93 return ::fRewind(this);
96 size_t SkManagedStream::getPosition() const {
97 return ::fGetPosition(this);
100 bool SkManagedStream::seek(size_t position) {
101 return ::fSeek(this, position);
104 bool SkManagedStream::move(long offset) {
105 return ::fMove(this, offset);
108 size_t SkManagedStream::getLength() const {
109 return ::fGetLength(this);
112 SkManagedStream* SkManagedStream::duplicate() const {
113 return ::fCreateNew(this);
116 SkManagedStream* SkManagedStream::fork() const {
117 std::unique_ptr<SkManagedStream> that(::fCreateNew(this));
118 that->seek(getPosition());
119 return that.release();
125 SkManagedWStream::SkManagedWStream() {
126 this->address = (size_t)this;
129 SkManagedWStream::~SkManagedWStream() {
130 ::fWDestroy(address);
133 void SkManagedWStream::setDelegates(const write_delegate pWrite,
134 const flush_delegate pFlush,
135 const bytesWritten_delegate pBytesWritten,
136 const wdestroy_delegate pDestroy)
140 ::fBytesWritten = (pBytesWritten);
141 ::fWDestroy = (pDestroy);
144 bool SkManagedWStream::write(const void* buffer, size_t size) {
145 return ::fWrite(this, buffer, size);
148 void SkManagedWStream::flush() {
152 size_t SkManagedWStream::bytesWritten() const {
153 return ::fBytesWritten(this);