blob: b993dfbb46e2e5552f130242fabcabe402a80d14 [file] [log] [blame]
Jesse Hallfc038bd2016-03-26 22:20:22 -07001/*
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 Hall8b0d55e2016-03-31 19:29:36 -070020#include <utils/String8.h>
21#include <vkjson.h>
Jesse Hallfc038bd2016-03-26 22:20:22 -070022
23namespace android {
24
25// ----------------------------------------------------------------------------
26
27class BpGpuService : public BpInterface<IGpuService>
28{
29public:
Chih-Hung Hsiehc4067912016-05-03 14:03:27 -070030 explicit BpGpuService(const sp<IBinder>& impl) : BpInterface<IGpuService>(impl) {}
Jesse Hallfc038bd2016-03-26 22:20:22 -070031};
32
33IMPLEMENT_META_INTERFACE(GpuService, "android.ui.IGpuService");
34
35status_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 Hall8b0d55e2016-03-31 19:29:36 -070058namespace {
59 status_t cmd_help(int out);
60 status_t cmd_vkjson(int out, int err);
61}
62
Jesse Hallfc038bd2016-03-26 22:20:22 -070063const char* const GpuService::SERVICE_NAME = "gpu";
64
65GpuService::GpuService() {}
66
Jesse Hall8b0d55e2016-03-31 19:29:36 -070067status_t GpuService::shellCommand(int /*in*/, int out, int err,
68 Vector<String16>& args)
Jesse Hallfc038bd2016-03-26 22:20:22 -070069{
Jesse Hall8b0d55e2016-03-31 19:29:36 -070070 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 Hallfc038bd2016-03-26 22:20:22 -070079 return NO_ERROR;
80}
81
Jesse Hall8b0d55e2016-03-31 19:29:36 -070082// ----------------------------------------------------------------------------
83
84namespace {
85
86status_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 Hall3841bf42016-06-12 15:08:28 -070095 " vkjson dump Vulkan properties as JSON\n");
Jesse Hall8b0d55e2016-03-31 19:29:36 -070096 fclose(outs);
97 return NO_ERROR;
98}
99
Jesse Hall3841bf42016-06-12 15:08:28 -0700100void vkjsonPrint(FILE* out) {
101 std::string json = VkJsonInstanceToJson(VkJsonGetInstance());
102 fwrite(json.data(), 1, json.size(), out);
103 fputc('\n', out);
Jesse Hall8b0d55e2016-03-31 19:29:36 -0700104}
105
Jesse Hall3841bf42016-06-12 15:08:28 -0700106status_t cmd_vkjson(int out, int /*err*/) {
Jesse Hall8b0d55e2016-03-31 19:29:36 -0700107 FILE* outs = fdopen(out, "w");
108 if (!outs) {
Jesse Hall3841bf42016-06-12 15:08:28 -0700109 int errnum = errno;
Jesse Hall8b0d55e2016-03-31 19:29:36 -0700110 ALOGE("vkjson: failed to create output stream: %s", strerror(errnum));
111 return -errnum;
112 }
Jesse Hall3841bf42016-06-12 15:08:28 -0700113 vkjsonPrint(outs);
Jesse Hall8b0d55e2016-03-31 19:29:36 -0700114 fclose(outs);
Jesse Hall3841bf42016-06-12 15:08:28 -0700115 return NO_ERROR;
Jesse Hall8b0d55e2016-03-31 19:29:36 -0700116}
117
118} // anonymous namespace
119
Jesse Hallfc038bd2016-03-26 22:20:22 -0700120} // namespace android