summaryrefslogtreecommitdiff
path: root/gralloc960/mali_gralloc_debug.cpp
blob: 3737fbca802c508bc283adaa98c65ccadbe93c95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
 * Copyright (C) 2016 ARM Limited. All rights reserved.
 *
 * Copyright (C) 2008 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * You may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <inttypes.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>

#if GRALLOC_USE_GRALLOC1_API == 1
#include <hardware/gralloc1.h>
#else
#include <hardware/gralloc.h>
#endif
#include <hardware/hardware.h>

#include "mali_gralloc_module.h"
#include "gralloc_priv.h"
#include "mali_gralloc_debug.h"

static pthread_mutex_t dump_lock = PTHREAD_MUTEX_INITIALIZER;
static std::vector<private_handle_t *> dump_buffers;
static android::String8 dumpStrings;

void mali_gralloc_dump_buffer_add(private_handle_t *handle)
{
	if (NULL == handle)
	{
		ALOGE("Invalid handle %p and return", handle);
		return;
	}

	pthread_mutex_lock(&dump_lock);
	dump_buffers.push_back(handle);
	pthread_mutex_unlock(&dump_lock);
}

void mali_gralloc_dump_buffer_erase(private_handle_t *handle)
{
	if (NULL == handle)
	{
		ALOGE("Invalid handle %p and return", handle);
		return;
	}

	pthread_mutex_lock(&dump_lock);
	dump_buffers.erase(std::remove(dump_buffers.begin(), dump_buffers.end(), handle));
	pthread_mutex_unlock(&dump_lock);
}

void mali_gralloc_dump_string(android::String8 &buf, const char *fmt, ...)
{
	va_list args;
	va_start(args, fmt);
	buf.appendFormatV(fmt, args);
	va_end(args);
}

void mali_gralloc_dump_buffers(android::String8 &dumpStrings, uint32_t *outSize)
{
	if (NULL == outSize)
	{
		ALOGE("Invalid pointer to dump buffer size and return");
		return;
	}

	dumpStrings.clear();
	mali_gralloc_dump_string(dumpStrings,
	                         "-------------------------Start to dump Gralloc buffers info------------------------\n");
	private_handle_t *hnd;
	size_t num;

	mali_gralloc_dump_string(dumpStrings, "    handle  | width | height | stride |   req format   |internal "
	                                      "format|consumer usage|producer usage| shared fd | AFBC "
	                                      "|\n");
	mali_gralloc_dump_string(dumpStrings, "------------+-------+--------+--------+----------------+---------------+----"
	                                      "----------+--------------+-----------+------+\n");
	pthread_mutex_lock(&dump_lock);

	for (num = 0; num < dump_buffers.size(); num++)
	{
		hnd = dump_buffers[num];
		mali_gralloc_dump_string(dumpStrings, " %08" PRIxPTR " | %5d |  %5d |  %5d |    %08x    |    %09" PRIx64
		                                      "  |   %09" PRIx64 "  |   %09" PRIx64 "  |  %08x | %4d |\n",
		                         hnd, hnd->width, hnd->height, hnd->stride, hnd->req_format, hnd->internal_format,
		                         hnd->consumer_usage, hnd->producer_usage, hnd->share_fd,
		                         (hnd->internal_format & MALI_GRALLOC_INTFMT_AFBCENABLE_MASK) ? true : false);
	}

	pthread_mutex_unlock(&dump_lock);
	mali_gralloc_dump_string(
	    dumpStrings, "---------------------End dump Gralloc buffers info with num %zu----------------------\n", num);

	*outSize = dumpStrings.size();
}

void mali_gralloc_dump_internal(uint32_t *outSize, char *outBuffer)
{
	uint32_t dumpSize;

	if (NULL == outSize)
	{
		ALOGE("Invalid pointer to dump buffer size and return");
		return;
	}

	if (NULL == outBuffer)
	{
		if (!dumpStrings.empty())
		{
			dumpStrings.clear();
		}

		mali_gralloc_dump_buffers(dumpStrings, outSize);
	}
	else
	{
		if (dumpStrings.empty())
		{
			*outSize = 0;
		}
		else
		{
			dumpSize = dumpStrings.size();
			*outSize = (dumpSize < *outSize) ? dumpSize : *outSize;
			memcpy(outBuffer, dumpStrings.c_str(), *outSize);
		}
	}
}