]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android/external-libkmsxx.git/blobdiff - tests/db.cpp
db: cleanup atomic req use
[android/external-libkmsxx.git] / tests / db.cpp
index 576896ef792ced4137e8c75fe6fea185cb48aa7b..3515b106aa8f4e7011eeb47ad1111bdf5a3ba8b6 100644 (file)
@@ -6,23 +6,18 @@
 #include <drm_fourcc.h>
 
 #include "kms++.h"
-#include "utils/color.h"
 
 #include "test.h"
 
 using namespace std;
 using namespace kms;
 
-static void draw_color_bar(Framebuffer& buf, int old_xpos, int xpos, int width);
-
 static void main_loop(Card& card);
 
-#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
-
 class OutputFlipHandler
 {
 public:
-       OutputFlipHandler(Connector* conn, Crtc* crtc, Framebuffer* fb1, Framebuffer* fb2)
+       OutputFlipHandler(Connector* conn, Crtc* crtc, DumbFramebuffer* fb1, DumbFramebuffer* fb2)
                : m_connector(conn), m_crtc(crtc), m_fbs { fb1, fb2 }, m_front_buf(1), m_bar_xpos(0)
        {
        }
@@ -69,27 +64,25 @@ public:
                if (card.has_atomic()) {
                        int r;
 
-                       AtomicReq ctx(card);
+                       AtomicReq req(card);
 
-                       ctx.add(m_crtc, card.get_prop("FB_ID"), fb->id());
+                       req.add(m_crtc, "FB_ID", fb->id());
 
-                       r = ctx.test();
+                       r = req.test();
                        ASSERT(r == 0);
 
-                       r = ctx.commit(this);
+                       r = req.commit(this);
                        ASSERT(r == 0);
                } else {
-                       int r = drmModePageFlip(card.fd(), m_crtc->id(), fb->id(), DRM_MODE_PAGE_FLIP_EVENT, this);
+                       int r = crtc->page_flip(*fb, this);
                        ASSERT(r == 0);
                }
        }
 
-       Crtc* crtc() const { return m_crtc; }
-
 private:
        Connector* m_connector;
        Crtc* m_crtc;
-       Framebuffer* m_fbs[2];
+       DumbFramebuffer* m_fbs[2];
 
        int m_front_buf;
        int m_bar_xpos;
@@ -106,30 +99,15 @@ int main()
 
        vector<OutputFlipHandler*> outputs;
 
-       for (auto conn : card.get_connectors())
+       for (auto pipe : card.get_connected_pipelines())
        {
-               if (conn->connected() == false)
-                       continue;
+               auto conn = pipe.connector;
+               auto crtc = pipe.crtc;
 
                auto mode = conn->get_default_mode();
 
-               Crtc* crtc = conn->get_current_crtc();
-               if (!crtc) {
-                       for (auto c : conn->get_possible_crtcs()) {
-                               if (find_if(outputs.begin(), outputs.end(), [c](OutputFlipHandler* o) { return o->crtc() == c; }) == outputs.end()) {
-                                       crtc = c;
-                                       break;
-                               }
-                       }
-               }
-
-               if (!crtc) {
-                       printf("failed to find crtc\n");
-                       return -1;
-               }
-
-               auto fb1 = new Framebuffer(card, mode.hdisplay, mode.vdisplay, "XR24");
-               auto fb2 = new Framebuffer(card, mode.hdisplay, mode.vdisplay, "XR24");
+               auto fb1 = new DumbFramebuffer(card, mode.hdisplay, mode.vdisplay, "XR24");
+               auto fb2 = new DumbFramebuffer(card, mode.hdisplay, mode.vdisplay, "XR24");
 
                printf("conn %u, crtc %u, fb1 %u, fb2 %u\n", conn->id(), crtc->id(), fb1->id(), fb2->id());
 
@@ -195,124 +173,3 @@ static void main_loop(Card& card)
                }
        }
 }
-
-
-static const RGB colors32[] = {
-       RGB(255, 255, 255),
-       RGB(255, 0, 0),
-       RGB(255, 255, 255),
-       RGB(0, 255, 0),
-       RGB(255, 255, 255),
-       RGB(0, 0, 255),
-       RGB(255, 255, 255),
-       RGB(200, 200, 200),
-       RGB(255, 255, 255),
-       RGB(100, 100, 100),
-       RGB(255, 255, 255),
-       RGB(50, 50, 50),
-};
-
-static const uint16_t colors16[] = {
-       colors32[0].rgb565(),
-       colors32[1].rgb565(),
-       colors32[2].rgb565(),
-       colors32[3].rgb565(),
-       colors32[4].rgb565(),
-       colors32[5].rgb565(),
-       colors32[6].rgb565(),
-       colors32[7].rgb565(),
-       colors32[8].rgb565(),
-       colors32[9].rgb565(),
-       colors32[10].rgb565(),
-       colors32[11].rgb565(),
-};
-
-static void drm_draw_color_bar_rgb888(Framebuffer& buf, int old_xpos, int xpos, int width)
-{
-       for (unsigned y = 0; y < buf.height(); ++y) {
-               RGB bcol = colors32[y * ARRAY_SIZE(colors32) / buf.height()];
-               uint32_t *line = (uint32_t*)(buf.map(0) + buf.stride(0) * y);
-
-               if (old_xpos >= 0) {
-                       for (int x = old_xpos; x < old_xpos + width; ++x)
-                               line[x] = 0;
-               }
-
-               for (int x = xpos; x < xpos + width; ++x)
-                       line[x] = bcol.raw;
-       }
-}
-
-static void drm_draw_color_bar_rgb565(Framebuffer& buf, int old_xpos, int xpos, int width)
-{
-       static_assert(ARRAY_SIZE(colors32) == ARRAY_SIZE(colors16), "bad colors arrays");
-
-       for (unsigned y = 0; y < buf.height(); ++y) {
-               uint16_t bcol = colors16[y * ARRAY_SIZE(colors16) / buf.height()];
-               uint16_t *line = (uint16_t*)(buf.map(0) + buf.stride(0) * y);
-
-               if (old_xpos >= 0) {
-                       for (int x = old_xpos; x < old_xpos + width; ++x)
-                               line[x] = 0;
-               }
-
-               for (int x = xpos; x < xpos + width; ++x)
-                       line[x] = bcol;
-       }
-}
-
-static void drm_draw_color_bar_semiplanar_yuv(Framebuffer& buf, int old_xpos, int xpos, int width)
-{
-       const uint8_t colors[] = {
-               0xff,
-               0x00,
-               0xff,
-               0x20,
-               0xff,
-               0x40,
-               0xff,
-               0x80,
-               0xff,
-       };
-
-       for (unsigned y = 0; y < buf.height(); ++y) {
-               unsigned int bcol = colors[y * ARRAY_SIZE(colors) / buf.height()];
-               uint8_t *line = (uint8_t*)(buf.map(0) + buf.stride(0) * y);
-
-               if (old_xpos >= 0) {
-                       for (int x = old_xpos; x < old_xpos + width; ++x)
-                               line[x] = 0;
-               }
-
-               for (int x = xpos; x < xpos + width; ++x)
-                       line[x] = bcol;
-       }
-}
-
-static void draw_color_bar(Framebuffer& buf, int old_xpos, int xpos, int width)
-{
-       switch (buf.format()) {
-       case DRM_FORMAT_NV12:
-       case DRM_FORMAT_NV21:
-               // XXX not right but gets something on the screen
-               drm_draw_color_bar_semiplanar_yuv(buf, old_xpos, xpos, width);
-               break;
-
-       case DRM_FORMAT_YUYV:
-       case DRM_FORMAT_UYVY:
-               // XXX not right but gets something on the screen
-               drm_draw_color_bar_rgb565(buf, old_xpos, xpos, width);
-               break;
-
-       case DRM_FORMAT_RGB565:
-               drm_draw_color_bar_rgb565(buf, old_xpos, xpos, width);
-               break;
-
-       case DRM_FORMAT_XRGB8888:
-               drm_draw_color_bar_rgb888(buf, old_xpos, xpos, width);
-               break;
-
-       default:
-               ASSERT(false);
-       }
-}