blob: dc1d3f06f55adda42146bb63d71ef4028d30aed0 [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
Jesse Hall3e26b132016-12-20 14:31:28 -080074 if (args.size() >= 1) {
75 if (args[0] == String16("vkjson"))
76 return cmd_vkjson(out, err);
77 if (args[0] == String16("help"))
78 return cmd_help(out);
79 }
80 // no command, or unrecognized command
81 cmd_help(err);
82 return BAD_VALUE;
Jesse Hallfc038bd2016-03-26 22:20:22 -070083}
84
Jesse Hall8b0d55e2016-03-31 19:29:36 -070085// ----------------------------------------------------------------------------
86
87namespace {
88
89status_t cmd_help(int out) {
90 FILE* outs = fdopen(out, "w");
91 if (!outs) {
92 ALOGE("vkjson: failed to create out stream: %s (%d)", strerror(errno),
93 errno);
94 return BAD_VALUE;
95 }
96 fprintf(outs,
97 "GPU Service commands:\n"
Jesse Hall3841bf42016-06-12 15:08:28 -070098 " vkjson dump Vulkan properties as JSON\n");
Jesse Hall8b0d55e2016-03-31 19:29:36 -070099 fclose(outs);
100 return NO_ERROR;
101}
102
Jesse Hall3841bf42016-06-12 15:08:28 -0700103void vkjsonPrint(FILE* out) {
104 std::string json = VkJsonInstanceToJson(VkJsonGetInstance());
105 fwrite(json.data(), 1, json.size(), out);
106 fputc('\n', out);
Jesse Hall8b0d55e2016-03-31 19:29:36 -0700107}
108
Jesse Hall3841bf42016-06-12 15:08:28 -0700109status_t cmd_vkjson(int out, int /*err*/) {
Jesse Hall8b0d55e2016-03-31 19:29:36 -0700110 FILE* outs = fdopen(out, "w");
111 if (!outs) {
Jesse Hall3841bf42016-06-12 15:08:28 -0700112 int errnum = errno;
Jesse Hall8b0d55e2016-03-31 19:29:36 -0700113 ALOGE("vkjson: failed to create output stream: %s", strerror(errnum));
114 return -errnum;
115 }
Jesse Hall3841bf42016-06-12 15:08:28 -0700116 vkjsonPrint(outs);
Jesse Hall8b0d55e2016-03-31 19:29:36 -0700117 fclose(outs);
Jesse Hall3841bf42016-06-12 15:08:28 -0700118 return NO_ERROR;
Jesse Hall8b0d55e2016-03-31 19:29:36 -0700119}
120
121} // anonymous namespace
122
Jesse Hallfc038bd2016-03-26 22:20:22 -0700123} // namespace android