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