forked from moko365/mokoid-stub
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathmokoid_2d.cpp
78 lines (57 loc) · 1.38 KB
/
mokoid_2d.cpp
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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <utils/IPCThreadState.h>
#include <utils/ProcessState.h>
#include <utils/IServiceManager.h>
#include <utils/Log.h>
#include "MokoidSurface.h"
using namespace android;
#define RGBA8888(r, g, b, a) \
((((r) & 0xff) << 0) | \
(((g) & 0xff) << 8) | \
(((b) & 0xff) << 16) | \
(((a) & 0xff) << 24))
static void draw(char *buf, int w, int h, int stride)
{
int x, y;
for (y = 0; y < h; y++) {
char *row = buf + stride * y;
for (x = 0; x < w; x++) {
int r, g, b, a;
r = 0xff;
g = 0x00;
b = 0x00;
a = 0xff;
((uint32_t *) row)[x] = RGBA8888(r, g, b, a);
}
}
}
sp<MokoidSurface> surface;
static void demo(int x, int y, int w, int h)
{
char *buf;
int stride;
LOGI("MokoidSurface: we use sp<> template.");
surface = new MokoidSurface();
if (!surface->clientInit(x, y, w, h, &stride)) {
LOGI("failed to initialize a surface\n");
return;
}
surface->lockScreen();
buf = surface->getBuffer();
draw(buf, w, h, stride);
surface->unlockScreen();
}
int main(int argc, char **argv)
{
//sp<ProcessState> proc(ProcessState::self());
LOGI("MokoidSurface is started.");
ProcessState::self()->startThreadPool();
demo(10, 10, 160, 240);
sleep(5);
demo(20, 20, 160, 240);
sleep(5);
IPCThreadState::self()->joinThreadPool();
return 0;
}