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
|
/*
* Copyright (c) 2007-2013 Intel Corporation. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <gui/Surface.h>
#include <gui/SurfaceComposerClient.h>
#include <gui/ISurfaceComposer.h>
#include <ui/PixelFormat.h>
#include <ui/DisplayInfo.h>
#include <system/window.h>
using namespace android;
#define BUFFER_USAGE (GraphicBuffer::USAGE_SW_READ_RARELY)|(GraphicBuffer::USAGE_SW_WRITE_RARELY)
#ifndef HAL_PIXEL_FORMAT_NV12
#define HAL_PIXEL_FORMAT_NV12 0x3231564E /*0x7FA00E00:VED*/
#endif
#ifndef HAL_PIXEL_FORMAT_NV12_Y_TILED_INTEL
#define HAL_PIXEL_FORMAT_NV12_Y_TILED_INTEL 0x100
#endif
#ifndef HAL_PIXEL_FORMAT_NV12_LINEAR_CAMERA_INTEL
#define HAL_PIXEL_FORMAT_NV12_LINEAR_CAMERA_INTEL 0x10F
#endif
static GraphicBuffer *GfxBuffer[32];
#ifdef _LINK_C
extern "C" int alloc_gralloc_buffer(int num_buffers, unsigned long *buffers,
int width, int height, int linear);
#endif
int alloc_gralloc_buffer(int num_buffers, unsigned long *buffers,
int width, int height, int linear)
{
int i, stride = 0;
int pixelFormat;
if (linear){
pixelFormat = HAL_PIXEL_FORMAT_NV12_LINEAR_CAMERA_INTEL; //Linear
printf("Using linear gralloc buffer\n");
} else {
pixelFormat = HAL_PIXEL_FORMAT_NV12_Y_TILED_INTEL; //Y-Tiled
printf("Using tiled gralloc buffer\n");
}
for (i=0; i < num_buffers; i++) {
ANativeWindowBuffer *WinBuffer;
GfxBuffer[i] = new GraphicBuffer(width, height,
pixelFormat, BUFFER_USAGE);
if (GfxBuffer[i] == NULL) {
printf("Allocate GraphicBuffer failed\n");
exit(1);
}
WinBuffer = GfxBuffer[i]->getNativeBuffer();
buffers[i] = (unsigned long)WinBuffer->handle;
stride = WinBuffer->stride;
}
/* gralloc buffer with it's own stride ? */
/*
if (width != 0 && stride != width_aligned) {
printf("Warning: desired stride is %d, gralloc buffer stride is %d, reset stride to %d\n",
width_aligned, stride, stride);
width_aligned = stride;
}
*/
return 0;
}
void *lockGraphicBuf(int idx) {
void *paddr = NULL;
GfxBuffer[idx]->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, &paddr);
return paddr;
}
void unlockGraphicBuf(int idx) {
GfxBuffer[idx]->unlock();
}
|