1#include <Application.h>
2#include <DirectWindow.h>
3
4#include <stdio.h>
5
6static const char *
7state_to_string(direct_buffer_state state)
8{
9	//TODO: Return more info like B_CLIPPING_MODIFIED, etc.
10
11	switch (state & B_DIRECT_MODE_MASK) {
12		case B_DIRECT_START:
13			return "B_DIRECT_START";
14		case B_DIRECT_STOP:
15			return "B_DIRECT_STOP";
16		case B_DIRECT_MODIFY:
17			return "B_DIRECT_MODIFY";
18		default:
19			return "other state";
20	}
21}
22
23
24static const char *
25layout_to_string(buffer_layout layout)
26{
27	switch (layout) {
28		case B_BUFFER_NONINTERLEAVED:
29			return "B_BUFFER_NONINTERLEAVED";
30		default:
31			return "unknown buffer_layout";
32	}
33}
34
35
36static const char *
37orientation_to_string(buffer_orientation orientation)
38{
39	switch (orientation) {
40		case B_BUFFER_TOP_TO_BOTTOM:
41			return "B_BUFFER_TOP_TO_BOTTOM";
42		case B_BUFFER_BOTTOM_TO_TOP:
43			return "B_BUFFER_BOTTOM_TO_TOP";
44		default:
45			return "unknown buffer_orientation";
46	}
47}
48
49class TestWindow : public BDirectWindow {
50public:
51	TestWindow() : BDirectWindow(BRect(100, 100, 400, 300), "DWInfo", B_DOCUMENT_WINDOW, 0)
52	{
53
54	}
55
56	virtual void DirectConnected(direct_buffer_info *info)
57	{
58		BRegion region;
59
60		printf("\n\n*** DirectConnected() ***\n");
61		area_id areaId = area_for(info);
62		area_info areaInfo;
63		if (areaId >= 0 && get_area_info(areaId, &areaInfo) == B_OK)
64			printf("area size: %ld\n", areaInfo.size);
65
66		printf("buffer state: %s\n", state_to_string(info->buffer_state));
67		printf("bits: %p\n", info->bits);
68		printf("pci_bits: %p\n", info->pci_bits);
69		printf("bytes_per_row: %ld\n", info->bytes_per_row);
70		printf("bits_per_pixel: %lu\n", info->bits_per_pixel);
71		printf("pixel_format: %d\n", info->pixel_format);
72		printf("buffer_layout: %s\n", layout_to_string(info->layout));
73		printf("buffer_orientation: %s\n", orientation_to_string(info->orientation));
74
75		printf("\nCLIPPING INFO:\n");
76		printf("clipping_rects count: %ld\n", info->clip_list_count);
77
78		printf("- window_bounds:\n");
79		region.Set(info->window_bounds);
80		region.PrintToStream();
81
82		region.MakeEmpty();
83		for (uint32 i = 0; i < info->clip_list_count; i++)
84			region.Include(info->clip_list[i]);
85
86		printf("- clip_list:\n");
87		region.PrintToStream();
88	}
89
90	virtual bool QuitRequested()
91	{
92		be_app->PostMessage(B_QUIT_REQUESTED);
93		return BDirectWindow::QuitRequested();
94	}
95};
96
97
98
99int main()
100{
101	BApplication app("application/x-vnd.DWInfo");
102
103	(new TestWindow())->Show();
104
105	app.Run();
106}
107