Jesse Hall | fc038bd | 2016-03-26 22:20:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | |
| 17 | #include "GpuService.h" |
| 18 | |
Jesse Hall | c0b1577 | 2016-12-20 14:47:45 -0800 | [diff] [blame] | 19 | #include <binder/IResultReceiver.h> |
Jesse Hall | fc038bd | 2016-03-26 22:20:22 -0700 | [diff] [blame] | 20 | #include <binder/Parcel.h> |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 21 | #include <utils/String8.h> |
| 22 | #include <vkjson.h> |
Jesse Hall | fc038bd | 2016-03-26 22:20:22 -0700 | [diff] [blame] | 23 | |
| 24 | namespace android { |
| 25 | |
Peiyong Lin | 2da7465 | 2018-11-01 10:34:57 -0700 | [diff] [blame] | 26 | class BpGpuService : public BpInterface<IGpuService> { |
Jesse Hall | fc038bd | 2016-03-26 22:20:22 -0700 | [diff] [blame] | 27 | public: |
Chih-Hung Hsieh | c406791 | 2016-05-03 14:03:27 -0700 | [diff] [blame] | 28 | explicit BpGpuService(const sp<IBinder>& impl) : BpInterface<IGpuService>(impl) {} |
Jesse Hall | fc038bd | 2016-03-26 22:20:22 -0700 | [diff] [blame] | 29 | }; |
| 30 | |
| 31 | IMPLEMENT_META_INTERFACE(GpuService, "android.ui.IGpuService"); |
| 32 | |
| 33 | status_t BnGpuService::onTransact(uint32_t code, const Parcel& data, |
Peiyong Lin | 2da7465 | 2018-11-01 10:34:57 -0700 | [diff] [blame] | 34 | Parcel* reply, uint32_t flags) { |
Jesse Hall | c0b1577 | 2016-12-20 14:47:45 -0800 | [diff] [blame] | 35 | status_t status; |
Jesse Hall | fc038bd | 2016-03-26 22:20:22 -0700 | [diff] [blame] | 36 | switch (code) { |
| 37 | case SHELL_COMMAND_TRANSACTION: { |
| 38 | int in = data.readFileDescriptor(); |
| 39 | int out = data.readFileDescriptor(); |
| 40 | int err = data.readFileDescriptor(); |
Peiyong Lin | 2da7465 | 2018-11-01 10:34:57 -0700 | [diff] [blame] | 41 | std::vector<String16> args; |
| 42 | data.readString16Vector(&args); |
Jesse Hall | c0b1577 | 2016-12-20 14:47:45 -0800 | [diff] [blame] | 43 | sp<IBinder> unusedCallback; |
| 44 | sp<IResultReceiver> resultReceiver; |
| 45 | if ((status = data.readNullableStrongBinder(&unusedCallback)) != OK) |
| 46 | return status; |
| 47 | if ((status = data.readNullableStrongBinder(&resultReceiver)) != OK) |
| 48 | return status; |
| 49 | status = shellCommand(in, out, err, args); |
| 50 | if (resultReceiver != nullptr) |
| 51 | resultReceiver->send(status); |
| 52 | return OK; |
Jesse Hall | fc038bd | 2016-03-26 22:20:22 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | default: |
| 56 | return BBinder::onTransact(code, data, reply, flags); |
| 57 | } |
| 58 | } |
| 59 | |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 60 | namespace { |
| 61 | status_t cmd_help(int out); |
| 62 | status_t cmd_vkjson(int out, int err); |
| 63 | } |
| 64 | |
Yiwei Zhang | 423d080 | 2018-11-16 10:56:12 -0800 | [diff] [blame^] | 65 | const char* const GpuService::SERVICE_NAME = "gpu"; |
Jesse Hall | fc038bd | 2016-03-26 22:20:22 -0700 | [diff] [blame] | 66 | |
Peiyong Lin | 2da7465 | 2018-11-01 10:34:57 -0700 | [diff] [blame] | 67 | GpuService::GpuService() = default; |
Jesse Hall | fc038bd | 2016-03-26 22:20:22 -0700 | [diff] [blame] | 68 | |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 69 | status_t GpuService::shellCommand(int /*in*/, int out, int err, |
Peiyong Lin | 2da7465 | 2018-11-01 10:34:57 -0700 | [diff] [blame] | 70 | std::vector<String16>& args) { |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 71 | ALOGV("GpuService::shellCommand"); |
| 72 | for (size_t i = 0, n = args.size(); i < n; i++) |
| 73 | ALOGV(" arg[%zu]: '%s'", i, String8(args[i]).string()); |
| 74 | |
Jesse Hall | 3e26b13 | 2016-12-20 14:31:28 -0800 | [diff] [blame] | 75 | if (args.size() >= 1) { |
| 76 | if (args[0] == String16("vkjson")) |
| 77 | return cmd_vkjson(out, err); |
| 78 | if (args[0] == String16("help")) |
| 79 | return cmd_help(out); |
| 80 | } |
| 81 | // no command, or unrecognized command |
| 82 | cmd_help(err); |
| 83 | return BAD_VALUE; |
Jesse Hall | fc038bd | 2016-03-26 22:20:22 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 86 | namespace { |
| 87 | |
| 88 | status_t cmd_help(int out) { |
| 89 | FILE* outs = fdopen(out, "w"); |
| 90 | if (!outs) { |
| 91 | ALOGE("vkjson: failed to create out stream: %s (%d)", strerror(errno), |
| 92 | errno); |
| 93 | return BAD_VALUE; |
| 94 | } |
| 95 | fprintf(outs, |
| 96 | "GPU Service commands:\n" |
Jesse Hall | 3841bf4 | 2016-06-12 15:08:28 -0700 | [diff] [blame] | 97 | " vkjson dump Vulkan properties as JSON\n"); |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 98 | fclose(outs); |
| 99 | return NO_ERROR; |
| 100 | } |
| 101 | |
Jesse Hall | 3841bf4 | 2016-06-12 15:08:28 -0700 | [diff] [blame] | 102 | void vkjsonPrint(FILE* out) { |
| 103 | std::string json = VkJsonInstanceToJson(VkJsonGetInstance()); |
| 104 | fwrite(json.data(), 1, json.size(), out); |
| 105 | fputc('\n', out); |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Jesse Hall | 3841bf4 | 2016-06-12 15:08:28 -0700 | [diff] [blame] | 108 | status_t cmd_vkjson(int out, int /*err*/) { |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 109 | FILE* outs = fdopen(out, "w"); |
| 110 | if (!outs) { |
Jesse Hall | 3841bf4 | 2016-06-12 15:08:28 -0700 | [diff] [blame] | 111 | int errnum = errno; |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 112 | ALOGE("vkjson: failed to create output stream: %s", strerror(errnum)); |
| 113 | return -errnum; |
| 114 | } |
Jesse Hall | 3841bf4 | 2016-06-12 15:08:28 -0700 | [diff] [blame] | 115 | vkjsonPrint(outs); |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 116 | fclose(outs); |
Jesse Hall | 3841bf4 | 2016-06-12 15:08:28 -0700 | [diff] [blame] | 117 | return NO_ERROR; |
Jesse Hall | 8b0d55e | 2016-03-31 19:29:36 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | } // anonymous namespace |
| 121 | |
Jesse Hall | fc038bd | 2016-03-26 22:20:22 -0700 | [diff] [blame] | 122 | } // namespace android |