• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 __linux__  // Only Linux 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 
26 class ScopedParcel {
27 public:
ScopedParcel(JNIEnv * env,jobject parcel)28     explicit ScopedParcel(JNIEnv* env, jobject parcel) {
29         mParcel = AParcel_fromJavaParcel(env, parcel);
30     }
31 
~ScopedParcel()32     ~ScopedParcel() { AParcel_delete(mParcel); }
33 
34     int32_t readInt32();
35 
36     uint32_t readUint32();
37 
38     int64_t readInt64();
39 
40     float readFloat();
41 
writeInt32(int32_t value)42     void writeInt32(int32_t value) { AParcel_writeInt32(mParcel, value); }
43 
writeUint32(uint32_t value)44     void writeUint32(uint32_t value) { AParcel_writeUint32(mParcel, value); }
45 
writeInt64(int64_t value)46     void writeInt64(int64_t value) { AParcel_writeInt64(mParcel, value); }
47 
writeFloat(float value)48     void writeFloat(float value) { AParcel_writeFloat(mParcel, value); }
49 
allowFds()50     bool allowFds() const { return AParcel_getAllowFds(mParcel); }
51 
52     std::optional<sk_sp<SkData>> readData();
53 
54     void writeData(const std::optional<sk_sp<SkData>>& optData);
55 
get()56     AParcel* get() { return mParcel; }
57 
58 private:
59     AParcel* mParcel;
60 };
61 
62 enum class BlobType : int32_t {
63     IN_PLACE,
64     ASHMEM,
65 };
66 
67 #endif  // __linux__ // Only Linux support parcel
68