Beispiel #1
0
static void rbt_delete_node(rbt_t* tree, rbt_node_t* node){
    rbt_node_t* descendant = NULL;
    if(node->left && node->right){
        descendant = rightmost_descendant(node->left);
        mem_retain(descendant);
        rbt_delete_node(tree, descendant);
        if(node->left) node->left->parent = descendant;
        if(node->right) node->right->parent = descendant;
        descendant->left = node->left;
        descendant->right = node->right;
        descendant->color = node->color;
    }else if(BLACK == rbt_node_color(node)){
        //black node with at most one non-leaf child
        if(RED == rbt_node_color(node->left) || RED == rbt_node_color(node->right)){
            descendant = node->left ? node->left : node->right;
            descendant->color = BLACK;
        } else {
            rbt_del_rebalance(tree, node);
        }
    }
    rbt_node_replace(tree, node, descendant);
    node->left = NULL;
    node->right = NULL;
    node->parent = NULL;
    mem_release(node);
}
void glxx_buffer_subdata(GLXX_BUFFER_T *buffer, int32_t offset, int32_t size, const void *data)
{
   vcos_assert(offset >= 0 && size >= 0);
   vcos_assert(data);

   //if write_would_block(buffer->pool[buffer->current_item] 
   //we pick one of the other pool items, copy the entirety of the current item
   //into that item, and then the new subdata

   if(write_would_block(&buffer->pool[buffer->current_item]))
   {
      //pick a non busy entry from the pool;
      uint32_t i;
      for(i = 0; i< GLXX_BUFFER_POOL_SIZE; i++)
      {
         if(i!=(uint32_t)buffer->current_item && !write_would_block(&buffer->pool[i]))
               break;
      }
      if(i<GLXX_BUFFER_POOL_SIZE)
      {  //found one
         //copy existing data into this new item assuming alloc succeeds
         uint32_t existing_size = mem_get_size(buffer->pool[buffer->current_item].mh_storage);
         bool ok;
         void * existing_data = mem_lock(buffer->pool[buffer->current_item].mh_storage);
         ok = glxx_buffer_inner_data(&buffer->pool[i],existing_size,existing_data,true);
         mem_unlock(buffer->pool[buffer->current_item].mh_storage);
         if(ok)
         {
#ifdef __VIDEOCORE4__
            //unretain current one, so when fixer also unretains, retain count will fall to 0
            mem_unretain(buffer->pool[buffer->current_item].mh_storage);
            //retain new one
            if(buffer->pool[i].mh_storage!=MEM_ZERO_SIZE_HANDLE)
               mem_retain(buffer->pool[i].mh_storage);
#endif
            buffer->current_item = i;
         }
      } //else stick with the existing and wait

   }

   glxx_buffer_inner_subdata(&buffer->pool[buffer->current_item],offset,size,data);

#ifdef REQUIRE_MAX_INDEX_CHECK
   buffer->size_used_for_max = 0;
#endif
}
Beispiel #3
0
bool vg_scissor_retain(
    MEM_HANDLE_T handle, int32_t *bounds,
    uint32_t width, uint32_t height,
    const int32_t *rects, uint32_t rects_count)
{
    if (!mem_retain(handle)) {
        KHRN_IMAGE_FORMAT_T format = vg_scissor_get_format(width, height);
        uint32_t stride = khrn_image_get_stride(format, width);
        if (!mem_resize_ex(handle, khrn_image_pad_height(format, height) * stride, MEM_COMPACT_DISCARD)) {
            mem_unretain(handle);
            return false;
        }
        vg_scissor_gen(mem_lock(handle), stride, bounds, format, width, height, rects, rects_count);
        mem_unlock(handle);
    }
    return true;
}
bool glxx_buffer_data(GLXX_BUFFER_T *buffer, int32_t size, const void *data, GLenum usage)
{
   vcos_assert(size >= 0);

   if(write_would_block(&buffer->pool[buffer->current_item]))
   {
      //pick a non busy entry from the pool;
      uint32_t i;
      for(i = 0; i< GLXX_BUFFER_POOL_SIZE; i++)
      {
         if(i!=(uint32_t)buffer->current_item && !write_would_block(&buffer->pool[i]))
            break;
      }
      if(i<GLXX_BUFFER_POOL_SIZE)
      {  //found one
#ifdef __VIDEOCORE4__
         //unretain current one, so when fixer also unretains, retain count will fall to 0
         mem_unretain(buffer->pool[buffer->current_item].mh_storage);
         //retain new one
         if(buffer->pool[i].mh_storage!=MEM_ZERO_SIZE_HANDLE)
            mem_retain(buffer->pool[i].mh_storage);
#endif
         buffer->current_item = i;

      } //else stick with the existing and wait
   }

   if(!glxx_buffer_inner_data(&buffer->pool[buffer->current_item],size,data,false))
      return false;

   //successfuly allocated memory and copied data
   buffer->usage = usage;

#ifdef REQUIRE_MAX_INDEX_CHECK
   buffer->size_used_for_max = 0;
#endif

   return true;
}