2 * Copyright 2016 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "GpuService.h"
19 #include <binder/IResultReceiver.h>
20 #include <binder/Parcel.h>
21 #include <utils/String8.h>
26 // ----------------------------------------------------------------------------
28 class BpGpuService : public BpInterface<IGpuService>
31 explicit BpGpuService(const sp<IBinder>& impl) : BpInterface<IGpuService>(impl) {}
34 IMPLEMENT_META_INTERFACE(GpuService, "android.ui.IGpuService");
36 status_t BnGpuService::onTransact(uint32_t code, const Parcel& data,
37 Parcel* reply, uint32_t flags)
41 case SHELL_COMMAND_TRANSACTION: {
42 int in = data.readFileDescriptor();
43 int out = data.readFileDescriptor();
44 int err = data.readFileDescriptor();
45 int argc = data.readInt32();
46 Vector<String16> args;
47 for (int i = 0; i < argc && data.dataAvail() > 0; i++) {
48 args.add(data.readString16());
50 sp<IBinder> unusedCallback;
51 sp<IResultReceiver> resultReceiver;
52 if ((status = data.readNullableStrongBinder(&unusedCallback)) != OK)
54 if ((status = data.readNullableStrongBinder(&resultReceiver)) != OK)
56 status = shellCommand(in, out, err, args);
57 if (resultReceiver != nullptr)
58 resultReceiver->send(status);
63 return BBinder::onTransact(code, data, reply, flags);
67 // ----------------------------------------------------------------------------
70 status_t cmd_help(int out);
71 status_t cmd_vkjson(int out, int err);
74 const char* const GpuService::SERVICE_NAME = "gpu";
76 GpuService::GpuService() {}
78 status_t GpuService::shellCommand(int /*in*/, int out, int err,
79 Vector<String16>& args)
81 ALOGV("GpuService::shellCommand");
82 for (size_t i = 0, n = args.size(); i < n; i++)
83 ALOGV(" arg[%zu]: '%s'", i, String8(args[i]).string());
85 if (args.size() >= 1) {
86 if (args[0] == String16("vkjson"))
87 return cmd_vkjson(out, err);
88 if (args[0] == String16("help"))
91 // no command, or unrecognized command
96 // ----------------------------------------------------------------------------
100 status_t cmd_help(int out) {
101 FILE* outs = fdopen(out, "w");
103 ALOGE("vkjson: failed to create out stream: %s (%d)", strerror(errno),
108 "GPU Service commands:\n"
109 " vkjson dump Vulkan properties as JSON\n");
114 void vkjsonPrint(FILE* out) {
115 std::string json = VkJsonInstanceToJson(VkJsonGetInstance());
116 fwrite(json.data(), 1, json.size(), out);
120 status_t cmd_vkjson(int out, int /*err*/) {
121 FILE* outs = fdopen(out, "w");
124 ALOGE("vkjson: failed to create output stream: %s", strerror(errnum));
132 } // anonymous namespace
134 } // namespace android