| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* GATE PROJECT LICENSE: | ||
| 2 | +----------------------------------------------------------------------------+ | ||
| 3 | | Copyright(c) 2018-2026, Stefan Meislinger | | ||
| 4 | | All rights reserved. | | ||
| 5 | | | | ||
| 6 | | Redistribution and use in source and binary forms, with or without | | ||
| 7 | | modification, are permitted provided that the following conditions are met:| | ||
| 8 | | | | ||
| 9 | | 1. Redistributions of source code must retain the above copyright notice, | | ||
| 10 | | this list of conditions and the following disclaimer. | | ||
| 11 | | 2. Redistributions in binary form must reproduce the above copyright | | ||
| 12 | | notice, this list of conditions and the following disclaimer in the | | ||
| 13 | | documentation and/or other materials provided with the distribution. | | ||
| 14 | | | | ||
| 15 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"| | ||
| 16 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | ||
| 17 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | ||
| 18 | | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | | ||
| 19 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | ||
| 20 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | ||
| 21 | | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | ||
| 22 | | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | ||
| 23 | | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | ||
| 24 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | | ||
| 25 | | THE POSSIBILITY OF SUCH DAMAGE. | | ||
| 26 | +----------------------------------------------------------------------------+ | ||
| 27 | */ | ||
| 28 | |||
| 29 | |||
| 30 | #include "gate/gatemain.h" | ||
| 31 | #include "gate/results.h" | ||
| 32 | |||
| 33 | #include "gate/applications.hpp" | ||
| 34 | #include "gate/wrappers.hpp" | ||
| 35 | #include "gate/graphics/framebuffers.hpp" | ||
| 36 | |||
| 37 | static gate_bool_t run_app_tests = false; | ||
| 38 | |||
| 39 | namespace gate | ||
| 40 | { | ||
| 41 | namespace apps | ||
| 42 | { | ||
| 43 | |||
| 44 | class GATE_API_LOCAL FramebufferTest : public App | ||
| 45 | { | ||
| 46 | private: | ||
| 47 | graph::FrameBufferInfo selectedDisplay; | ||
| 48 | Optional<graph::FrameBuffer> frameBuffer; | ||
| 49 | Optional<graph::FrameBuffer> shadowBuffer; | ||
| 50 | |||
| 51 | |||
| 52 | public: | ||
| 53 | 1 | FramebufferTest() | |
| 54 | 1 | { | |
| 55 | 1 | } | |
| 56 | 2 | ~FramebufferTest() noexcept | |
| 57 | 2 | { | |
| 58 | 2 | } | |
| 59 | |||
| 60 | 1 | virtual void onInit() override | |
| 61 | { | ||
| 62 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | Array<graph::FrameBufferInfo> displays = graph::FrameBufferFactory::enumDisplays(); |
| 63 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (displays.empty()) |
| 64 | { | ||
| 65 | ✗ | raiseException(results::NotAvailable, "No framebuffer displays available"); | |
| 66 | } | ||
| 67 | 1 | this->selectedDisplay = displays.at(0); | |
| 68 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | graph::FrameBufferFactory::findDisplay(this->selectedDisplay.width, this->selectedDisplay.height); |
| 69 | |||
| 70 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | this->frameBuffer.create(graph::FrameBufferFactory::openDisplay(this->selectedDisplay)); |
| 71 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | this->selectedDisplay = this->frameBuffer->getInfo(); |
| 72 | { | ||
| 73 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | graph::FrameBuffer fb = *this->frameBuffer; |
| 74 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | fb.getInterfaceName(); |
| 75 |
4/8✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✓ Branch 15 taken 1 times.
✗ Branch 16 not taken.
|
4 | GATEXX_TRY_IGNORE( fb.setProperty("WrongProp", Property()) ); |
| 76 |
3/6✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
|
3 | GATEXX_TRY_IGNORE( fb.getProperty("WrongProp") ); |
| 77 | } | ||
| 78 | |||
| 79 | 1 | this->shadowBuffer.create(graph::FrameBufferFactory::createImageFrameBuffer( | |
| 80 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | this->selectedDisplay.width, this->selectedDisplay.height)); |
| 81 | { | ||
| 82 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | graph::FrameBuffer shadow = *this->shadowBuffer; |
| 83 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | shadow.getInterfaceName(); |
| 84 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | shadow.getInfo(); |
| 85 |
4/8✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
✓ Branch 15 taken 1 times.
✗ Branch 16 not taken.
|
4 | GATEXX_TRY_IGNORE( shadow.setProperty("WrongProp", Property()) ); |
| 86 |
3/6✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
|
3 | GATEXX_TRY_IGNORE( shadow.getProperty("WrongProp") ); |
| 87 | graph::FrameBuffer::Event fbEvent; | ||
| 88 |
2/4✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
2 | GATEXX_TRY_IGNORE( shadow.awaitEvent(0, fbEvent)); |
| 89 | } | ||
| 90 | |||
| 91 | 1 | } | |
| 92 | |||
| 93 | 1 | void onUninit() | |
| 94 | { | ||
| 95 | 1 | this->frameBuffer.reset(); | |
| 96 | 1 | } | |
| 97 | |||
| 98 | 1 | virtual void run() override | |
| 99 | { | ||
| 100 | static const graph::Color colors[] = | ||
| 101 | { | ||
| 102 | graph::Color::Blue, | ||
| 103 | graph::Color::Green, | ||
| 104 | graph::Color::Red, | ||
| 105 | graph::Color::Magenta, | ||
| 106 | graph::Color::Cyan, | ||
| 107 | graph::Color::Brown, | ||
| 108 | graph::Color::LightGray | ||
| 109 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | }; |
| 110 | static const unsigned colorsCount = sizeof(colors) / sizeof(colors[0]); | ||
| 111 | 1 | graph::FrameBuffer& fb = *this->frameBuffer; | |
| 112 | 1 | graph::FrameBuffer& shadow = *this->shadowBuffer; | |
| 113 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | const graph::FrameBuffer::Info info = fb.getInfo(); |
| 114 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | graph::RasterImage image(info.width, info.height); |
| 115 | 1 | const unsigned width2 = info.width / 2; | |
| 116 | 1 | const unsigned height2 = info.height / 2; | |
| 117 | 1 | const unsigned width4 = info.width / 4; | |
| 118 | 1 | const unsigned height4 = info.height / 4; | |
| 119 | |||
| 120 | 1 | bool_t canceled = false; | |
| 121 | 1 | unsigned colorIndex = 0; | |
| 122 | 1 | uint32_t timeoutMs = 200; | |
| 123 | |||
| 124 | 1 | uint32_t loopCounter = 0; | |
| 125 | |||
| 126 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 1 times.
|
12 | while (!canceled) |
| 127 | { | ||
| 128 | 11 | const bool_t isOdd = loopCounter % 2; | |
| 129 |
1/2✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
|
11 | image.clear(colors[colorIndex]); |
| 130 | |||
| 131 |
1/2✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
|
11 | shadow.setImage(image); |
| 132 | { | ||
| 133 |
1/2✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
|
11 | graph::Color pixel; |
| 134 | 11 | shadow.getPixel(width2, height2, pixel); | |
| 135 | 11 | pixel.value.r = 255 - pixel.value.r; | |
| 136 | 11 | pixel.value.g = 255 - pixel.value.g; | |
| 137 | 11 | pixel.value.b = 255 - pixel.value.b; | |
| 138 | 11 | shadow.setPixel(width2, height2, pixel); | |
| 139 | } | ||
| 140 |
1/2✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
|
11 | shadow.update(); |
| 141 | |||
| 142 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 6 times.
|
11 | const unsigned useX = isOdd ? width4 : 0; |
| 143 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 6 times.
|
11 | const unsigned useY = isOdd ? height4 : 0; |
| 144 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 6 times.
|
11 | const unsigned useWidth = isOdd ? width2 : info.width; |
| 145 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 6 times.
|
11 | const unsigned useHeight = isOdd ? height2 : info.height; |
| 146 | |||
| 147 |
1/2✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
|
22 | graph::RasterImage shadowImage = shadow.getImage(useX, useY, useWidth, useHeight); |
| 148 | |||
| 149 |
1/2✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
|
11 | fb.setImage(shadowImage, useX, useY); |
| 150 |
1/2✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
|
11 | fb.update(); |
| 151 | |||
| 152 | graph::FrameBuffer::Event fbEvent; | ||
| 153 |
2/4✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
|
11 | if (fb.awaitEvent(timeoutMs, fbEvent)) |
| 154 | { | ||
| 155 | ✗ | switch(fbEvent.event_type) | |
| 156 | { | ||
| 157 | ✗ | case graph::FrameBuffer::EventType_Cancel: | |
| 158 | case graph::FrameBuffer::EventType_Quit: | ||
| 159 | { | ||
| 160 | ✗ | canceled = true; | |
| 161 | ✗ | break; | |
| 162 | } | ||
| 163 | ✗ | default: | |
| 164 | { | ||
| 165 | ✗ | break; | |
| 166 | } | ||
| 167 | } | ||
| 168 | } | ||
| 169 | 11 | ++colorIndex; | |
| 170 | 11 | colorIndex = (colorIndex + 1) % colorsCount; | |
| 171 | |||
| 172 | 11 | ++loopCounter; | |
| 173 |
1/2✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
|
11 | if (run_app_tests) |
| 174 | { | ||
| 175 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10 times.
|
11 | if (loopCounter > 10) |
| 176 | { | ||
| 177 | 1 | canceled = true; | |
| 178 | } | ||
| 179 | } | ||
| 180 | } | ||
| 181 | |||
| 182 | 1 | this->onUninit(); | |
| 183 | 1 | } | |
| 184 | }; | ||
| 185 | |||
| 186 | } // end of namespace apps | ||
| 187 | } // end of namespace gate | ||
| 188 | |||
| 189 | 1 | int gate_main(char const* program, char const* const* arguments, gate_size_t argcount, gate_uintptr_t apphandle) | |
| 190 | { | ||
| 191 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | gate::apps::FramebufferTest fbTest; |
| 192 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (argcount > 0) |
| 193 | { | ||
| 194 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | if (0 == gate_str_comp_ic(arguments[0], "--runtests")) |
| 195 | { | ||
| 196 | 1 | run_app_tests = true; | |
| 197 | } | ||
| 198 | } | ||
| 199 | |||
| 200 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | int exitcode = gate::App::runApp(fbTest, program, arguments, argcount, apphandle); |
| 201 | 2 | return exitcode; | |
| 202 | } | ||
| 203 |