PDA

View Full Version : Sample Implementation



jonathan
11-23-2009, 07:42 AM
I have a question regarding the provided sample implementation of OpenWF.
Is it possible to provide a simple demo programm, i do not understand how the sample implementation is supposed to be used. Which headers must I include, and how do I get a reference to a NativeStreamType?
I have sucessfully compiled it, but I cant find a function to instantiate the required Native Types. Also the headers in the folder Khronos_include use Types like this:
WFCDevice, WFCContext and the other headers in the subfolders use Types like:
WFC_DEVICE, WFCCONTEXTTYPE and i do not see a typedef to convert these.

Has someone already got a small application working?

Thank you,
Jonathan

jpilon
11-23-2009, 10:07 AM
By the looks of it, you can create a NativeStream with owfNativeStreamCreateImageStream(); which requires you to include owfnativestream.h.

lremes
11-30-2009, 09:54 AM
The working group is working on the examples, but it will take some time before we can get them approved. In the meantime, here's some example code how to use the OpenWF sample implementation to create native stream/images.



#include "owfstream.h"

/*!
* Creates a native image stream.
* This function is WFC implementation specific.
*/
WFCNativeStreamType createNativeStream(WFCint width,
WFCint height,
WFCint numBuffers)
{
WFCNativeStreamType stream;
OWF_IMAGE_FORMAT imgf;

/* If you use other input format you need to modify these */
imgf.pixelFormat = OWF_IMAGE_ARGB8888;
imgf.linear = OWF_FALSE;
imgf.premultiplied = OWF_TRUE;
imgf.rowPadding = OWF_Image_GetFormatPadding(imgf.pixelFormat);

stream = owfNativeStreamCreateImageStream(width,
height,
&imgf,
numBuffers);

return stream;
}

/*!
* Write raw image data to native stream.
* Note that this function is WFC implementation specific.
*/
void writeImageToStream(WFCNativeStreamType stream, void* data, WFCint numPixels)
{
OWFNativeStreamBuffer buffer;
void* dataPtr;

buffer = owfNativeStreamAcquireWriteBuffer(stream);
dataPtr = owfNativeStreamGetBufferPtr(stream, buffer);

memcpy(dataPtr, data, numPixels * 4);

owfNativeStreamReleaseWriteBuffer(stream, buffer, EGL_DEFAULT_DISPLAY, EGL_NO_SYNC_KHR);
}

/*!
* Destroys native stream.
* Note that this function is WFC implementation specific.
*/
void destroyNativeStream(WFCNativeStreamType stream)
{
owfNativeStreamDestroy(stream);
}





static const int image_width = 250;
static const int image_height = 91;
static const khronos_uint32_t image_data[22750] = { image data as bytes here };
WFCNativeStreamType sourceStream = WFC_INVALID_HANDLE;

/* stream with two buffers */
sourceStream = createNativeStream(image_width, image_height, 2);

source = wfcCreateSourceFromStream(dev, ctx, sourceStream, NULL);

writeImageToStream(sourceStream, &image_data, image_width * image_height);

if (sourceStream != WFC_INVALID_HANDLE) {
destroyNativeStream(sourceStream);
}


OpenWF Display can also use images as source.



#include "owfimage.h"

/*!
* Creates a native image from pixel data.
* This function is WFD implementation specific.
*/
WFDEGLImage createNativeImage(int width,
int height,
void* data)
{
OWF_IMAGE_FORMAT imgf;
OWF_IMAGE* image = NULL;
WFDint stride, numBytes;

/* If you use other input format you need to modify these */
imgf.pixelFormat = OWF_IMAGE_ARGB8888;
imgf.linear = OWF_FALSE;
imgf.premultiplied = OWF_TRUE;
imgf.rowPadding = OWF_Image_GetFormatPadding(imgf.pixelFormat);

image = OWF_Image_Create(width, height, &imgf, NULL, 0);
assert(image != OWF_INVALID_HANDLE);

/* overflow if size2 < size1 */
stride = OWF_Image_GetStride(width, &imgf, 0);
numBytes = stride * height;

if (!image || !(image->data) || numBytes < stride) {
OWF_Image_Destroy(image);
image->data = NULL;
free(image);
image = NULL;
} else {
if (data) {
memcpy(image->data, data, numBytes);
}
}

return image;
}

void destroyNativeImage(WFDEGLImage image)
{
if (image != NULL)
{
OWF_Image_Destroy((OWF_IMAGE*)image);
image = NULL;
}
}


Usage:



static const int image_width = 250;
static const int image_height = 91;
static const khronos_uint32_t image_data[22750] = { image data as bytes here };
WFDEGLImage image = NULL;

image = createNativeImage(image_width, image_height, &image_data);
destroyNativeImage(image);