blob: fd8d6a210f0f77bd0b868567e39dfd67559f88e1 [file] [log] [blame]
Sally Qi9d2d9342023-02-06 11:11:31 -08001/*
2 * Copyright (C) 2023 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#include "SkData.h"
17
18#ifdef __ANDROID__ // Layoutlib does not support parcel
19#include <android-base/unique_fd.h>
20#include <android/binder_parcel.h>
21#include <android/binder_parcel_jni.h>
22#include <android/binder_parcel_platform.h>
23#include <cutils/ashmem.h>
24#include <renderthread/RenderProxy.h>
25
26class ScopedParcel {
27public:
28 explicit ScopedParcel(JNIEnv* env, jobject parcel) {
29 mParcel = AParcel_fromJavaParcel(env, parcel);
30 }
31
32 ~ScopedParcel() { AParcel_delete(mParcel); }
33
34 int32_t readInt32();
35
36 uint32_t readUint32();
37
38 float readFloat();
39
40 void writeInt32(int32_t value) { AParcel_writeInt32(mParcel, value); }
41
42 void writeUint32(uint32_t value) { AParcel_writeUint32(mParcel, value); }
43
44 void writeFloat(float value) { AParcel_writeFloat(mParcel, value); }
45
46 bool allowFds() const { return AParcel_getAllowFds(mParcel); }
47
48 std::optional<sk_sp<SkData>> readData();
49
50 void writeData(const std::optional<sk_sp<SkData>>& optData);
51
52 AParcel* get() { return mParcel; }
53
54private:
55 AParcel* mParcel;
56};
57
58enum class BlobType : int32_t {
59 IN_PLACE,
60 ASHMEM,
61};
62
63#endif // __ANDROID__ // Layoutlib does not support parcel