summaryrefslogtreecommitdiffstats
path: root/tools/qmeegographicssystemhelper/qmeegoruntime.cpp
blob: b1b0874e2a0efeecc4a29b1bb6d29baf7f94faf7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/

#include "mruntime.h"

#define ENSURE_INITIALIZED {if (!initialized) initialize();}

QLibrary* MRuntime::library = NULL;
bool MRuntime::initialized = false;

typedef int (*MImageToEglSharedImageFunc) (const QImage&);
typedef QPixmapData* (*MPixmapDataFromEglSharedImageFunc) (Qt::HANDLE handle, const QImage&);
typedef QPixmapData* (*MPixmapDataWithGLTextureFunc) (int w, int h);
typedef bool (*MDestroyEGLSharedImageFunc) (Qt::HANDLE handle);
typedef void (*MUpdateEglSharedImagePixmapFunc) (QPixmap*);
typedef void (*MSetSurfaceFixedSizeFunc) (int w, int h);
typedef void (*MSetSurfaceScalingFunc) (int x, int y, int w, int h);
typedef void (*MSetTranslucentFunc) (bool translucent);

static MImageToEglSharedImageFunc m_image_to_egl_shared_image = NULL;
static MPixmapDataFromEglSharedImageFunc m_pixmapdata_from_egl_shared_image = NULL;
static MPixmapDataWithGLTextureFunc m_pixmapdata_with_gl_texture = NULL;
static MDestroyEGLSharedImageFunc m_destroy_egl_shared_image = NULL;
static MUpdateEglSharedImagePixmapFunc m_update_egl_shared_image_pixmap = NULL;
static MSetSurfaceFixedSizeFunc m_set_surface_fixed_size = NULL;
static MSetSurfaceScalingFunc m_set_surface_scaling = NULL;
static MSetTranslucentFunc m_set_translucent = NULL;

void MRuntime::initialize()
{
    library = new QLibrary("/usr/lib/qt4/plugins/graphicssystems/libmeegographicssystem.so");
    Q_ASSERT(library);
    
    m_image_to_egl_shared_image = (MImageToEglSharedImageFunc) library->resolve("m_image_to_egl_shared_image");
    m_pixmapdata_from_egl_shared_image = (MPixmapDataFromEglSharedImageFunc)  library->resolve("m_pixmapdata_from_egl_shared_image");
    m_pixmapdata_with_gl_texture = (MPixmapDataWithGLTextureFunc) library->resolve("m_pixmapdata_with_gl_texture");
    m_destroy_egl_shared_image = (MDestroyEGLSharedImageFunc) library->resolve("m_destroy_egl_shared_image");
    m_update_egl_shared_image_pixmap = (MUpdateEglSharedImagePixmapFunc) library->resolve("m_update_egl_shared_image_pixmap");
    m_set_surface_fixed_size = (MSetSurfaceFixedSizeFunc) library->resolve("m_set_surface_fixed_size");
    m_set_surface_scaling = (MSetSurfaceScalingFunc) library->resolve("m_set_surface_scaling");
    m_set_translucent = (MSetTranslucentFunc) library->resolve("m_set_translucent");
    
    
    initialized = true;
}

Qt::HANDLE MRuntime::imageToEGLSharedImage(const QImage &image)
{
    ENSURE_INITIALIZED;
    Q_ASSERT(m_image_to_egl_shared_image);
    return m_image_to_egl_shared_image(image);
}

QPixmap MRuntime::pixmapFromEGLSharedImage(Qt::HANDLE handle, const QImage &softImage)
{
    ENSURE_INITIALIZED;
    Q_ASSERT(m_pixmapdata_from_egl_shared_image);
    return QPixmap(m_pixmapdata_from_egl_shared_image(handle, softImage));
}

QPixmap MRuntime::pixmapWithGLTexture(int w, int h)
{
    ENSURE_INITIALIZED;
    Q_ASSERT(m_pixmapdata_with_gl_texture);
    return QPixmap(m_pixmapdata_with_gl_texture(w, h));
}

bool MRuntime::destroyEGLSharedImage(Qt::HANDLE handle)
{
    ENSURE_INITIALIZED;
    Q_ASSERT(m_destroy_egl_shared_image);
    return m_destroy_egl_shared_image(handle);
}

void MRuntime::updateEGLSharedImagePixmap(QPixmap *p)
{
    ENSURE_INITIALIZED;
    Q_ASSERT(m_update_egl_shared_image_pixmap);
    return m_update_egl_shared_image_pixmap(p);
}

void MRuntime::setSurfaceFixedSize(int w, int h)
{
    ENSURE_INITIALIZED;
    Q_ASSERT(m_set_surface_fixed_size);
    m_set_surface_fixed_size(w, h);
}

void MRuntime::setSurfaceScaling(int x, int y, int w, int h)
{
    ENSURE_INITIALIZED;
    Q_ASSERT(m_set_surface_scaling);
    m_set_surface_scaling(x, y, w, h);
}

void MRuntime::setTranslucent(bool translucent)
{
    ENSURE_INITIALIZED;
    Q_ASSERT(m_set_translucent);
    m_set_translucent(translucent);
}