| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* GATE PROJECT LICENSE: | ||
| 2 | +----------------------------------------------------------------------------+ | ||
| 3 | | Copyright (c) 2018-2026, Stefan Meislinger <sm@opengate.at> | | ||
| 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 | #include "gate/graphics/framebuffers.hpp" | ||
| 30 | |||
| 31 | #include "gate/exceptions.hpp" | ||
| 32 | |||
| 33 | |||
| 34 | namespace gate | ||
| 35 | { | ||
| 36 | namespace graph | ||
| 37 | { | ||
| 38 | |||
| 39 | 1 | FrameBuffer::FrameBuffer(gate_framebuffer_t* ptr_fb) | |
| 40 | 1 | : object_impl_t(ptr_fb) | |
| 41 | { | ||
| 42 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (this->impl_ptr == NULL) |
| 43 | { | ||
| 44 | ✗ | GATEXX_RAISE_ERROR(results::NullPointer); | |
| 45 | } | ||
| 46 | 1 | } | |
| 47 | |||
| 48 | ✗ | FrameBuffer::FrameBuffer(FrameBuffer const& src) | |
| 49 | ✗ | : object_impl_t(src) | |
| 50 | { | ||
| 51 | ✗ | } | |
| 52 | |||
| 53 | ✗ | FrameBuffer::Info FrameBuffer::getInfo() | |
| 54 | { | ||
| 55 | Info info; | ||
| 56 | ✗ | result_t result = gate_framebuffer_get_info(this->c_impl(), &info); | |
| 57 | ✗ | GATEXX_CHECK_ERROR(result); | |
| 58 | ✗ | return info; | |
| 59 | } | ||
| 60 | |||
| 61 | ✗ | Property FrameBuffer::getProperty(String const& name) | |
| 62 | { | ||
| 63 | ✗ | Property prop; | |
| 64 | ✗ | result_t result = gate_framebuffer_get_property(this->c_impl(), name.c_impl(), prop.c_impl()); | |
| 65 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 66 | ✗ | return prop; | |
| 67 | } | ||
| 68 | |||
| 69 | ✗ | void FrameBuffer::setProperty(String const& name, Property const& prop) | |
| 70 | { | ||
| 71 | ✗ | result_t result = gate_framebuffer_set_property(this->c_impl(), name.c_impl(), prop.c_impl()); | |
| 72 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 73 | ✗ | } | |
| 74 | |||
| 75 | ✗ | void FrameBuffer::update() | |
| 76 | { | ||
| 77 | ✗ | result_t result = gate_framebuffer_update(this->c_impl()); | |
| 78 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 79 | ✗ | } | |
| 80 | |||
| 81 | ✗ | bool_t FrameBuffer::getPixel(uint32_t x, uint32_t y, Color& col) noexcept | |
| 82 | { | ||
| 83 | ✗ | result_t result = gate_framebuffer_get_pixel(this->c_impl(), x, y, &col.value); | |
| 84 | ✗ | return GATE_SUCCEEDED(result); | |
| 85 | } | ||
| 86 | |||
| 87 | ✗ | bool_t FrameBuffer::setPixel(uint32_t x, uint32_t y, Color const& col) noexcept | |
| 88 | { | ||
| 89 | ✗ | result_t result = gate_framebuffer_set_pixel(this->c_impl(), x, y, col.value); | |
| 90 | ✗ | return GATE_SUCCEEDED(result); | |
| 91 | } | ||
| 92 | |||
| 93 | ✗ | RasterImage FrameBuffer::getImage(uint32_t src_x, uint32_t src_y, uint32_t width, uint32_t height) | |
| 94 | { | ||
| 95 | ✗ | RasterImage raster; | |
| 96 | ✗ | result_t result = gate_framebuffer_get_image(this->c_impl(), src_x, src_y, width, height, raster.c_impl()); | |
| 97 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 98 | ✗ | return raster; | |
| 99 | } | ||
| 100 | |||
| 101 | ✗ | void FrameBuffer::setImage(RasterImage const& image, uint32_t dest_x, uint32_t dest_y) | |
| 102 | { | ||
| 103 | ✗ | result_t result = gate_framebuffer_set_image(this->c_impl(), image.c_impl(), dest_x, dest_y); | |
| 104 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 105 | ✗ | } | |
| 106 | |||
| 107 | ✗ | bool_t FrameBuffer::awaitEvent(uint32_t timeout_ms, Event& evt) | |
| 108 | { | ||
| 109 | ✗ | result_t result = gate_framebuffer_await_event(this->c_impl(), timeout_ms, &evt); | |
| 110 | ✗ | switch (result) | |
| 111 | { | ||
| 112 | ✗ | case GATE_RESULT_OK: | |
| 113 | { | ||
| 114 | ✗ | return true; | |
| 115 | } | ||
| 116 | ✗ | case GATE_RESULT_TIMEOUT: | |
| 117 | { | ||
| 118 | ✗ | break; | |
| 119 | } | ||
| 120 | ✗ | default: | |
| 121 | { | ||
| 122 | ✗ | GATEXX_CHECK_ERROR(result); | |
| 123 | } | ||
| 124 | } | ||
| 125 | ✗ | return false; | |
| 126 | } | ||
| 127 | |||
| 128 | |||
| 129 | 1 | Array<FrameBufferInfo> FrameBufferFactory::enumDisplays() | |
| 130 | { | ||
| 131 | FrameBufferInfo infos[32]; | ||
| 132 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | size_t used = gate_framebuffer_enum_displays(&infos[0], sizeof(infos) / sizeof(infos[0])); |
| 133 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return Array<FrameBufferInfo>(infos, used); |
| 134 | } | ||
| 135 | |||
| 136 | ✗ | FrameBufferInfo FrameBufferFactory::findDisplay(uint32_t requiredWidth, uint32_t requiredHeight) | |
| 137 | { | ||
| 138 | FrameBufferInfo info; | ||
| 139 | ✗ | result_t result = gate_framebuffer_find_display(requiredWidth, requiredHeight, &info); | |
| 140 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 141 | ✗ | return info; | |
| 142 | } | ||
| 143 | |||
| 144 | ✗ | FrameBuffer FrameBufferFactory::openDisplay(FrameBufferInfo const& info) | |
| 145 | { | ||
| 146 | ✗ | gate_framebuffer_t* ptr_fb = NULL; | |
| 147 | ✗ | result_t result = gate_framebuffer_open_display(&info, &ptr_fb); | |
| 148 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
| 149 | ✗ | return FrameBuffer(ptr_fb); | |
| 150 | } | ||
| 151 | |||
| 152 | 1 | FrameBuffer FrameBufferFactory::createImageFrameBuffer(uint32_t width, uint32_t height) | |
| 153 | { | ||
| 154 | 1 | gate_framebuffer_t* ptr_fb = NULL; | |
| 155 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_framebuffer_create_image(width, height, &ptr_fb); |
| 156 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 157 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return FrameBuffer(ptr_fb); |
| 158 | } | ||
| 159 | |||
| 160 | } // end of namespace graph | ||
| 161 | } // end of namespace gate | ||
| 162 |