Permalink
Browse files

Create a separate file with test draw utilities in order to reuse them

  • Loading branch information...
1 parent 6688332 commit 21d5060b431a46a225d77bf00eb6e985c6134266 Sergey Matyukevich committed Oct 24, 2012
Showing with 48 additions and 50 deletions.
  1. +2 −2 CMakeLists.txt
  2. +26 −0 draw_utils.c
  3. +13 −0 draw_utils.h
  4. +3 −25 drm_dumb_bo.c
  5. +4 −23 drm_dumb_bo_libkms.c
View
@@ -3,8 +3,8 @@ project(drm_tests)
add_executable(test test.c)
add_executable(drm_info drm_info.c)
-add_executable(drm_dumb_bo drm_dumb_bo.c drm_utils.c)
-add_executable(drm_dumb_bo_libkms drm_dumb_bo_libkms.c drm_utils.c)
+add_executable(drm_dumb_bo drm_dumb_bo.c drm_utils.c draw_utils.c)
+add_executable(drm_dumb_bo_libkms drm_dumb_bo_libkms.c drm_utils.c draw_utils.c)
add_executable(drm_gl_simple drm_gl_simple.c drm_utils.c)
# find headers
View
@@ -0,0 +1,26 @@
+#include "draw_utils.h"
+
+/* */
+
+void draw_test_image(uint32_t *dst, uint32_t w, uint32_t h)
+{
+
+ uint32_t color32[] = {
+ 0x000000FF, 0x0000FF00, 0x00FF0000,
+ 0x00FF00FF, 0x00FFFF00, 0x0000FFFF,
+ };
+
+ uint32_t color;
+ int i, j;
+
+ for(i = 0; i < h; i++ ){
+
+ color = color32[6*i/h];
+
+ for(j = 0; j < w; j++) {
+ *(dst + i*w + j) = color;
+ }
+ }
+
+
+}
View
@@ -0,0 +1,13 @@
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <error.h>
+#include <errno.h>
+
+/* */
+
+void draw_test_image(uint32_t *addr, uint32_t width, uint32_t height);
View
@@ -17,6 +17,7 @@
#include <xf86drm.h>
#include <xf86drmMode.h>
+#include "draw_utils.h"
#include "drm_utils.h"
/* */
@@ -148,31 +149,8 @@ int main(char argc, char *argv[])
/* draw on the screen */
- do {
-
- uint32_t color32[] = {
- 0x000000FF, 0x0000FF00, 0x00FF0000,
- 0x00FF00FF, 0x00FFFF00, 0x0000FFFF,
- };
-
- uint32_t *dst = (uint32_t *) dbo.map;
- uint32_t h = kms_data.mode->vdisplay;
- uint32_t w = kms_data.mode->hdisplay;
- uint32_t color;
- int i, j;
-
- for(i = 0; i < h; i++ ){
-
- color = color32[6*i/h];
-
- for(j = 0; j < w; j++) {
- *(dst + i*w + j) = color;
- }
- }
-
- getchar();
-
- } while(0);
+ draw_test_image((uint32_t *) dbo.map, kms_data.mode->hdisplay, kms_data.mode->vdisplay);
+ getchar();
/* restore old crtc */
View
@@ -16,6 +16,7 @@
#include <xf86drm.h>
#include <libkms.h>
+#include "draw_utils.h"
#include "drm_utils.h"
/* */
@@ -132,30 +133,10 @@ int main(char argc, char *argv[])
/* draw on the screen */
- do {
+ draw_test_image((uint32_t *) dst, kms_data.mode->hdisplay, kms_data.mode->vdisplay);
+ getchar();
- uint32_t color32[] = {
- 0x000000FF, 0x0000FF00, 0x00FF0000,
- 0x00FF00FF, 0x00FFFF00, 0x0000FFFF,
- };
-
- uint32_t h = kms_data.mode->vdisplay;
- uint32_t w = kms_data.mode->hdisplay;
- uint32_t color;
- int i, j;
-
- for(i = 0; i < h; i++ ){
-
- color = color32[6*i/h];
-
- for(j = 0; j < w; j++) {
- *(dst + i*w + j) = color;
- }
- }
-
- getchar();
-
- } while(0);
+ /* restore original crtc settings */
ret = drmModeSetCrtc(fd, saved_crtc->crtc_id, saved_crtc->buffer_id,
saved_crtc->x, saved_crtc->y, &kms_data.connector->connector_id, 1, &saved_crtc->mode);

0 comments on commit 21d5060

Please sign in to comment.