1 /*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "pointer_style.h"
17
18 #include "pixel_map.h"
19
20 namespace OHOS {
21 namespace MMI {
CustomCursorParcel(void * pixelMap,int32_t focusX,int32_t focusY)22 CustomCursorParcel::CustomCursorParcel(void* pixelMap, int32_t focusX, int32_t focusY)
23 : Parcelable(), pixelMap(pixelMap), focusX(focusX), focusY(focusY) {}
24
Marshalling(Parcel & out) const25 bool CustomCursorParcel::Marshalling(Parcel &out) const
26 {
27 if (pixelMap == nullptr) {
28 return false;
29 }
30 OHOS::Media::PixelMap* pixelMapPtr = static_cast<OHOS::Media::PixelMap*>(pixelMap);
31 if (pixelMapPtr->GetCapacity() == 0) {
32 return false;
33 }
34
35 if (!pixelMapPtr->Marshalling(out)) {
36 return false;
37 }
38 if (!out.WriteInt32(focusX)) {
39 return false;
40 }
41 if (!out.WriteInt32(focusY)) {
42 return false;
43 }
44 return true;
45 }
46
ReadFromParcel(Parcel & in)47 bool CustomCursorParcel::ReadFromParcel(Parcel &in)
48 {
49 OHOS::Media::PixelMap* pixelMapPtr = Media::PixelMap::Unmarshalling(in);
50 if (pixelMapPtr == nullptr) {
51 return false;
52 }
53 pixelMap = (void *)pixelMapPtr;
54 return (
55 in.ReadInt32(focusX) &&
56 in.ReadInt32(focusY)
57 );
58 }
59
Unmarshalling(Parcel & in)60 CustomCursorParcel *CustomCursorParcel::Unmarshalling(Parcel &in)
61 {
62 CustomCursorParcel *data = new (std::nothrow) CustomCursorParcel();
63 if (data && !data->ReadFromParcel(in)) {
64 delete data;
65 data = nullptr;
66 }
67 return data;
68 }
69
Marshalling(Parcel & out) const70 bool CursorOptionsParcel::Marshalling(Parcel &out) const
71 {
72 if (!out.WriteBool(followSystem)) {
73 return false;
74 }
75 return true;
76 }
77
ReadFromParcel(Parcel & in)78 bool CursorOptionsParcel::ReadFromParcel(Parcel &in)
79 {
80 if (!in.ReadBool(followSystem)) {
81 return false;
82 }
83 return true;
84 }
85
Unmarshalling(Parcel & in)86 CursorOptionsParcel *CursorOptionsParcel::Unmarshalling(Parcel &in)
87 {
88 CursorOptionsParcel *data = new (std::nothrow) CursorOptionsParcel();
89 if (data && !data->ReadFromParcel(in)) {
90 delete data;
91 data = nullptr;
92 }
93 return data;
94 }
95
Marshalling(Parcel & out) const96 bool CursorPixelMap::Marshalling(Parcel &out) const
97 {
98 if (pixelMap == nullptr) {
99 return false;
100 }
101 OHOS::Media::PixelMap* pixelMapPtr = static_cast<OHOS::Media::PixelMap*>(pixelMap);
102 if (pixelMapPtr->GetCapacity() == 0) {
103 return false;
104 }
105
106 if (!pixelMapPtr->Marshalling(out)) {
107 return false;
108 }
109 return true;
110 }
111
ReadFromParcel(Parcel & in)112 bool CursorPixelMap::ReadFromParcel(Parcel &in)
113 {
114 OHOS::Media::PixelMap* pixelMapPtr = Media::PixelMap::Unmarshalling(in);
115 if (pixelMapPtr == nullptr) {
116 return false;
117 }
118 pixelMap = (void *)pixelMapPtr;
119 return true;
120 }
121
Unmarshalling(Parcel & in)122 CursorPixelMap *CursorPixelMap::Unmarshalling(Parcel &in)
123 {
124 CursorPixelMap *data = new (std::nothrow) CursorPixelMap();
125 if (data && !data->ReadFromParcel(in)) {
126 delete data;
127 data = nullptr;
128 }
129 return data;
130 }
131 } // namespace MMI
132 } // namespace OHOS