forked from moko365/mokoid-stub
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathtest.cpp
83 lines (60 loc) · 1.48 KB
/
test.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
79
80
81
82
83
#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 <ui/SurfaceComposerClient.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 x, y;
int stride = w * 4; // 4 = depth / 8
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);
}
}
}
int createSurface(int w, int h)
{
Surface::SurfaceInfo info;
char *rawBuffer;
int depth = 32;
sp<SurfaceComposerClient> surfaceflinger_client;
sp<Surface> surface;
surfaceflinger_client = new SurfaceComposerClient();
// Create a new surface.
surface = surfaceflinger_client->createSurface(getpid(), 0, w, h, depth, 0);
// Control
surface->setPosition(0, 0);
surface->setLayer(INT_MAX);
// Get raw buffer of Surface.
surface->lock(&info);
rawBuffer = (char *)info.bits;
// Draw a red rect
draw(rawBuffer, 10, 10);
// Unlock
surface->unlockAndPost();
return 0;
}
int main(int argc, char **argv)
{
LOGI("MokoidSurface is started.");
//ProcessState::self()->startThreadPool();
createSurface(100, 100);
//IPCThreadState::self()->joinThreadPool();
return 0;
}