Skip to content

Commit dc3cf24

Browse files
committed
Dump layer buffer
Support NV12&ARGB Signed-off-by: lihaihong <haihongx.li@intel.com>
1 parent d526817 commit dc3cf24

7 files changed

Lines changed: 142 additions & 5 deletions

File tree

Android.bp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ cc_defaults {
5151
"libutils",
5252
],
5353

54-
include_dirs: ["vendor/intel/external/drm-hwcomposer"],
54+
include_dirs: [
55+
"vendor/intel/external/drm-hwcomposer",
56+
"hardware/intel/external/minigbm-intel/cros_gralloc",
57+
],
5558

5659
header_libs: [
5760
"android.hardware.graphics.composer3-command-buffer",
@@ -140,6 +143,7 @@ cc_library_shared {
140143
],
141144
cppflags: [
142145
"-DHEADLESS_RESOLUTION_2560_1600",
146+
"-DHWC_DUMP_BUFFER",
143147
],
144148
}
145149

backend/Backend.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121
#include <aidl/android/hardware/graphics/composer3/Composition.h>
2222
#include "BackendManager.h"
2323
#include "bufferinfo/BufferInfoGetter.h"
24-
24+
#ifdef HWC_DUMP_BUFFER
25+
#include "bufferinfo/legacy/BufferInfoMinigbm.h"
26+
#include "utils/properties.h"
27+
#endif
2528
namespace android {
2629

2730
HWC2::Error Backend::ValidateDisplay(HwcDisplay *display, uint32_t *num_types,
@@ -35,6 +38,15 @@ HWC2::Error Backend::ValidateDisplay(HwcDisplay *display, uint32_t *num_types,
3538
if ((uint32_t)l->GetSfType() == (uint32_t)aidl::android::hardware::graphics::composer3::Composition::DISPLAY_DECORATION)
3639
return HWC2::Error::Unsupported;
3740
}
41+
42+
#ifdef HWC_DUMP_BUFFER
43+
char status[PROPERTY_VALUE_MAX] = {0};
44+
property_get("drm.dumpbuffer.on", status, "1");
45+
for (size_t z_order = 0; z_order < layers.size(); ++z_order) {
46+
if (status[0] != '0')
47+
BufferInfoMinigbm::DumpBuffer(display->GetPipe().device, layers[z_order]->GetBufferHandle(), z_order);
48+
}
49+
#endif
3850
int client_start = -1;
3951
size_t client_size = 0;
4052

bufferinfo/legacy/BufferInfoMinigbm.cpp

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include <cstring>
2626

2727
#include "utils/log.h"
28+
#include <cros_gralloc_helpers.h>
29+
#include <i915_private_android_types.h>
2830
namespace android {
2931

3032
LEGACY_BUFFER_INFO_GETTER(BufferInfoMinigbm);
@@ -122,4 +124,91 @@ int BufferInfoMinigbm::ValidateGralloc() {
122124
return 0;
123125
}
124126

127+
void BufferInfoMinigbm::InitializeGralloc1(DrmDevice *drmDevice) {
128+
hw_device_t *device;
129+
130+
struct dri2_drm_display *dri_drm = (struct dri2_drm_display *)calloc(1, sizeof(*dri_drm));
131+
if (!dri_drm)
132+
return;
133+
134+
dri_drm->fd = -1;
135+
int ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID,
136+
(const hw_module_t **)&dri_drm->gralloc);
137+
if (ret) {
138+
return;
139+
}
140+
141+
dri_drm->gralloc_version = dri_drm->gralloc->common.module_api_version;
142+
if (dri_drm->gralloc_version == HARDWARE_MODULE_API_VERSION(1, 0)) {
143+
ret = dri_drm->gralloc->common.methods->open(&dri_drm->gralloc->common, GRALLOC_HARDWARE_MODULE_ID, &device);
144+
if (ret) {
145+
ALOGE("Failed to open device");
146+
return;
147+
} else {
148+
ALOGE("success to open device, Initialize");
149+
dri_drm->gralloc1_dvc = (gralloc1_device_t *)device;
150+
dri_drm->pfn_lock = (GRALLOC1_PFN_LOCK)dri_drm->gralloc1_dvc->getFunction(dri_drm->gralloc1_dvc, GRALLOC1_FUNCTION_LOCK);
151+
dri_drm->pfn_importBuffer = (GRALLOC1_PFN_IMPORT_BUFFER)dri_drm->gralloc1_dvc->getFunction(dri_drm->gralloc1_dvc, GRALLOC1_FUNCTION_IMPORT_BUFFER);
152+
dri_drm->pfn_release = (GRALLOC1_PFN_RELEASE)dri_drm->gralloc1_dvc->getFunction(dri_drm->gralloc1_dvc, GRALLOC1_FUNCTION_RELEASE);
153+
dri_drm->pfn_unlock = (GRALLOC1_PFN_UNLOCK)dri_drm->gralloc1_dvc->getFunction(dri_drm->gralloc1_dvc, GRALLOC1_FUNCTION_UNLOCK);
154+
dri_drm->pfn_get_stride = (GRALLOC1_PFN_GET_STRIDE)dri_drm->gralloc1_dvc->getFunction(dri_drm->gralloc1_dvc, GRALLOC1_FUNCTION_GET_STRIDE);
155+
drmDevice->dri_drm_ = (void *)dri_drm;
156+
}
157+
}
158+
return;
159+
}
160+
161+
void BufferInfoMinigbm::DumpBuffer(DrmDevice *drmDevice, buffer_handle_t handle, int z_order) {
162+
if (NULL == handle)
163+
return;
164+
char dump_file[256] = {0};
165+
buffer_handle_t handle_copy;
166+
uint8_t* pixels = nullptr;
167+
cros_gralloc_handle *gr_handle = (cros_gralloc_handle *)handle;
168+
gralloc1_rect_t accessRegion = {0, 0, (int32_t)gr_handle->width, (int32_t)gr_handle->height};;
169+
170+
struct dri2_drm_display *dri_drm = (struct dri2_drm_display *)drmDevice->dri_drm_;
171+
172+
assert (dri_drm == nullptr ||
173+
dri_drm->pfn_importBuffer == nullptr ||
174+
dri_drm->pfn_lock == nullptr ||
175+
dri_drm->pfn_unlock == nullptr ||
176+
dri_drm->pfn_release == nullptr ||
177+
dri_drm->pfn_get_stride);
178+
179+
int ret = dri_drm->pfn_importBuffer(dri_drm->gralloc1_dvc, handle, &handle_copy);
180+
if (ret) {
181+
ALOGE("Gralloc importBuffer failed");
182+
return;
183+
}
184+
ret = dri_drm->pfn_lock(dri_drm->gralloc1_dvc, handle_copy,
185+
GRALLOC1_CONSUMER_USAGE_CPU_READ_OFTEN, GRALLOC1_PRODUCER_USAGE_CPU_WRITE_NEVER,
186+
&accessRegion, reinterpret_cast<void**>(&pixels), 0);
187+
if (ret) {
188+
ALOGE("gralloc->lock failed: %d", ret);
189+
return;
190+
} else {
191+
char ctime[32];
192+
time_t t = time(0);
193+
static int i = 0;
194+
strftime(ctime, sizeof(ctime), "%Y-%m-%d", localtime(&t));
195+
sprintf(dump_file, "/data/local/traces/dump_%d_%dx%d_%s_%d", z_order, gr_handle->width, gr_handle->height, ctime,i++);
196+
int file_fd = 0;
197+
file_fd = open(dump_file, O_RDWR|O_CREAT, 0666);
198+
if (file_fd == -1) {
199+
ALOGE("Failed to open %s while dumping", dump_file);
200+
} else {
201+
size_t size = 0;
202+
if (gr_handle->usage & GRALLOC_USAGE_HW_VIDEO_ENCODER)
203+
size = gr_handle->width * gr_handle->height * 1.5;
204+
else
205+
size = gr_handle->width * gr_handle->height * 4;
206+
write(file_fd, pixels, size);
207+
close(file_fd);
208+
}
209+
int outReleaseFence = 0;
210+
dri_drm->pfn_unlock(dri_drm->gralloc1_dvc, handle_copy, &outReleaseFence);
211+
dri_drm->pfn_release(dri_drm->gralloc1_dvc, handle_copy);
212+
}
213+
}
125214
} // namespace android

bufferinfo/legacy/BufferInfoMinigbm.h

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,42 @@
1818
#define BUFFERINFOMINIGBM_H_
1919

2020
#include <hardware/gralloc.h>
21-
21+
#include <hardware/gralloc1.h>
2222
#include "bufferinfo/BufferInfoGetter.h"
2323

24+
#define DRV_MAX_PLANES 4
25+
#define DRV_MAX_FDS (DRV_MAX_PLANES + 1)
26+
27+
enum INITIALIZE_ERROR{
28+
INITIALIZE_CALLOC_ERROR = 1,
29+
INITIALIZE_GET_MODULE_ERROR,
30+
INITIALIZE_OPEN_DEVICE_ERROR,
31+
INITIALIZE_NONE = 0,
32+
};
33+
34+
struct dri2_drm_display
35+
{
36+
int fd;
37+
const gralloc_module_t *gralloc;
38+
uint16_t gralloc_version;
39+
gralloc1_device_t *gralloc1_dvc;
40+
GRALLOC1_PFN_LOCK pfn_lock;
41+
GRALLOC1_PFN_GET_FORMAT pfn_getFormat;
42+
GRALLOC1_PFN_UNLOCK pfn_unlock;
43+
GRALLOC1_PFN_IMPORT_BUFFER pfn_importBuffer;
44+
GRALLOC1_PFN_RELEASE pfn_release;
45+
GRALLOC1_PFN_GET_STRIDE pfn_get_stride;
46+
};
47+
2448
namespace android {
2549

2650
class BufferInfoMinigbm : public LegacyBufferInfoGetter {
2751
public:
2852
using LegacyBufferInfoGetter::LegacyBufferInfoGetter;
2953
auto GetBoInfo(buffer_handle_t handle) -> std::optional<BufferInfo> override;
3054
int ValidateGralloc() override;
55+
static void InitializeGralloc1(DrmDevice *drmDevice);
56+
static void DumpBuffer(DrmDevice *drmDevice, buffer_handle_t handle, int z_order);
3157
};
3258

3359
} // namespace android

drm/DrmDevice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ class DrmDevice {
136136
bool planes_enabling_;
137137
uint32_t planes_num_;
138138
bool color_adjustment_enabling_;
139+
void *dri_drm_;
139140
};
140141
} // namespace android
141142

hwc2_device/HwcDisplay.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
#include "utils/properties.h"
2828
#include <sync/sync.h>
2929
#include <cinttypes>
30-
30+
#ifdef HWC_DUMP_BUFFER
31+
#include "bufferinfo/legacy/BufferInfoMinigbm.h"
32+
#endif
3133
namespace android {
3234

3335
std::string HwcDisplay::DumpDelta(HwcDisplay::Stats delta) {
@@ -168,7 +170,9 @@ HWC2::Error HwcDisplay::Init() {
168170
}
169171

170172
client_layer_.SetLayerBlendMode(HWC2_BLEND_MODE_PREMULTIPLIED);
171-
173+
#ifdef HWC_DUMP_BUFFER
174+
BufferInfoMinigbm::InitializeGralloc1(pipeline_->device);
175+
#endif
172176
return HWC2::Error::None;
173177
}
174178

hwc2_device/HwcLayer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class HwcLayer {
118118
return !bi_get_failed_ && !fb_import_failed_ && buffer_handle_ != nullptr;
119119
}
120120

121+
buffer_handle_t GetBufferHandle() {return buffer_handle_;}
121122
private:
122123
void ImportFb();
123124
bool bi_get_failed_{};

0 commit comments

Comments
 (0)