<file_sep>/*
Copyright (c) 2012, Broadcom Europe Ltd
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of the copyright holder nor the
      names of its contributors may be used to endorse or promote products
      derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/*=============================================================================
VCOS - packet-like messages, based loosely on those found in TRIPOS.
=============================================================================*/

#ifndef VCOS_MSGQUEUE_H
#define VCOS_MSGQUEUE_H

#ifdef __cplusplus
extern "C" {
#endif

#include "vcos_types.h"
#include "vcos_platform.h"

/**
 * \file
 *
 * Packet-like messages, based loosely on those found in TRIPOS and
 * derivatives thereof.
 *
 * A task can send a message *pointer* to another task, where it is
 * queued on a linked list and the task woken up. The receiving task
 * consumes all of the messages on its input queue, and optionally
 * sends back replies using the original message memory.
 *
 * A caller can wait for the reply to a specific message - any other
 * messages that arrive in the meantime are queued separately.
 *
 *
 * All messages have a standard common layout, but the payload area can
 * be used freely to extend this.
 */

/** Map the payload portion of a message to a structure pointer.
  */
#define VCOS_MSG_DATA(_msg) (void*)((_msg)->data)

/** Standard message ids - FIXME - these need to be done properly! */
#define VCOS_MSG_N_QUIT            1
#define VCOS_MSG_N_OPEN            2
#define VCOS_MSG_N_CLOSE           3
#define VCOS_MSG_N_PRIVATE         (1<<20)

#define VCOS_MSG_REPLY_BIT         (1<<31)

/** Make gnuc compiler be happy about pointer punning */
#ifdef __GNUC__
#define __VCOS_MAY_ALIAS __attribute__((__may_alias__))
#else
#define __VCOS_MAY_ALIAS
#endif

/** A single message queue.
  */
typedef struct VCOS_MSGQUEUE_T
{
   struct VCOS_MSG_T *head;            /**< head of linked list of messages waiting on this queue */
   struct VCOS_MSG_T *tail;            /**< tail of message queue */
   VCOS_SEMAPHORE_T sem;               /**< thread waits on this for new messages */
   VCOS_MUTEX_T lock;                  /**< locks the messages list */
} VCOS_MSGQUEUE_T;

/** A single message
  */
typedef struct VCOS_MSG_T
{
   uint32_t code;                      /**< message code */
   int error;                          /**< error status signalled back to caller */
   VCOS_MSGQUEUE_T *dst;               /**< destination queue */
   VCOS_MSGQUEUE_T *src;               /**< source; replies go back to here */
   struct VCOS_MSG_T *next;            /**< next in queue */
   VCOS_THREAD_T *src_thread;          /**< for debug */
   uint32_t data[25];                  /**< payload area */
} VCOS_MSG_T;
   
/** An endpoint
  */
typedef struct VCOS_MSG_ENDPOINT_T
{
   VCOS_MSGQUEUE_T primary;            /**< incoming messages */
   VCOS_MSGQUEUE_T secondary;          /**< this is used for waitspecific */
   char name[32];                      /**< name of this endpoint, for find() */
   struct VCOS_MSG_ENDPOINT_T *next;   /**< next in global list of endpoints */
} VCOS_MSG_ENDPOINT_T;
#define MSG_REPLY_BIT (1<<31)

/** Initalise the library. Normally called from vcos_init().
  */
VCOSPRE_ VCOS_STATUS_T VCOSPOST_ vcos_msgq_init(void);

/** De-initialise the library. Normally called from vcos_deinit().
 */
VCOSPRE_ void VCOSPOST_ vcos_msgq_deinit(void);

/** Find a message queue by name and get a handle to it.
  *
  * @param name  the name of the queue to find
  *
  * @return The message queue, or NULL if not found.
  */
VCOSPRE_ VCOS_MSGQUEUE_T VCOSPOST_ *vcos_msgq_find(const char *name);

/** Wait for a message queue to come into existence. If it already exists,
  * return immediately, otherwise block.
  *
  * On the whole, if you find yourself using this, it is probably a sign
  * of poor design, since you should create all the server threads first,
  * and then the client threads. But it is sometimes useful.
  *
  * @param name  the name of the queue to find
  * @return The message queue
  */
VCOSPRE_ VCOS_MSGQUEUE_T VCOSPOST_ *vcos_msgq_wait(const char *name);

/** Send a message.
  */
VCOSPRE_ void VCOSPOST_ vcos_msg_send(VCOS_MSGQUEUE_T *dest, uint32_t code, VCOS_MSG_T *msg);

/** Send a message and wait for a reply.
  */
VCOSPRE_ void VCOSPOST_ vcos_msg_sendwait(VCOS_MSGQUEUE_T *queue, uint32_t code, VCOS_MSG_T *msg);

/** Wait for a message on this thread's endpoint.
  */
VCOSPRE_ VCOS_MSG_T * VCOSPOST_ vcos_msg_wait(void);

/** Wait for a specific message.
  */
VCOS_MSG_T * vcos_msg_wait_specific(VCOS_MSGQUEUE_T *queue, VCOS_MSG_T *msg);

/** Peek for a message on this thread's endpoint, if a message is not available, NULL is 
    returned. If a message is available it will be removed from the endpoint and returned.
  */
VCOSPRE_ VCOS_MSG_T * VCOSPOST_ vcos_msg_peek(void);

/** Send a reply to a message
  */
VCOSPRE_ void VCOSPOST_ vcos_msg_reply(VCOS_MSG_T *msg);

/** Create an endpoint. Each thread should need no more than one of these - if you 
  * find yourself needing a second one, you've done something wrong.
  */
VCOSPRE_ VCOS_STATUS_T VCOSPOST_ vcos_msgq_endpoint_create(VCOS_MSG_ENDPOINT_T *ep, const char *name);

/** Destroy an endpoint.
  */
VCOSPRE_ void  VCOSPOST_ vcos_msgq_endpoint_delete(VCOS_MSG_ENDPOINT_T *ep);

#ifdef __cplusplus
}
#endif
#endif


<file_sep>#!/bin/bash
mkdir -p build/arm-android/release/
pushd build/arm-android/release/
echo "Before running this, set ANDROID_ROOT to your root-Android-dir, and ANDROID_TOOLCHAIN to your toolchain's /bin dir."
cmake -DCMAKE_TOOLCHAIN_FILE=../../../makefiles/cmake/toolchains/arm-android.cmake -DCMAKE_BUILD_TYPE=Release ../../..
make
popd

<file_sep>#
# CMake defines to cross-compile to ARM/Linux on BCM2708 using glibc.
#


# Note that the compilers should be in $ANDROID_TOOLCHAIN
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_C_COMPILER $ENV{ANDROID_TOOLCHAIN}/arm-linux-androideabi-gcc)
SET(CMAKE_CXX_COMPILER $ENV{ANDROID_TOOLCHAIN}/arm-linux-androideabi-g++)
SET(CMAKE_ASM_COMPILER $ENV{ANDROID_TOOLCHAIN}/arm-linux-androideabi-as)
SET(CMAKE_SYSTEM_PROCESSOR arm)
SET(ANDROID TRUE)

#ADD_DEFINITIONS("-march=armv6")
add_definitions("-mcpu=arm1176jzf-s")

# rdynamic means the backtrace should work
IF (CMAKE_BUILD_TYPE MATCHES "Debug")
   add_definitions(-rdynamic)
ENDIF()

# avoids annoying and pointless warnings from gcc
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -U_FORTIFY_SOURCE")

<file_sep>#ifndef _GRLC_H
#define _GRLC_H
#include "include/ui/android_native_buffer.h"
typedef struct gralloc_private_handle_t{

	int res_type;
	int w;
	int h;
	int stride;
	uint32_t vcHandle;
	int gl_format;
	android_native_buffer_t * buffer;


} gralloc_private_handle_t;

/*
typedef __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef __int8 int8_t;
typedef unsigned __int8 uint8_t;
*/
const int GRALLOC_PRIV_TYPE_MM_RESOURCE = 0;
const int GRALLOC_PRIV_TYPE_GL_RESOURCE = 1;

const int GRALLOC_MAGICS_HAL_PIXEL_FORMAT_OPAQUE = 0;
const int GRALLOC_MAGICS_HAL_PIXEL_FORMAT_TRANSLUCENT = 1;

gralloc_private_handle_t* gralloc_private_handle_from_client_buffer(EGLClientBuffer buffer);
uint32_t gralloc_private_handle_get_vc_handle(gralloc_private_handle_t *b);
uint32_t gralloc_private_handle_get_egl_image(gralloc_private_handle_t *b);
int gralloc_get_pf(gralloc_private_handle_t *b);

#endif
<file_sep>This repository contains the source code for the ARM side libraries used on Raspberry Pi.
These typically are installed in /opt/vc/lib and includes source for the ARM side code to interface to:
EGL, mmal, GLESv2, vcos, openmaxil, vchiq_arm, bcm_host, WFC, OpenVG.

This is an effort to create an Android-compatible version of the libraries. It <em>should</em> be usable as of commit '168441d31c'. However, as there's no working gralloc module for Android on the Raspberry Pi, there's no real way of knowing if it is. If you happen to discover any issue with the libs, post an issue and it'll be looked into, or better yet, fork me and fix it yourself, then gimme a pull request.

Use buildme.android to build. It requires cmake to be installed and an arm cross compiler.
Before running buildme.android, set the environment variables 'ANDROID_ROOT' to your root-Android-dir (as in, your CyanogenMod source tree with proper RPi-patches etc), and 'ANDROID_TOOLCHAIN' to your toolchain's /bin dir.</p>

Contact: #razdroid @ irc.freenode.net -- My nick is Warg.
<file_sep>/*
Copyright (c) 2012, Broadcom Europe Ltd
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of the copyright holder nor the
      names of its contributors may be used to endorse or promote products
      derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "mmal_clock.h"
#include "mmal_logging.h"
#include "core/mmal_clock_private.h"
#include "core/mmal_port_private.h"
#include "util/mmal_util.h"

#ifdef __VIDEOCORE__
# include "vcfw/rtos/common/rtos_common_mem.h"
#endif

/** Minimum number of buffers required on a clock port */
#define MMAL_PORT_CLOCK_BUFFERS_MIN  8

/** Private clock port context */
typedef struct MMAL_PORT_MODULE_T
{
   MMAL_PORT_CLOCK_EVENT_CB event_cb; /**< callback for notifying the component of clock events */
   MMAL_QUEUE_T *queue;               /**< queue for empty buffers sent to the port */
   MMAL_CLOCK_T *clock;               /**< clock module for scheduling requests */
   MMAL_BOOL_T is_reference;          /**< TRUE -> clock port is a reference, therefore
                                           will forward time updates */
} MMAL_PORT_MODULE_T;

/*****************************************************************************
 * Private functions
 *****************************************************************************/
#ifdef __VIDEOCORE__
/* FIXME: mmal_buffer_header_mem_lock() assumes that payload memory is on the
 * relocatable heap when on VC. However that is not always the case. The MMAL
 * framework will allocate memory from the normal heap when ports are connected.
 * To work around this, override the default behaviour by providing a payload
 * allocator for clock ports which always allocates from the relocatable heap. */
static uint8_t* mmal_port_clock_payload_alloc(MMAL_PORT_T *port, uint32_t payload_size)
{
   int alignment = port->buffer_alignment_min;
   uint8_t *mem;

   if (!alignment)
      alignment = 32;
   vcos_assert((alignment & (alignment-1)) == 0);

   mem = (uint8_t*)mem_alloc(payload_size, alignment, MEM_FLAG_DIRECT, port->name);
   if (!mem)
   {
      LOG_ERROR("could not allocate %u bytes", payload_size);
      return NULL;
   }
   return mem;
}

static void mmal_port_clock_payload_free(MMAL_PORT_T *port, uint8_t *payload)
{
   MMAL_PARAM_UNUSED(port);
   mem_release((MEM_HANDLE_T)payload);
}
#endif


/* Callback invoked by the clock module in response to a client request */
static void mmal_port_clock_request_cb(MMAL_CLOCK_T* clock, int64_t media_time, void *cb_data, MMAL_CLOCK_VOID_FP cb)
{
   MMAL_PORT_CLOCK_REQUEST_CB cb_client = (MMAL_PORT_CLOCK_REQUEST_CB)cb;

   /* Forward to the client */
   cb_client((MMAL_PORT_T*)clock->user_data, media_time, cb_data);
}

/* Process buffers received from other clock ports */
static MMAL_STATUS_T mmal_port_clock_process_buffer(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
{
   MMAL_STATUS_T status = MMAL_SUCCESS;
   MMAL_CLOCK_PAYLOAD_T payload;

   if (buffer->length != sizeof(MMAL_CLOCK_PAYLOAD_T))
   {
      LOG_ERROR("invalid buffer length %d", buffer->length);
      return MMAL_EINVAL;
   }

   mmal_buffer_header_mem_lock(buffer);
   memcpy(&payload, buffer->data, sizeof(MMAL_CLOCK_PAYLOAD_T));
   mmal_buffer_header_mem_unlock(buffer);

   if (payload.magic != MMAL_CLOCK_PAYLOAD_MAGIC)
   {
      LOG_ERROR("buffer corrupt (magic %4.4s)", (char*)&payload.magic);
      return MMAL_EINVAL;
   }

   LOG_TRACE("port %s length %d id %4.4s time %"PRIi64,
         port->name, buffer->length, (char*)&payload.id, payload.time);

   switch (payload.id)
   {
   case MMAL_CLOCK_PAYLOAD_TIME:
      mmal_clock_media_time_set(port->priv->module->clock, payload.time);
      break;
   case MMAL_CLOCK_PAYLOAD_SCALE:
      mmal_clock_scale_set(port->priv->module->clock, payload.data.scale);
      break;
   default:
      LOG_ERROR("invalid id %4.4s", (char*)&payload.id);
      status = MMAL_EINVAL;
      break;
   }

   /* Finished with the buffer, so return it */
   buffer->length = 0;
   mmal_port_buffer_header_callback(port, buffer);

   return status;
}

static MMAL_STATUS_T mmal_port_clock_send(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
{
   MMAL_PORT_MODULE_T *module = port->priv->module;

   if (buffer->length)
      return mmal_port_clock_process_buffer(port, buffer);

   /* Queue empty buffers to be used later when forwarding clock updates */
   mmal_queue_put(module->queue, buffer);

   return MMAL_SUCCESS;
}

static MMAL_STATUS_T mmal_port_clock_flush(MMAL_PORT_T *port)
{
   MMAL_BUFFER_HEADER_T *buffer;

   /* Flush empty buffers */
   buffer = mmal_queue_get(port->priv->module->queue);
   while (buffer)
   {
      mmal_port_buffer_header_callback(port, buffer);
      buffer = mmal_queue_get(port->priv->module->queue);
   }

   return MMAL_SUCCESS;
}

static MMAL_STATUS_T mmal_port_clock_parameter_set(MMAL_PORT_T *port, const MMAL_PARAMETER_HEADER_T *param)
{
   MMAL_STATUS_T status = MMAL_SUCCESS;
   MMAL_PORT_MODULE_T *module = port->priv->module;
   MMAL_CLOCK_PAYLOAD_T event;

   switch (param->id)
   {
      case MMAL_PARAMETER_CLOCK_REFERENCE:
      {
         const MMAL_PARAMETER_BOOLEAN_T *p = (const MMAL_PARAMETER_BOOLEAN_T*)param;
         module->is_reference = p->enable;
         event.id = MMAL_CLOCK_PAYLOAD_REFERENCE;
         event.time = mmal_clock_media_time_get(module->clock);
         event.data.enable = p->enable;
      }
      break;
      case MMAL_PARAMETER_CLOCK_ACTIVE:
      {
         const MMAL_PARAMETER_BOOLEAN_T *p = (const MMAL_PARAMETER_BOOLEAN_T*)param;
         status = mmal_clock_active_set(module->clock, p->enable);
         event.id = MMAL_CLOCK_PAYLOAD_ACTIVE;
         event.time = mmal_clock_media_time_get(module->clock);
         event.data.enable = p->enable;
      }
      break;
      case MMAL_PARAMETER_CLOCK_SCALE:
      {
         const MMAL_PARAMETER_RATIONAL_T *p = (const MMAL_PARAMETER_RATIONAL_T*)param;
         status = mmal_port_clock_scale_set(port, p->value);
         event.id = MMAL_CLOCK_PAYLOAD_SCALE;
         event.time = mmal_clock_media_time_get(module->clock);
         event.data.scale = p->value;
      }
      break;
      case MMAL_PARAMETER_CLOCK_TIME:
      {
         const MMAL_PARAMETER_INT64_T *p = (const MMAL_PARAMETER_INT64_T*)param;
         status = mmal_port_clock_media_time_set(port, p->value);
         event.id = MMAL_CLOCK_PAYLOAD_INVALID;
      }
      break;
      case MMAL_PARAMETER_CLOCK_TIME_OFFSET:
      {
         const MMAL_PARAMETER_INT64_T *p = (const MMAL_PARAMETER_INT64_T*)param;
         status = mmal_port_clock_media_time_offset_set(port, p->value);
         event.id = MMAL_CLOCK_PAYLOAD_INVALID;
      }
      break;
      case MMAL_PARAMETER_CLOCK_UPDATE_THRESHOLD:
      {
         const MMAL_PARAMETER_CLOCK_UPDATE_THRESHOLD_T *p = (MMAL_PARAMETER_CLOCK_UPDATE_THRESHOLD_T *)param;
         status = mmal_clock_update_threshold_set(module->clock, p);
         event.id = MMAL_CLOCK_PAYLOAD_INVALID;
      }
      break;
      case MMAL_PARAMETER_CLOCK_DISCONT_THRESHOLD:
      {
         const MMAL_PARAMETER_CLOCK_DISCONT_THRESHOLD_T *p = (MMAL_PARAMETER_CLOCK_DISCONT_THRESHOLD_T *)param;
         status = mmal_clock_discont_threshold_set(module->clock, p);
         event.id = MMAL_CLOCK_PAYLOAD_INVALID;
      }
      break;
      default:
         return MMAL_ENOSYS;
   }

   /* Notify the component */
   if (module->event_cb && status == MMAL_SUCCESS && event.id != MMAL_CLOCK_PAYLOAD_INVALID)
      module->event_cb(port, &event);

   return status;
}

static MMAL_STATUS_T mmal_port_clock_parameter_get(MMAL_PORT_T *port, MMAL_PARAMETER_HEADER_T *param)
{
   MMAL_PORT_MODULE_T *module = port->priv->module;

   switch (param->id)
   {
      case MMAL_PARAMETER_CLOCK_REFERENCE:
      {
         MMAL_PARAMETER_BOOLEAN_T *p = (MMAL_PARAMETER_BOOLEAN_T*)param;
         p->enable = module->is_reference;
      }
      break;
      case MMAL_PARAMETER_CLOCK_ACTIVE:
      {
         MMAL_PARAMETER_BOOLEAN_T *p = (MMAL_PARAMETER_BOOLEAN_T*)param;
         p->enable = mmal_clock_is_active(module->clock);
      }
      break;
      case MMAL_PARAMETER_CLOCK_SCALE:
      {
         MMAL_PARAMETER_RATIONAL_T *p = (MMAL_PARAMETER_RATIONAL_T*)param;
         p->value = mmal_clock_scale_get(module->clock);
      }
      break;
      case MMAL_PARAMETER_CLOCK_TIME:
      {
         MMAL_PARAMETER_INT64_T *p = (MMAL_PARAMETER_INT64_T*)param;
         p->value = mmal_clock_media_time_get(module->clock);
      }
      break;
      case MMAL_PARAMETER_CLOCK_TIME_OFFSET:
      {
         MMAL_PARAMETER_INT64_T *p = (MMAL_PARAMETER_INT64_T*)param;
         p->value = mmal_clock_media_time_offset_get(module->clock);
      }
      break;
      case MMAL_PARAMETER_CLOCK_UPDATE_THRESHOLD:
      {
         MMAL_PARAMETER_CLOCK_UPDATE_THRESHOLD_T *p = (MMAL_PARAMETER_CLOCK_UPDATE_THRESHOLD_T *)param;
         mmal_clock_update_threshold_get(module->clock, p);
      }
      break;
      case MMAL_PARAMETER_CLOCK_DISCONT_THRESHOLD:
      {
         MMAL_PARAMETER_CLOCK_DISCONT_THRESHOLD_T *p = (MMAL_PARAMETER_CLOCK_DISCONT_THRESHOLD_T *)param;
         mmal_clock_discont_threshold_get(module->clock, p);
      }
      break;
      default:
         return MMAL_ENOSYS;
   }
   return MMAL_SUCCESS;
}

static MMAL_STATUS_T mmal_port_clock_enable(MMAL_PORT_T *port, MMAL_PORT_BH_CB_T cb)
{
   MMAL_PARAM_UNUSED(port);
   MMAL_PARAM_UNUSED(cb);
   return MMAL_SUCCESS;
}

static MMAL_STATUS_T mmal_port_clock_disable(MMAL_PORT_T *port)
{
   MMAL_PORT_MODULE_T *module = port->priv->module;

   if (mmal_clock_is_active(module->clock))
      mmal_clock_active_set(module->clock, MMAL_FALSE);

   mmal_port_clock_flush(port);

   return MMAL_SUCCESS;
}

static MMAL_STATUS_T mmal_port_clock_set_format(MMAL_PORT_T *port)
{
   MMAL_PARAM_UNUSED(port);
   return MMAL_SUCCESS;
}

static MMAL_STATUS_T mmal_port_clock_connect(MMAL_PORT_T *port, MMAL_PORT_T *other_port)
{
   MMAL_PARAM_UNUSED(port);
   MMAL_PARAM_UNUSED(other_port);
   return MMAL_ENOSYS;
}

/* Send a payload buffer to a connected port/client */
static MMAL_STATUS_T mmal_port_clock_forward_payload(MMAL_PORT_T *port, const MMAL_CLOCK_PAYLOAD_T *payload)
{
   MMAL_STATUS_T status;
   MMAL_BUFFER_HEADER_T *buffer;

   buffer = mmal_queue_get(port->priv->module->queue);
   if (!buffer)
   {
      LOG_ERROR("no free buffers available");
      return MMAL_ENOSPC;
   }

   status = mmal_buffer_header_mem_lock(buffer);
   if (status != MMAL_SUCCESS)
   {
      LOG_ERROR("failed to lock buffer %s", mmal_status_to_string(status));
      mmal_queue_put_back(port->priv->module->queue, buffer);
      goto end;
   }
   buffer->length = sizeof(MMAL_CLOCK_PAYLOAD_T);
   memcpy(buffer->data, payload, buffer->length);
   mmal_buffer_header_mem_unlock(buffer);

   mmal_port_buffer_header_callback(port, buffer);

end:
   return status;
}

/* Send a clock time update to a connected port/client */
static MMAL_STATUS_T mmal_port_clock_forward_media_time(MMAL_PORT_T *port, int64_t media_time)
{
   MMAL_CLOCK_PAYLOAD_T payload;

   payload.id = MMAL_CLOCK_PAYLOAD_TIME;
   payload.magic = MMAL_CLOCK_PAYLOAD_MAGIC;
   payload.time = media_time;

   return mmal_port_clock_forward_payload(port, &payload);
}

/* Send a clock scale update to a connected port/client */
static MMAL_STATUS_T mmal_port_clock_forward_scale(MMAL_PORT_T *port, MMAL_RATIONAL_T scale)
{
   MMAL_CLOCK_PAYLOAD_T payload;

   payload.id = MMAL_CLOCK_PAYLOAD_SCALE;
   payload.magic = MMAL_CLOCK_PAYLOAD_MAGIC;
   payload.time = mmal_clock_media_time_get(port->priv->module->clock);
   payload.data.scale = scale;

   return mmal_port_clock_forward_payload(port, &payload);
}

/* Initialise all callbacks and setup internal resources */
static MMAL_STATUS_T mmal_port_clock_setup(MMAL_PORT_T *port, MMAL_PORT_CLOCK_EVENT_CB event_cb)
{
   MMAL_STATUS_T status;

   status = mmal_clock_create(&port->priv->module->clock);
   if (status != MMAL_SUCCESS)
   {
      LOG_ERROR("failed to create clock module on port %s (%s)", port->name, mmal_status_to_string(status));
      return status;
   }
   port->priv->module->clock->user_data = port;

   port->buffer_size = sizeof(MMAL_CLOCK_PAYLOAD_T);
   port->buffer_size_min = sizeof(MMAL_CLOCK_PAYLOAD_T);
   port->buffer_num_min = MMAL_PORT_CLOCK_BUFFERS_MIN;
   port->buffer_num_recommended = MMAL_PORT_CLOCK_BUFFERS_MIN;

   port->priv->module->event_cb = event_cb;
   port->priv->module->queue = mmal_queue_create();
   if (!port->priv->module->queue)
   {
      mmal_clock_destroy(port->priv->module->clock);
      return MMAL_ENOMEM;
   }

   port->priv->pf_set_format = mmal_port_clock_set_format;
   port->priv->pf_enable = mmal_port_clock_enable;
   port->priv->pf_disable = mmal_port_clock_disable;
   port->priv->pf_send = mmal_port_clock_send;
   port->priv->pf_flush = mmal_port_clock_flush;
   port->priv->pf_parameter_set = mmal_port_clock_parameter_set;
   port->priv->pf_parameter_get = mmal_port_clock_parameter_get;
   port->priv->pf_connect = mmal_port_clock_connect;
#ifdef __VIDEOCORE__
   port->priv->pf_payload_alloc = mmal_port_clock_payload_alloc;
   port->priv->pf_payload_free = mmal_port_clock_payload_free;
   port->capabilities = MMAL_PORT_CAPABILITY_ALLOCATION;
#endif

   return status;
}

/* Release all internal resources */
static void mmal_port_clock_teardown(MMAL_PORT_T *port)
{
   if (!port)
      return;
   mmal_queue_destroy(port->priv->module->queue);
   mmal_clock_destroy(port->priv->module->clock);
}

/*****************************************************************************
 * Public functions
 *****************************************************************************/
/* Allocate a clock port */
MMAL_PORT_T* mmal_port_clock_alloc(MMAL_COMPONENT_T *component, MMAL_PORT_CLOCK_EVENT_CB event_cb)
{
   MMAL_PORT_T *port;

   port = mmal_port_alloc(component, MMAL_PORT_TYPE_CLOCK, sizeof(MMAL_PORT_MODULE_T));
   if (!port)
      return NULL;

   if (mmal_port_clock_setup(port, event_cb) != MMAL_SUCCESS)
   {
      mmal_port_free(port);
      return NULL;
   }

   return port;
}

/* Free a clock port */
void mmal_port_clock_free(MMAL_PORT_T *port)
{
   mmal_port_clock_teardown(port);
   mmal_port_free(port);
}

/* Allocate an array of clock ports */
MMAL_PORT_T **mmal_ports_clock_alloc(MMAL_COMPONENT_T *component, unsigned int ports_num, MMAL_PORT_CLOCK_EVENT_CB event_cb)
{
   unsigned int i;
   MMAL_PORT_T **ports;

   ports = mmal_ports_alloc(component, ports_num, MMAL_PORT_TYPE_CLOCK, sizeof(MMAL_PORT_MODULE_T));
   if (!ports)
      return NULL;

   for (i = 0; i < ports_num; i++)
   {
      if (mmal_port_clock_setup(ports[i], event_cb) != MMAL_SUCCESS)
         break;
   }

   if (i != ports_num)
   {
      for (ports_num = i, i = 0; i < ports_num; i++)
         mmal_port_clock_free(ports[i]);
      vcos_free(ports);
      return NULL;
   }

   return ports;
}

/* Free an array of clock ports */
void mmal_ports_clock_free(MMAL_PORT_T **ports, unsigned int ports_num)
{
   unsigned int i;

   for (i = 0; i < ports_num; i++)
      mmal_port_clock_free(ports[i]);
   vcos_free(ports);
}

/* Register a callback request */
MMAL_STATUS_T mmal_port_clock_request_add(MMAL_PORT_T *port, int64_t media_time, int64_t offset,
      MMAL_PORT_CLOCK_REQUEST_CB cb, void *cb_data)
{
   return mmal_clock_request_add(port->priv->module->clock, media_time, offset,
                                 mmal_port_clock_request_cb, cb_data, (MMAL_CLOCK_VOID_FP)cb);
}

/* Flush all pending clock requests */
MMAL_STATUS_T mmal_port_clock_request_flush(MMAL_PORT_T *port)
{
   return mmal_clock_request_flush(port->priv->module->clock);
}

/* Set the media-time on the clock port */
MMAL_STATUS_T mmal_port_clock_media_time_set(MMAL_PORT_T *port, int64_t media_time)
{
   MMAL_STATUS_T status;

   status = mmal_clock_media_time_set(port->priv->module->clock, media_time);
   if (status != MMAL_SUCCESS)
   {
      LOG_DEBUG("clock update ignored");
      return status;
   }

   /* Only forward time updates if this port is set as a reference clock port */
   if (port->priv->module->is_reference)
      mmal_port_clock_forward_media_time(port, mmal_clock_media_time_get(port->priv->module->clock));

   return status;
}

/* Set the media-time offset on the clock port */
MMAL_STATUS_T mmal_port_clock_media_time_offset_set(MMAL_PORT_T *port, int64_t offset)
{
   MMAL_STATUS_T status;

   status = mmal_clock_media_time_offset_set(port->priv->module->clock, offset);

   /* The media-time has effectively changed, so need to inform connected clock ports */
   if (port->priv->module->is_reference)
      mmal_port_clock_forward_media_time(port, mmal_clock_media_time_get(port->priv->module->clock));

   return status;
}

/* Return the current media-time */
int64_t mmal_port_clock_media_time_get(MMAL_PORT_T *port)
{
   return mmal_clock_media_time_get(port->priv->module->clock);
}

/* Return the media-time offset */
int64_t mmal_port_clock_media_time_offset_get(MMAL_PORT_T *port)
{
   return mmal_clock_media_time_offset_get(port->priv->module->clock);
}

/* Set the clock scale factor */
MMAL_STATUS_T mmal_port_clock_scale_set(MMAL_PORT_T *port, MMAL_RATIONAL_T scale)
{
   MMAL_STATUS_T status;

   status = mmal_clock_scale_set(port->priv->module->clock, scale);

   if (port->priv->module->is_reference)
      mmal_port_clock_forward_scale(port, scale);

   return status;
}

/* Return the clock scale factor */
MMAL_RATIONAL_T mmal_port_clock_scale_get(MMAL_PORT_T *port)
{
   return mmal_clock_scale_get(port->priv->module->clock);
}

/* Return TRUE if clock is running (media-time is advancing) */
MMAL_BOOL_T mmal_port_clock_is_active(MMAL_PORT_T *port)
{
   return mmal_clock_is_active(port->priv->module->clock);
}

<file_sep>#ifndef __LOGGY__
#define NO_OPENVG 1
#include "include/android/log.h"
#define LOG_TAG "LOGGY_WARG"

# define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
# define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)

#define __LOGGY__ 1
#endif
<file_sep># setup environment for cross compile to arm-linux

if (DEFINED CMAKE_TOOLCHAIN_FILE)
else()
   message(FATAL_ERROR 
	"  *********************************************************\n"
   	"  *   CMAKE_TOOLCHAIN_FILE not defined                    *\n"
	"  *   Please DELETE the build directory and re-run with:  *\n"
	"  *   -DCMAKE_TOOLCHAIN_FILE=toolchain_file.cmake         *\n"
	"  *                                                       *\n"
   	"  *   Toolchain files are in makefiles/cmake/toolchains.  *\n"
	"  *********************************************************"
       )
endif()

# pull in headers for android
if(ANDROID)
    # build shared libs
    OPTION (BUILD_SHARED_LIBS ON)

    #
    # work out where android headers and library are
    #
    set(ANDROID_PRODUCT "rpi" CACHE INTERNAL "" FORCE)
    set(ANDROID_ROOT $ENV{ANDROID_ROOT} CACHE INTERNAL "" FORCE)
    set(ANDROID_NDK_ROOT $ENV{ANDROID_NDK_ROOT} CACHE INTERNAL "" FORCE)
    set(ANDROID_LIBS $ENV{ANDROID_LIBS} CACHE INTERNAL "" FORCE)
    set(ANDROID_BIONIC $ENV{ANDROID_BIONIC} CACHE INTERNAL "" FORCE)
    set(ANDROID_LDSCRIPTS $ENV{ANDROID_LDSCRIPTS} CACHE INTERNAL "" FORCE)
      
    if("${ANDROID_NDK_ROOT}" STREQUAL "")
        find_program(ANDROID_COMPILER arm-eabi-gcc)
        get_filename_component(ANDROID_BIN ${ANDROID_COMPILER} PATH)
        find_path(_ANDROID_ROOT Makefile PATHS ${ANDROID_BIN}
                  PATH_SUFFIXES ../../../../..
                  NO_DEFAULT_PATH)
                if("${_ANDROID_ROOT}" STREQUAL "_ANDROID_ROOT-NOTFOUND")
                    set(_ANDROID_ROOT "$ENV{ANDROID_ROOT}" CACHE INTERNAL "" FORCE)
                endif()
                if("${_ANDROID_ROOT}" STREQUAL "")
            # message(FATAL_ERROR "Cannot find android root directory")
	    SET(ANDROID_ROOT ".")
        endif()
        get_filename_component(ANDROID_ROOT ${_ANDROID_ROOT} ABSOLUTE CACHE)
        #
        # top level of cross-compiler target include and lib directory structure
        #
        set(ANDROID_NDK_ROOT
            "${ANDROID_ROOT}/prebuilt/ndk" CACHE INTERNAL "" FORCE)
        set(ANDROID_BIONIC
            "${ANDROID_ROOT}/bionic" CACHE INTERNAL "" FORCE)
        set(ANDROID_LDSCRIPTS
            "${ANDROID_ROOT}/build/core" CACHE INTERNAL "" FORCE)
        set(ANDROID_LIBS
            "${ANDROID_ROOT}/out/target/product/${ANDROID_PRODUCT}/obj/lib"
            CACHE INTERNAL "" FORCE)
    endif()

    if("${ANDROID_NDK_ROOT}" STREQUAL "")
        message(FATAL_ERROR "Cannot find Android NDK root directory")
    endif()
    if("${ANDROID_BIONIC}" STREQUAL "")
        message(FATAL_ERROR "Cannot find Android BIONIC directory")
    endif()
    if("${ANDROID_LDSCRIPTS}" STREQUAL "")
        message(FATAL_ERROR "Cannot find Android LD scripts directory")
    endif()
    
    set(CMAKE_SYSTEM_PREFIX_PATH "${ANDROID_NDK_ROOT}/android-ndk-r${ANDROID_NDK_RELEASE}/platforms/android-${ANDROID_NDK_PLATFORM}/arch-${CMAKE_SYSTEM_PROCESSOR}/usr")
    
    if("${ANDROID_LIBS}" STREQUAL "")
        set(ANDROID_LIBS "${CMAKE_SYSTEM_PREFIX_PATH}/lib"
            CACHE INTERNAL "" FORCE)
        # message(FATAL_ERROR "Cannot find android libraries")
    endif()

    #
    # add include directories for pthreads
    #
    include_directories("${CMAKE_SYSTEM_PREFIX_PATH}/include" BEFORE SYSTEM)
    include_directories("${ANDROID_BIONIC}/libc/include/arch-arm/include" BEFORE SYSTEM)
    include_directories("${ANDROID_BIONIC}/libc/include" BEFORE SYSTEM)
    include_directories("${ANDROID_BIONIC}/libc/kernel/arch-arm" BEFORE SYSTEM)
    include_directories("${ANDROID_BIONIC}/libc/kernel/common" BEFORE SYSTEM)
    include_directories("${ANDROID_BIONIC}/libm/include" BEFORE SYSTEM)
    include_directories("${ANDROID_BIONIC}/libm/include/arch/arm" BEFORE SYSTEM)
    include_directories("${ANDROID_BIONIC}/libstdc++/include" BEFORE SYSTEM)
    

    #
    # Pull in Android link options manually
    #
    set(ANDROID_SHARED_CRTBEGIN "${ANDROID_TOOLCHAIN}/../lib/gcc/arm-linux-androideabi/4.6.3/crtbeginS.o")
    set(ANDROID_SHARED_CRTEND "${ANDROID_TOOLCHAIN}/../lib/gcc/arm-linux-androideabi/4.6.3/crtendS.o")
    set(CMAKE_SHARED_LINKER_FLAGS "-nostdlib ${ANDROID_SHARED_CRTBEGIN} -Wl,-Bdynamic -Wl,-T${ANDROID_LDSCRIPTS}/armelf.x")
    # set(ANDROID_CRTBEGIN "/home/viktor/arm-linux-androideabi-4.6.3/lib/gcc/arm-linux-androideabi/4.6.3/crtbegin.o")
    # set(ANDROID_CRTEND "/home/viktor/arm-linux-androideabi-4.6.3/lib/gcc/arm-linux-androideabi/4.6.3/crtend.o")

    link_directories(${ANDROID_LIBS})
    set(CMAKE_EXE_LINKER_FLAGS "-nostdlib ${ANDROID_SHARED_CRTBEGIN} -nostdlib -Wl,-z,noexecstack") 
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-dynamic-linker,/system/bin/linker -Wl,-rpath,${CMAKE_INSTALL_PREFIX}/lib")
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-T${ANDROID_LDSCRIPTS}/armelf.x -Wl,--gc-sections")
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,nocopyreloc -Wl,-z,noexecstack -Wl,--fix-cortex-a8 -Wl,--no-undefined")

    set(CMAKE_C_STANDARD_LIBRARIES "-llog -lc -lgcc ${ANDROID_SHARED_CRTEND}" CACHE INTERNAL "" FORCE)
    
    set(SHARED "SHARED")
else()
    set(SHARED "SHARED")
endif()


# All linux systems have sbrk()
add_definitions(-D_HAVE_SBRK)

# pull in declarations of lseek64 and friends
add_definitions(-D_LARGEFILE64_SOURCE)
	
# test for glibc malloc debugging extensions
try_compile(HAVE_MTRACE
            ${CMAKE_BINARY_DIR}
            ${CMAKE_SOURCE_DIR}/makefiles/cmake/srcs/test-mtrace.c
            OUTPUT_VARIABLE foo)

add_definitions(-DHAVE_CMAKE_CONFIG)
configure_file (
    "makefiles/cmake/cmake_config.h.in"
    "${PROJECT_BINARY_DIR}/cmake_config.h"
    )
 
<file_sep>#!/bin/bash
sudo apt-get install g++-4.6-arm-linux-gnueabi gcc-4.6-arm-linux-gnueabi binutils-arm-linux-gnueabi unzip

wget -O libs.zip https://www.dropbox.com/s/wovdzzxplqjze1o/req_libs.zip?dl=1
unzip libs.zip

rm -rf build
mkdir -p build/arm-android/release/
pushd build/arm-android/release/
cmake -DCMAKE_TOOLCHAIN_FILE=../../../makefiles/cmake/toolchains/drone-linux.cmake -DCMAKE_BUILD_TYPE=Release ../../..
make -j8
popd
<file_sep>add_library (mmal_core
   mmal_format.c
   mmal_port.c
   mmal_port_clock.c
   mmal_component.c
   mmal_buffer.c
   mmal_queue.c
   mmal_pool.c
   mmal_events.c
   mmal_logging.c
   mmal_clock.c
)

target_link_libraries (mmal_core vcos)

<file_sep>/*
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ANDROID_ANDROID_NATIVES_PRIV_H
#define ANDROID_ANDROID_NATIVES_PRIV_H

#include "include/ui/egl/android_natives.h"

#ifdef __cplusplus
extern "C" {
#endif

/*****************************************************************************/

typedef struct android_native_buffer_t
{
#ifdef __cplusplus
    android_native_buffer_t() { 
        common.magic = ANDROID_NATIVE_BUFFER_MAGIC;
        common.version = sizeof(android_native_buffer_t);
        memset(common.reserved, 0, sizeof(common.reserved));
    }

    // Implement the methods that sp<android_native_buffer_t> expects so that it
    // can be used to automatically refcount android_native_buffer_t's.
    void incStrong(const void* id) const {
        common.incRef(const_cast<android_native_base_t*>(&common));
    }
    void decStrong(const void* id) const {
        common.decRef(const_cast<android_native_base_t*>(&common));
    }
#endif

    struct android_native_base_t common;

    int width;
    int height;
    int stride;
    int format;
    int usage;

    /* transformation as defined in hardware.h */
    uint8_t transform;

    uint8_t reserved_bytes[3];
    void* reserved[1];

    buffer_handle_t handle;

    void* reserved_proc[8];
} android_native_buffer_t;


/*****************************************************************************/

#ifdef __cplusplus
}
#endif

/*****************************************************************************/

#endif /* ANDROID_ANDROID_NATIVES_PRIV_H */
<file_sep>cmake_minimum_required(VERSION 2.8)

project(vmcs_host_apps)

set(BUILD_MMAL TRUE)
set(ANDROID TRUE)
set(BUILD_MMAL_APPS FALSE)
set(vmcs_root ${PROJECT_SOURCE_DIR})
get_filename_component(VIDEOCORE_ROOT . ABSOLUTE)

set(VCOS_PTHREADS_BUILD_SHARED TRUE)

include(makefiles/cmake/global_settings.cmake)

if(DRONE)
include(makefiles/cmake/arm-drone.cmake)
endif()

if(NOT DRONE)
include(makefiles/cmake/arm-linux.cmake)
endif()

include(makefiles/cmake/vmcs.cmake)

# Global include paths
include_directories(host_applications/framework)
include_directories(${PROJECT_SOURCE_DIR})
include_directories(interface/vcos/pthreads)
include_directories(interface/vmcs_host/linux)
include_directories(interface/vmcs_host)
include_directories(interface/vmcs_host/khronos)
include_directories(interface/khronos/include)
include_directories(${PROJECT_BINARY_DIR})
include_directories(interface/vchiq_arm)
#include_directories(tools/inet_transport)
include_directories(host_support/include)

# Global compiler flags
if(CMAKE_COMPILER_IS_GNUCC)
   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-multichar -Wall -Wno-unused-but-set-variable")
endif()

add_definitions(-D_REENTRANT)
add_definitions(-DUSE_VCHIQ_ARM -DVCHI_BULK_ALIGN=1 -DVCHI_BULK_GRANULARITY=1)
add_definitions(-DOMX_SKIP64BIT)
add_definitions(-DEGL_SERVER_DISPMANX)
add_definitions(-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE)

# do we actually need this?
add_definitions(-D__VIDEOCORE4__)


# add_definitions(-DKHRONOS_CLIENT_LOGGING)

# Check for OpenWF-C value set via command line
if(KHRONOS_EGL_PLATFORM MATCHES "openwfc")
   add_definitions(-DKHRONOS_EGL_PLATFORM_OPENWFC)
endif()
# "gralloc"
# add_subdirectory(gralloc)

# List of subsidiary CMakeLists
add_subdirectory(interface/vcos)
add_subdirectory(interface/vmcs_host)
add_subdirectory(interface/vchiq_arm)
add_subdirectory(interface/khronos)

#add_subdirectory(opensrc/tools/lua)
if(BUILD_MMAL)
   include_directories(interface/mmal)
   add_subdirectory(interface/mmal)
endif()

#add_subdirectory(containers)
add_subdirectory(middleware/openmaxil)

# 3d demo code
#if(NOT ANDROID)
#   add_subdirectory(thirdparty/applications/demos)
#   add_subdirectory(opensrc/applications/demos)
#endif()

#if(ENABLE_3D_TESTS)
#   add_subdirectory(thirdparty/applications/test)
#endif()

# FIXME: this directory needs a more sensible name and better
# platform factoring
add_subdirectory(interface/usbdk)

# FIXME: we should use a pre-packaged version of freetype
# rather than the one included in the repo.
#add_subdirectory(opensrc/helpers/freetype)
#add_subdirectory(${PROJECT_SOURCE_DIR}/opensrc/helpers/fonts/ttf-bitstream-vera)

# VMCS Host Applications
#add_subdirectory(host_applications/framework)
#add_subdirectory(host_applications/vmcs)

# add_subdirectory(interface/vchiq/test/win32)

# Apps and libraries supporting Camera Tuning Tool
#add_subdirectory(tools/inet_transport/linux)
#add_subdirectory(host_support/vcstandalone)

# add linux apps
add_subdirectory(host_applications/linux)

set(vmcs_host_apps_VERSION_MAJOR 1)
set(vmcs_host_apps_VERSION_MINOR 0)

include_directories("${PROJECT_BINARY_DIR}")

# Remove cache entry, if one added by command line
unset(KHRONOS_EGL_PLATFORM CACHE)
<file_sep>if (WIN32)
   set(VCOS_PLATFORM win32)
else ()
   set(VCOS_PLATFORM pthreads)
   add_definitions(-Wall -Werror)
endif ()

include_directories( ../ )

add_library(grlc ${SHARED} gralloc.c)

target_link_libraries(grlc vcos)

install(TARGETS grlc DESTINATION lib)

<file_sep>add_library (mmal_util
   mmal_il.c
   mmal_util.c
   mmal_connection.c
   mmal_graph.c
   mmal_list.c
   mmal_param_convert.c
   mmal_util_params.c
   mmal_component_wrapper.c
   mmal_util_rational.c
)

target_link_libraries (mmal_util vcos)

<file_sep>#
# CMake defines to cross-compile to ARM/Linux on BCM2708 using glibc.
#


# Note that the compilers should be in $ANDROID_TOOLCHAIN
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_C_COMPILER arm-linux-gnueabi-gcc-4.6)
SET(CMAKE_CXX_COMPILER arm-linux-gnueabi-g++-4.6)
SET(CMAKE_ASM_COMPILER arm-linux-gnueabi-as)
SET(CMAKE_SYSTEM_PROCESSOR arm)
SET(ANDROID_ROOT lib)
SET(ANDROID TRUE)
SET(DRONE TRUE)

#ADD_DEFINITIONS("-march=armv6")
add_definitions("-mcpu=arm1176jzf-s")

# rdynamic means the backtrace should work
IF (CMAKE_BUILD_TYPE MATCHES "Debug")
   add_definitions(-rdynamic)
ENDIF()

# avoids annoying and pointless warnings from gcc
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -U_FORTIFY_SOURCE")

<file_sep>/*
 * Copyright (C) 2005 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

//

// Pixel formats used across the system.
// These formats might not all be supported by all renderers, for instance
// skia or SurfaceFlinger are not required to support all of these formats
// (either as source or destination)

// XXX: we should consolidate these formats and skia's

#ifndef UI_PIXELFORMAT_H
#define UI_PIXELFORMAT_H

#include <stdint.h>
#include <sys/types.h>
//#include <utils/Errors.h>
#include "include/pixelflinger/format.h"
#include "include/hardware/hardware.h"

//namespace android {

enum {
    //
    // these constants need to match those
    // in graphics/PixelFormat.java & pixelflinger/format.h
    //
    PIXEL_FORMAT_UNKNOWN    =   0,
    PIXEL_FORMAT_NONE       =   0,

    // logical pixel formats used by the SurfaceFlinger -----------------------
    PIXEL_FORMAT_CUSTOM         = -4,
        // Custom pixel-format described by a PixelFormatInfo structure

    PIXEL_FORMAT_TRANSLUCENT    = -3,
        // System chooses a format that supports translucency (many alpha bits)

    PIXEL_FORMAT_TRANSPARENT    = -2,
        // System chooses a format that supports transparency
        // (at least 1 alpha bit)

    PIXEL_FORMAT_OPAQUE         = -1,
        // System chooses an opaque format (no alpha bits required)
    
    // real pixel formats supported for rendering -----------------------------

    PIXEL_FORMAT_RGBA_8888   = HAL_PIXEL_FORMAT_RGBA_8888,  // 4x8-bit RGBA
    PIXEL_FORMAT_RGBX_8888   = HAL_PIXEL_FORMAT_RGBX_8888,  // 4x8-bit RGB0
    PIXEL_FORMAT_RGB_888     = HAL_PIXEL_FORMAT_RGB_888,    // 3x8-bit RGB
    PIXEL_FORMAT_RGB_565     = HAL_PIXEL_FORMAT_RGB_565,    // 16-bit RGB
    PIXEL_FORMAT_BGRA_8888   = HAL_PIXEL_FORMAT_BGRA_8888,  // 4x8-bit BGRA
    PIXEL_FORMAT_RGBA_5551   = HAL_PIXEL_FORMAT_RGBA_5551,  // 16-bit ARGB
    PIXEL_FORMAT_RGBA_4444   = HAL_PIXEL_FORMAT_RGBA_4444,  // 16-bit ARGB
    PIXEL_FORMAT_A_8         = GGL_PIXEL_FORMAT_A_8,        // 8-bit A
    PIXEL_FORMAT_L_8         = GGL_PIXEL_FORMAT_L_8,        // 8-bit L (R=G=B=L)
    PIXEL_FORMAT_LA_88       = GGL_PIXEL_FORMAT_LA_88,      // 16-bit LA
    PIXEL_FORMAT_RGB_332     = GGL_PIXEL_FORMAT_RGB_332,    // 8-bit RGB

    // New formats can be added if they're also defined in
    // pixelflinger/format.h
};

typedef int32_t PixelFormat;

/*struct PixelFormatInfo
{
    enum {
        INDEX_ALPHA   = 0,
        INDEX_RED     = 1,
        INDEX_GREEN   = 2,
        INDEX_BLUE    = 3
    };
    
    enum { // components
        ALPHA               = 1,
        RGB                 = 2,
        RGBA                = 3,
        LUMINANCE           = 4,
        LUMINANCE_ALPHA     = 5,
        OTHER               = 0xFF
    };

    struct szinfo {
        uint8_t h;
        uint8_t l;
    };
    
    inline PixelFormatInfo() : version(sizeof(PixelFormatInfo)) { }
    size_t getScanlineSize(unsigned int width) const;
    size_t getSize(size_t ci) const { 
        return (ci <= 3) ? (cinfo[ci].h - cinfo[ci].l) : 0;
    }
    size_t      version;
    PixelFormat format;
    size_t      bytesPerPixel;
    size_t      bitsPerPixel;
    union {
        szinfo      cinfo[4];
        struct {
            uint8_t     h_alpha;
            uint8_t     l_alpha;    
            uint8_t     h_red;
            uint8_t     l_red;
            uint8_t     h_green;
            uint8_t     l_green;
            uint8_t     h_blue;
            uint8_t     l_blue;
        };
    };
    uint8_t     components;
    uint8_t     reserved0[3];
    uint32_t    reserved1;
};

// Consider caching the results of these functions are they're not
// guaranteed to be fast.
ssize_t     bytesPerPixel(PixelFormat format);
ssize_t     bitsPerPixel(PixelFormat format);
status_t    getPixelFormatInfo(PixelFormat format, PixelFormatInfo* info);

}; // namespace android
*/
#endif // UI_PIXELFORMAT_H
