LCOV - code coverage report
Current view: top level - gui/include/sketch - gui_sketch_texture.inl (source / functions) Hit Total Coverage
Test: crystal-facet-uml_v1.61.0_covts Lines: 8 28 28.6 %
Date: 2024-10-26 21:44:38 Functions: 2 3 66.7 %

          Line data    Source code
       1             : /* File: gui_sketch_texture.inl; Copyright and License: see below */
       2             : 
       3             : #include "u8/u8_log.h"
       4             : #include "u8/u8_trace.h"
       5             : #include <assert.h>
       6             : 
       7           4 : static inline void gui_sketch_texture_init( gui_sketch_texture_t *this_ )
       8             : {
       9           4 :     (*this_).memory_fence_1 = 12345;
      10           4 :     (*this_).memory_fence_2 = 54321;
      11             :     (*this_).surface
      12           4 :         = cairo_image_surface_create_for_data( &((*this_).buf[0]),
      13             :                                                CAIRO_FORMAT_ARGB32,
      14             :                                                GUI_SKETCH_TEXTURE_MAX_WIDTH,
      15             :                                                GUI_SKETCH_TEXTURE_MAX_HEIGHT,
      16             :                                                GUI_SKETCH_TEXTURE_MAX_WIDTH * GUI_SKETCH_TEXTURE_BYTES_PER_PIXEL /* = stride */
      17             :                                              );
      18           4 : }
      19             : 
      20           4 : static inline void gui_sketch_texture_destroy( gui_sketch_texture_t *this_ )
      21             : {
      22           4 :     cairo_surface_destroy( (*this_).surface );
      23           4 : }
      24             : 
      25           0 : static inline u8_error_t gui_sketch_texture_draw( gui_sketch_texture_t *this_,
      26             :                                                   GdkTexture *icon,
      27             :                                                   double left,
      28             :                                                   double top,
      29             :                                                   cairo_t *cr )
      30             : {
      31           0 :     U8_TRACE_BEGIN();
      32           0 :     assert( icon != NULL );
      33           0 :     assert( cr != NULL );
      34           0 :     u8_error_t result = U8_ERROR_NONE;
      35             : 
      36           0 :     const int icon_width = gdk_texture_get_width( icon );
      37           0 :     const int icon_height = gdk_texture_get_height( icon );
      38           0 :     if (( icon_width <= GUI_SKETCH_TEXTURE_MAX_WIDTH )&&( icon_height <= GUI_SKETCH_TEXTURE_MAX_HEIGHT ))
      39             :     {
      40           0 :         cairo_surface_flush( (*this_).surface );
      41           0 :         gdk_texture_download( icon,
      42           0 :                               &((*this_).buf[0]),
      43             :                               GUI_SKETCH_TEXTURE_MAX_WIDTH * GUI_SKETCH_TEXTURE_BYTES_PER_PIXEL /* = stride */
      44             :                             );
      45           0 :         cairo_surface_mark_dirty( (*this_).surface );
      46             :         /* check that boundaries of (*this_).buf have not been overwritten: */
      47           0 :         assert( (*this_).memory_fence_1 == 12345 );
      48           0 :         assert( (*this_).memory_fence_2 == 54321 );
      49             : 
      50           0 :         cairo_set_source_surface( cr, (*this_).surface, left, top );
      51           0 :         cairo_rectangle( cr, left, top, icon_width, icon_height );
      52           0 :         cairo_fill( cr );
      53             :     }
      54             :     else
      55             :     {
      56           0 :         result = U8_ERROR_EDGE_CASE_PARAM;
      57             :     }
      58             : 
      59           0 :     U8_TRACE_END_ERR( result );
      60           0 :     return result;
      61             : }
      62             : 
      63             : 
      64             : /*
      65             : Copyright 2024-2024 Andreas Warnke
      66             : 
      67             : Licensed under the Apache License, Version 2.0 (the "License");
      68             : you may not use this file except in compliance with the License.
      69             : You may obtain a copy of the License at
      70             : 
      71             :     http://www.apache.org/licenses/LICENSE-2.0
      72             : 
      73             : Unless required by applicable law or agreed to in writing, software
      74             : distributed under the License is distributed on an "AS IS" BASIS,
      75             : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      76             : See the License for the specific language governing permissions and
      77             : limitations under the License.
      78             : */

Generated by: LCOV version 1.16