| 1 |
/* |
| 2 |
* Copyright (C) 2025 Linux Studio Plugins Project <https://lsp-plug.in/> |
| 3 |
* (C) 2025 Vladimir Sadovnikov <[email protected]> |
| 4 |
* |
| 5 |
* This file is part of lsp-ws-lib |
| 6 |
* Created on: 9 июл. 2022 г. |
| 7 |
* |
| 8 |
* lsp-ws-lib is free software: you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU Lesser General Public License as published by |
| 10 |
* the Free Software Foundation, either version 3 of the License, or |
| 11 |
* any later version. |
| 12 |
* |
| 13 |
* lsp-ws-lib is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU Lesser General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Lesser General Public License |
| 19 |
* along with lsp-ws-lib. If not, see <https://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#include <lsp-plug.in/common/endian.h> |
| 23 |
#include <lsp-plug.in/stdlib/math.h> |
| 24 |
#include <lsp-plug.in/test-fw/mtest.h> |
| 25 |
#include <lsp-plug.in/ws/factory.h> |
| 26 |
#include <lsp-plug.in/ws/IEventHandler.h> |
| 27 |
|
| 28 |
MTEST_BEGIN("ws.display", dsurface) |
| 29 |
|
| 30 |
class Handler: public ws::IEventHandler |
| 31 |
{ |
| 32 |
private: |
| 33 |
test_type_t *pTest; |
| 34 |
ws::IWindow *pWnd; |
| 35 |
|
| 36 |
public: |
| 37 |
inline Handler(test_type_t *test, ws::IWindow *wnd) |
| 38 |
{ |
| 39 |
pTest = test; |
| 40 |
pWnd = wnd; |
| 41 |
} |
| 42 |
|
| 43 |
virtual status_t handle_event(const ws::event_t *ev) |
| 44 |
{ |
| 45 |
switch (ev->nType) |
| 46 |
{ |
| 47 |
case ws::UIE_REDRAW: |
| 48 |
{ |
| 49 |
Color c(1.0f, 1.0f, 1.0f); |
| 50 |
ws::ISurface *s = pWnd->get_surface(); |
| 51 |
if (s == NULL) |
| 52 |
return STATUS_OK; |
| 53 |
|
| 54 |
// Perform drawing |
| 55 |
s->begin(); |
| 56 |
s->clear(c); |
| 57 |
lsp_finally{ s->end(); }; |
| 58 |
|
| 59 |
uint32_t *buf = static_cast<uint32_t *>(malloc( 320 * 200 * sizeof(uint32_t))); |
| 60 |
lsp_finally{ free(buf); }; |
| 61 |
|
| 62 |
for (size_t y=0; y<200; ++y) |
| 63 |
{ |
| 64 |
uint32_t *row = &buf[y * 320]; |
| 65 |
uint32_t alpha= uint8_t((0xff * y) / (200 - 1)) << 24; |
| 66 |
for (size_t x=0; x<320; ++x) |
| 67 |
row[x] = CPU_TO_LE(uint32_t((x * y) | alpha)); |
| 68 |
row[y] = CPU_TO_LE(uint32_t(0xffff0000)); |
| 69 |
} |
| 70 |
|
| 71 |
s->draw_raw( |
| 72 |
buf, 320, 200, 320 * sizeof(uint32_t), |
| 73 |
0.0f, 0.0f, 1.0f, 1.0f, 0.0f); |
| 74 |
s->draw_raw( |
| 75 |
buf, 320, 200, 320 * sizeof(uint32_t), |
| 76 |
320.0f, 200.0f, 1.0f, 1.0f, 0.25f); |
| 77 |
|
| 78 |
for (size_t y=0; y<200; ++y) |
| 79 |
{ |
| 80 |
uint32_t *row = &buf[y * 320]; |
| 81 |
for (size_t x=0; x<320; ++x) |
| 82 |
row[x] = CPU_TO_LE(LE_TO_CPU(row[x]) ^ 0x00ffffff); |
| 83 |
row[y] = CPU_TO_LE(uint32_t(0xff00ff00)); |
| 84 |
} |
| 85 |
|
| 86 |
s->draw_raw( |
| 87 |
buf, 320, 200, 320 * sizeof(uint32_t), |
| 88 |
320.0f, 0.0f, 1.0f, 1.0f, 0.0f); |
| 89 |
s->draw_raw( |
| 90 |
buf, 320, 200, 320 * sizeof(uint32_t), |
| 91 |
0.0f, 200.0f, 1.0f, 1.0f, 0.75f); |
| 92 |
|
| 93 |
return STATUS_OK; |
| 94 |
} |
| 95 |
|
| 96 |
case ws::UIE_CLOSE: |
| 97 |
{ |
| 98 |
pWnd->hide(); |
| 99 |
pWnd->display()->quit_main(); |
| 100 |
break; |
| 101 |
} |
| 102 |
|
| 103 |
default: |
| 104 |
return IEventHandler::handle_event(ev); |
| 105 |
} |
| 106 |
|
| 107 |
return STATUS_OK; |
| 108 |
} |
| 109 |
}; |
| 110 |
|
| 111 |
MTEST_MAIN |
| 112 |
{ |
| 113 |
ws::IDisplay *dpy = ws::create_display(0, NULL); |
| 114 |
MTEST_ASSERT(dpy != NULL); |
| 115 |
lsp_finally { ws::free_display(dpy); }; |
| 116 |
|
| 117 |
ws::IWindow *wnd = dpy->create_window(); |
| 118 |
MTEST_ASSERT(wnd != NULL); |
| 119 |
lsp_finally { |
| 120 |
wnd->destroy(); |
| 121 |
delete wnd; |
| 122 |
}; |
| 123 |
|
| 124 |
MTEST_ASSERT(wnd->init() == STATUS_OK); |
| 125 |
MTEST_ASSERT(wnd->set_caption("Test direct surface") == STATUS_OK); |
| 126 |
MTEST_ASSERT(wnd->resize(640, 400) == STATUS_OK); |
| 127 |
MTEST_ASSERT(wnd->set_window_actions(ws::WA_MOVE | ws::WA_CLOSE) == STATUS_OK); |
| 128 |
MTEST_ASSERT(wnd->set_size_constraints(640, 400, 640, 400) == STATUS_OK); |
| 129 |
|
| 130 |
Handler h(this, wnd); |
| 131 |
wnd->set_handler(&h); |
| 132 |
|
| 133 |
MTEST_ASSERT(wnd->show() == STATUS_OK); |
| 134 |
|
| 135 |
MTEST_ASSERT(dpy->main() == STATUS_OK); |
| 136 |
} |
| 137 |
|
| 138 |
MTEST_END |
| 139 |
|
| 140 |
|
| 141 |
|