Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

device-motion-m1400: Commit

device/motion/m1400


Commit MetaInfo

Revision773e7c255646d5693ec977d0a53c24192c331ab2 (tree)
Time2011-05-01 01:08:24
Authorfonix232 <fonix232@gmai...>
Commiterfonix232

Log Message

Remove libgralloc

Change Summary

  • delete: libgralloc/Android.mk
  • delete: libgralloc/framebuffer.cpp
  • delete: libgralloc/gr.h
  • delete: libgralloc/gralloc.cpp
  • delete: libgralloc/gralloc_priv.h
  • delete: libgralloc/mapper.cpp

Incremental Difference

--- a/libgralloc/Android.mk
+++ /dev/null
@@ -1,33 +0,0 @@
1-# Copyright (C) 2010 The Android-x86 Open Source Project
2-#
3-# Licensed under the Apache License, Version 2.0 (the "License");
4-# you may not use this file except in compliance with the License.
5-# You may obtain a copy of the License at
6-#
7-# http://www.apache.org/licenses/LICENSE-2.0
8-#
9-# Unless required by applicable law or agreed to in writing, software
10-# distributed under the License is distributed on an "AS IS" BASIS,
11-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-# See the License for the specific language governing permissions and
13-# limitations under the License.
14-
15-ifeq ($(BOARD_USES_I915),true)
16-LOCAL_PATH := $(call my-dir)
17-
18-# HAL module implemenation, not prelinked and stored in
19-# hw/<OVERLAY_HARDWARE_MODULE_ID>.<ro.product.board>.so
20-include $(CLEAR_VARS)
21-LOCAL_PRELINK_MODULE := false
22-LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
23-LOCAL_SHARED_LIBRARIES := liblog libcutils
24-
25-LOCAL_SRC_FILES := \
26- gralloc.cpp \
27- framebuffer.cpp \
28- mapper.cpp
29-
30-LOCAL_MODULE := gralloc.$(TARGET_PRODUCT)
31-LOCAL_CFLAGS:= -DLOG_TAG=\"gralloc\"
32-include $(BUILD_SHARED_LIBRARY)
33-endif
--- a/libgralloc/framebuffer.cpp
+++ /dev/null
@@ -1,345 +0,0 @@
1-/*
2- * Copyright (C) 2008 The Android Open Source Project
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
16-
17-#include <sys/mman.h>
18-
19-#include <dlfcn.h>
20-
21-#include <cutils/ashmem.h>
22-#include <cutils/log.h>
23-
24-#include <hardware/hardware.h>
25-#include <hardware/gralloc.h>
26-
27-#include <fcntl.h>
28-#include <errno.h>
29-#include <sys/ioctl.h>
30-#include <string.h>
31-#include <stdlib.h>
32-
33-#include <cutils/log.h>
34-#include <cutils/atomic.h>
35-
36-#if HAVE_ANDROID_OS
37-#include <linux/fb.h>
38-#endif
39-
40-#include "gralloc_priv.h"
41-#include "gr.h"
42-
43-/*****************************************************************************/
44-
45-enum {
46- PAGE_FLIP = 0x00000001,
47- LOCKED = 0x00000002
48-};
49-
50-struct fb_context_t {
51- framebuffer_device_t device;
52-};
53-
54-/*****************************************************************************/
55-
56-static int fb_setSwapInterval(struct framebuffer_device_t* dev,
57- int interval)
58-{
59- fb_context_t* ctx = (fb_context_t*)dev;
60- if (interval < dev->minSwapInterval || interval > dev->maxSwapInterval)
61- return -EINVAL;
62- // FIXME: implement fb_setSwapInterval
63- return 0;
64-}
65-
66-static int fb_setUpdateRect(struct framebuffer_device_t* dev,
67- int l, int t, int w, int h)
68-{
69- if (((w|h) <= 0) || ((l|t)<0))
70- return -EINVAL;
71-
72- fb_context_t* ctx = (fb_context_t*)dev;
73- private_module_t* m = reinterpret_cast<private_module_t*>(
74- dev->common.module);
75- m->info.reserved[0] = 0x54445055; // "UPDT";
76- m->info.reserved[1] = (uint16_t)l | ((uint32_t)t << 16);
77- m->info.reserved[2] = (uint16_t)(l+w) | ((uint32_t)(t+h) << 16);
78- return 0;
79-}
80-
81-static int fb_post(struct framebuffer_device_t* dev, buffer_handle_t buffer)
82-{
83- if (private_handle_t::validate(buffer) < 0)
84- return -EINVAL;
85-
86- fb_context_t* ctx = (fb_context_t*)dev;
87-
88- private_handle_t const* hnd = reinterpret_cast<private_handle_t const*>(buffer);
89- private_module_t* m = reinterpret_cast<private_module_t*>(
90- dev->common.module);
91-
92- if (hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER) {
93- const size_t offset = hnd->base - m->framebuffer->base;
94- m->info.activate = FB_ACTIVATE_VBL;
95- m->info.yoffset = offset / m->finfo.line_length;
96- if (ioctl(m->framebuffer->fd, FBIOPUT_VSCREENINFO, &m->info) == -1) {
97- LOGE("FBIOPUT_VSCREENINFO failed");
98- m->base.unlock(&m->base, buffer);
99- return -errno;
100- }
101- m->currentBuffer = buffer;
102-
103- } else {
104- // If we can't do the page_flip, just copy the buffer to the front
105- // FIXME: use copybit HAL instead of memcpy
106-
107- void* fb_vaddr;
108- void* buffer_vaddr;
109-
110- m->base.lock(&m->base, m->framebuffer,
111- GRALLOC_USAGE_SW_WRITE_RARELY,
112- 0, 0, m->info.xres, m->info.yres,
113- &fb_vaddr);
114-
115- m->base.lock(&m->base, buffer,
116- GRALLOC_USAGE_SW_READ_RARELY,
117- 0, 0, m->info.xres, m->info.yres,
118- &buffer_vaddr);
119-
120- memcpy(fb_vaddr, buffer_vaddr, m->finfo.line_length * m->info.yres);
121-
122- m->base.unlock(&m->base, buffer);
123- m->base.unlock(&m->base, m->framebuffer);
124- }
125-
126- return 0;
127-}
128-
129-/*****************************************************************************/
130-
131-int mapFrameBufferLocked(struct private_module_t* module)
132-{
133- // already initialized...
134- if (module->framebuffer) {
135- return 0;
136- }
137-
138- char const * const device_template[] = {
139- "/dev/graphics/fb%u",
140- "/dev/fb%u",
141- 0 };
142-
143- int fd = -1;
144- int i=0;
145- char name[64];
146-
147- while ((fd==-1) && device_template[i]) {
148- snprintf(name, 64, device_template[i], 0);
149- fd = open(name, O_RDWR, 0);
150- i++;
151- }
152- if (fd < 0)
153- return -errno;
154-
155- struct fb_fix_screeninfo finfo;
156- if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo) == -1)
157- return -errno;
158-
159- struct fb_var_screeninfo info;
160- if (ioctl(fd, FBIOGET_VSCREENINFO, &info) == -1)
161- return -errno;
162-
163- info.reserved[0] = 0;
164- info.reserved[1] = 0;
165- info.reserved[2] = 0;
166- info.xoffset = 0;
167- info.yoffset = 0;
168- info.activate = FB_ACTIVATE_NOW;
169-
170- if (info.bits_per_pixel == 32) {
171- info.red.offset = 24;
172- info.red.length = 8;
173- info.green.offset = 16;
174- info.green.length = 8;
175- info.blue.offset = 8;
176- info.blue.length = 8;
177- info.transp.offset = 0;
178- info.transp.length = 0;
179- } else if (info.bits_per_pixel == 16) {
180- info.red.offset = 11;
181- info.red.length = 5;
182- info.green.offset = 5;
183- info.green.length = 6;
184- info.blue.offset = 0;
185- info.blue.length = 5;
186- info.transp.offset = 0;
187- info.transp.length = 0;
188- } else {
189- LOGE("Unsupported bpp: %d", info.bits_per_pixel);
190- return -1;
191- }
192-
193- info.yres_virtual = info.yres;
194- uint32_t flags = 0;
195-
196- if (ioctl(fd, FBIOPUT_VSCREENINFO, &info) == -1) {
197- LOGW("FBIOPUT_VSCREENINFO failed: %s", strerror(errno));
198- }
199-
200- if (ioctl(fd, FBIOGET_VSCREENINFO, &info) == -1)
201- return -errno;
202-
203- // The original AOSP calculates refreshRate by pixclock.
204- // However, the i915 driver has pixclock = 0 ?
205- int refreshRate = 60 * 1000; // 60 Hz
206-
207- if (int(info.width) <= 0 || int(info.height) <= 0) {
208- // the driver doesn't return that information
209- // default to 160 dpi
210- info.width = ((info.xres * 25.4f)/160.0f + 0.5f);
211- info.height = ((info.yres * 25.4f)/160.0f + 0.5f);
212- }
213-
214- float xdpi = (info.xres * 25.4f) / info.width;
215- float ydpi = (info.yres * 25.4f) / info.height;
216- float fps = refreshRate / 1000.0f;
217-
218- LOGI( "using (fd=%d)\n"
219- "id = %s\n"
220- "xres = %d px\n"
221- "yres = %d px\n"
222- "xres_virtual = %d px\n"
223- "yres_virtual = %d px\n"
224- "bpp = %d\n"
225- "r = %2u:%u\n"
226- "g = %2u:%u\n"
227- "b = %2u:%u\n",
228- fd,
229- finfo.id,
230- info.xres,
231- info.yres,
232- info.xres_virtual,
233- info.yres_virtual,
234- info.bits_per_pixel,
235- info.red.offset, info.red.length,
236- info.green.offset, info.green.length,
237- info.blue.offset, info.blue.length
238- );
239-
240- LOGI( "width = %d mm (%f dpi)\n"
241- "height = %d mm (%f dpi)\n"
242- "refresh rate = %.2f Hz\n",
243- info.width, xdpi,
244- info.height, ydpi,
245- fps
246- );
247-
248-
249- if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo) == -1)
250- return -errno;
251-
252- if (finfo.smem_len <= 0)
253- return -errno;
254-
255-
256- module->flags = flags;
257- module->info = info;
258- module->finfo = finfo;
259- module->xdpi = xdpi;
260- module->ydpi = ydpi;
261- module->fps = fps;
262-
263- /*
264- * map the framebuffer
265- */
266-
267- int err;
268- size_t fbSize = roundUpToPageSize(finfo.line_length * info.yres_virtual);
269- module->framebuffer = new private_handle_t(dup(fd), fbSize, 0);
270-
271- module->numBuffers = info.yres_virtual / info.yres;
272- module->bufferMask = 0;
273-
274- void* vaddr = mmap(0, fbSize, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
275- if (vaddr == MAP_FAILED) {
276- LOGE("Error mapping the framebuffer (%s)", strerror(errno));
277- return -errno;
278- }
279- module->framebuffer->base = intptr_t(vaddr);
280- memset(vaddr, 0, fbSize);
281- return 0;
282-}
283-
284-static int mapFrameBuffer(struct private_module_t* module)
285-{
286- pthread_mutex_lock(&module->lock);
287- int err = mapFrameBufferLocked(module);
288- pthread_mutex_unlock(&module->lock);
289- return err;
290-}
291-
292-/*****************************************************************************/
293-
294-static int fb_close(struct hw_device_t *dev)
295-{
296- fb_context_t* ctx = (fb_context_t*)dev;
297- if (ctx) {
298- free(ctx);
299- }
300- return 0;
301-}
302-
303-int fb_device_open(hw_module_t const* module, const char* name,
304- hw_device_t** device)
305-{
306- int status = -EINVAL;
307- if (!strcmp(name, GRALLOC_HARDWARE_FB0)) {
308- alloc_device_t* gralloc_device;
309- status = gralloc_open(module, &gralloc_device);
310- if (status < 0)
311- return status;
312-
313- /* initialize our state here */
314- fb_context_t *dev = (fb_context_t*)malloc(sizeof(*dev));
315- memset(dev, 0, sizeof(*dev));
316-
317- /* initialize the procs */
318- dev->device.common.tag = HARDWARE_DEVICE_TAG;
319- dev->device.common.version = 0;
320- dev->device.common.module = const_cast<hw_module_t*>(module);
321- dev->device.common.close = fb_close;
322- dev->device.setSwapInterval = fb_setSwapInterval;
323- dev->device.post = fb_post;
324- dev->device.setUpdateRect = 0;
325-
326- private_module_t* m = (private_module_t*)module;
327- status = mapFrameBuffer(m);
328- if (status >= 0) {
329- int stride = m->finfo.line_length / (m->info.bits_per_pixel >> 3);
330- const_cast<uint32_t&>(dev->device.flags) = 0;
331- const_cast<uint32_t&>(dev->device.width) = m->info.xres;
332- const_cast<uint32_t&>(dev->device.height) = m->info.yres;
333- const_cast<int&>(dev->device.stride) = stride;
334- const_cast<int&>(dev->device.format) = (m->info.bits_per_pixel == 32) ?
335- HAL_PIXEL_FORMAT_BGRA_8888 : HAL_PIXEL_FORMAT_RGB_565;
336- const_cast<float&>(dev->device.xdpi) = m->xdpi;
337- const_cast<float&>(dev->device.ydpi) = m->ydpi;
338- const_cast<float&>(dev->device.fps) = m->fps;
339- const_cast<int&>(dev->device.minSwapInterval) = 1;
340- const_cast<int&>(dev->device.maxSwapInterval) = 1;
341- *device = &dev->device.common;
342- }
343- }
344- return status;
345-}
--- a/libgralloc/gr.h
+++ /dev/null
@@ -1,64 +0,0 @@
1-/*
2- * Copyright (C) 2008 The Android Open Source Project
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
16-
17-#ifndef GR_H_
18-#define GR_H_
19-
20-#include <stdint.h>
21-#ifdef HAVE_ANDROID_OS // just want PAGE_SIZE define
22-# include <asm/page.h>
23-#else
24-# include <sys/user.h>
25-#endif
26-#include <limits.h>
27-#include <sys/cdefs.h>
28-#include <hardware/gralloc.h>
29-#include <pthread.h>
30-#include <errno.h>
31-
32-#include <cutils/native_handle.h>
33-
34-/*****************************************************************************/
35-
36-struct private_module_t;
37-struct private_handle_t;
38-
39-inline size_t roundUpToPageSize(size_t x) {
40- return (x + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1);
41-}
42-
43-int mapFrameBufferLocked(struct private_module_t* module);
44-int terminateBuffer(gralloc_module_t const* module, private_handle_t* hnd);
45-int mapBuffer(gralloc_module_t const* module, private_handle_t* hnd);
46-
47-/*****************************************************************************/
48-
49-class Locker {
50- pthread_mutex_t mutex;
51-public:
52- class Autolock {
53- Locker& locker;
54- public:
55- inline Autolock(Locker& locker) : locker(locker) { locker.lock(); }
56- inline ~Autolock() { locker.unlock(); }
57- };
58- inline Locker() { pthread_mutex_init(&mutex, 0); }
59- inline ~Locker() { pthread_mutex_destroy(&mutex); }
60- inline void lock() { pthread_mutex_lock(&mutex); }
61- inline void unlock() { pthread_mutex_unlock(&mutex); }
62-};
63-
64-#endif /* GR_H_ */
--- a/libgralloc/gralloc.cpp
+++ /dev/null
@@ -1,311 +0,0 @@
1-/*
2- * Copyright (C) 2008 The Android Open Source Project
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
16-
17-#include <limits.h>
18-#include <unistd.h>
19-#include <fcntl.h>
20-#include <errno.h>
21-#include <pthread.h>
22-#include <stdlib.h>
23-#include <string.h>
24-
25-#include <sys/mman.h>
26-#include <sys/stat.h>
27-#include <sys/types.h>
28-#include <sys/ioctl.h>
29-
30-#include <cutils/ashmem.h>
31-#include <cutils/log.h>
32-#include <cutils/atomic.h>
33-
34-#include <hardware/hardware.h>
35-#include <hardware/gralloc.h>
36-
37-#include "gralloc_priv.h"
38-#include "gr.h"
39-
40-/*****************************************************************************/
41-
42-struct gralloc_context_t {
43- alloc_device_t device;
44- /* our private data here */
45-};
46-
47-static int gralloc_alloc_buffer(alloc_device_t* dev,
48- size_t size, int usage, buffer_handle_t* pHandle);
49-
50-/*****************************************************************************/
51-
52-int fb_device_open(const hw_module_t* module, const char* name,
53- hw_device_t** device);
54-
55-static int gralloc_device_open(const hw_module_t* module, const char* name,
56- hw_device_t** device);
57-
58-extern int gralloc_lock(gralloc_module_t const* module,
59- buffer_handle_t handle, int usage,
60- int l, int t, int w, int h,
61- void** vaddr);
62-
63-extern int gralloc_unlock(gralloc_module_t const* module,
64- buffer_handle_t handle);
65-
66-extern int gralloc_register_buffer(gralloc_module_t const* module,
67- buffer_handle_t handle);
68-
69-extern int gralloc_unregister_buffer(gralloc_module_t const* module,
70- buffer_handle_t handle);
71-
72-/*****************************************************************************/
73-
74-static struct hw_module_methods_t gralloc_module_methods = {
75- open: gralloc_device_open
76-};
77-
78-struct private_module_t HAL_MODULE_INFO_SYM = {
79- base: {
80- common: {
81- tag: HARDWARE_MODULE_TAG,
82- version_major: 1,
83- version_minor: 0,
84- id: GRALLOC_HARDWARE_MODULE_ID,
85- name: "Graphics Memory Allocator Module",
86- author: "The Android Open Source Project",
87- methods: &gralloc_module_methods
88- },
89- registerBuffer: gralloc_register_buffer,
90- unregisterBuffer: gralloc_unregister_buffer,
91- lock: gralloc_lock,
92- unlock: gralloc_unlock,
93- },
94- framebuffer: 0,
95- flags: 0,
96- numBuffers: 0,
97- bufferMask: 0,
98- lock: PTHREAD_MUTEX_INITIALIZER,
99- currentBuffer: 0,
100-};
101-
102-/*****************************************************************************/
103-
104-static int gralloc_alloc_framebuffer_locked(alloc_device_t* dev,
105- size_t size, int usage, buffer_handle_t* pHandle)
106-{
107- private_module_t* m = reinterpret_cast<private_module_t*>(
108- dev->common.module);
109-
110- // allocate the framebuffer
111- if (m->framebuffer == NULL) {
112- // initialize the framebuffer, the framebuffer is mapped once
113- // and forever.
114- int err = mapFrameBufferLocked(m);
115- if (err < 0) {
116- return err;
117- }
118- }
119-
120- const uint32_t bufferMask = m->bufferMask;
121- const uint32_t numBuffers = m->numBuffers;
122- const size_t bufferSize = m->finfo.line_length * m->info.yres;
123- if (numBuffers == 1) {
124- // If we have only one buffer, we never use page-flipping. Instead,
125- // we return a regular buffer which will be memcpy'ed to the main
126- // screen when post is called.
127- int newUsage = (usage & ~GRALLOC_USAGE_HW_FB) | GRALLOC_USAGE_HW_2D;
128- return gralloc_alloc_buffer(dev, bufferSize, newUsage, pHandle);
129- }
130-
131- if (bufferMask >= ((1LU<<numBuffers)-1)) {
132- // We ran out of buffers.
133- return -ENOMEM;
134- }
135-
136- // create a "fake" handles for it
137- intptr_t vaddr = intptr_t(m->framebuffer->base);
138- private_handle_t* hnd = new private_handle_t(dup(m->framebuffer->fd), size,
139- private_handle_t::PRIV_FLAGS_FRAMEBUFFER);
140-
141- // find a free slot
142- for (uint32_t i=0 ; i<numBuffers ; i++) {
143- if ((bufferMask & (1LU<<i)) == 0) {
144- m->bufferMask |= (1LU<<i);
145- break;
146- }
147- vaddr += bufferSize;
148- }
149-
150- hnd->base = vaddr;
151- hnd->offset = vaddr - intptr_t(m->framebuffer->base);
152- *pHandle = hnd;
153-
154- return 0;
155-}
156-
157-static int gralloc_alloc_framebuffer(alloc_device_t* dev,
158- size_t size, int usage, buffer_handle_t* pHandle)
159-{
160- private_module_t* m = reinterpret_cast<private_module_t*>(
161- dev->common.module);
162- pthread_mutex_lock(&m->lock);
163- int err = gralloc_alloc_framebuffer_locked(dev, size, usage, pHandle);
164- pthread_mutex_unlock(&m->lock);
165- return err;
166-}
167-
168-static int gralloc_alloc_buffer(alloc_device_t* dev,
169- size_t size, int usage, buffer_handle_t* pHandle)
170-{
171- int err = 0;
172- int fd = -1;
173-
174- size = roundUpToPageSize(size);
175-
176- fd = ashmem_create_region("gralloc-buffer", size);
177- if (fd < 0) {
178- LOGE("couldn't create ashmem (%s)", strerror(-errno));
179- err = -errno;
180- }
181-
182- if (err == 0) {
183- private_handle_t* hnd = new private_handle_t(fd, size, 0);
184- gralloc_module_t* module = reinterpret_cast<gralloc_module_t*>(
185- dev->common.module);
186- err = mapBuffer(module, hnd);
187- if (err == 0) {
188- *pHandle = hnd;
189- }
190- }
191-
192- LOGE_IF(err, "gralloc failed err=%s", strerror(-err));
193-
194- return err;
195-}
196-
197-/*****************************************************************************/
198-
199-static int gralloc_alloc(alloc_device_t* dev,
200- int w, int h, int format, int usage,
201- buffer_handle_t* pHandle, int* pStride)
202-{
203- if (!pHandle || !pStride)
204- return -EINVAL;
205-
206- size_t size, stride;
207-
208- int align = 4;
209- int bpp = 0;
210- switch (format) {
211- case HAL_PIXEL_FORMAT_RGBA_8888:
212- case HAL_PIXEL_FORMAT_RGBX_8888:
213- case HAL_PIXEL_FORMAT_BGRA_8888:
214- bpp = 4;
215- break;
216- case HAL_PIXEL_FORMAT_RGB_888:
217- bpp = 3;
218- break;
219- case HAL_PIXEL_FORMAT_RGB_565:
220- case HAL_PIXEL_FORMAT_RGBA_5551:
221- case HAL_PIXEL_FORMAT_RGBA_4444:
222- bpp = 2;
223- break;
224- default:
225- return -EINVAL;
226- }
227- size_t bpr = (w*bpp + (align-1)) & ~(align-1);
228- size = bpr * h;
229- stride = bpr / bpp;
230-
231- int err;
232- if (usage & GRALLOC_USAGE_HW_FB) {
233- err = gralloc_alloc_framebuffer(dev, size, usage, pHandle);
234- } else {
235- err = gralloc_alloc_buffer(dev, size, usage, pHandle);
236- }
237-
238- if (err < 0) {
239- return err;
240- }
241-
242- *pStride = stride;
243- return 0;
244-}
245-
246-static int gralloc_free(alloc_device_t* dev,
247- buffer_handle_t handle)
248-{
249- if (private_handle_t::validate(handle) < 0)
250- return -EINVAL;
251-
252- private_handle_t const* hnd = reinterpret_cast<private_handle_t const*>(handle);
253- if (hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER) {
254- // free this buffer
255- private_module_t* m = reinterpret_cast<private_module_t*>(
256- dev->common.module);
257- const size_t bufferSize = m->finfo.line_length * m->info.yres;
258- int index = (hnd->base - m->framebuffer->base) / bufferSize;
259- m->bufferMask &= ~(1<<index);
260- } else {
261- gralloc_module_t* module = reinterpret_cast<gralloc_module_t*>(
262- dev->common.module);
263- terminateBuffer(module, const_cast<private_handle_t*>(hnd));
264- }
265-
266- close(hnd->fd);
267- delete hnd;
268- return 0;
269-}
270-
271-/*****************************************************************************/
272-
273-static int gralloc_close(struct hw_device_t *dev)
274-{
275- gralloc_context_t* ctx = reinterpret_cast<gralloc_context_t*>(dev);
276- if (ctx) {
277- /* TODO: keep a list of all buffer_handle_t created, and free them
278- * all here.
279- */
280- free(ctx);
281- }
282- return 0;
283-}
284-
285-int gralloc_device_open(const hw_module_t* module, const char* name,
286- hw_device_t** device)
287-{
288- int status = -EINVAL;
289- if (!strcmp(name, GRALLOC_HARDWARE_GPU0)) {
290- gralloc_context_t *dev;
291- dev = (gralloc_context_t*)malloc(sizeof(*dev));
292-
293- /* initialize our state here */
294- memset(dev, 0, sizeof(*dev));
295-
296- /* initialize the procs */
297- dev->device.common.tag = HARDWARE_DEVICE_TAG;
298- dev->device.common.version = 0;
299- dev->device.common.module = const_cast<hw_module_t*>(module);
300- dev->device.common.close = gralloc_close;
301-
302- dev->device.alloc = gralloc_alloc;
303- dev->device.free = gralloc_free;
304-
305- *device = &dev->device.common;
306- status = 0;
307- } else {
308- status = fb_device_open(module, name, device);
309- }
310- return status;
311-}
--- a/libgralloc/gralloc_priv.h
+++ /dev/null
@@ -1,112 +0,0 @@
1-/*
2- * Copyright (C) 2008 The Android Open Source Project
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
16-
17-#ifndef GRALLOC_PRIV_H_
18-#define GRALLOC_PRIV_H_
19-
20-#include <stdint.h>
21-#include <limits.h>
22-#include <sys/cdefs.h>
23-#include <hardware/gralloc.h>
24-#include <pthread.h>
25-#include <errno.h>
26-#include <unistd.h>
27-
28-#include <cutils/native_handle.h>
29-
30-#include <linux/fb.h>
31-
32-/*****************************************************************************/
33-
34-struct private_module_t;
35-struct private_handle_t;
36-
37-struct private_module_t {
38- gralloc_module_t base;
39-
40- private_handle_t* framebuffer;
41- uint32_t flags;
42- uint32_t numBuffers;
43- uint32_t bufferMask;
44- pthread_mutex_t lock;
45- buffer_handle_t currentBuffer;
46- int pmem_master;
47- void* pmem_master_base;
48-
49- struct fb_var_screeninfo info;
50- struct fb_fix_screeninfo finfo;
51- float xdpi;
52- float ydpi;
53- float fps;
54-};
55-
56-/*****************************************************************************/
57-
58-#ifdef __cplusplus
59-struct private_handle_t : public native_handle {
60-#else
61-struct private_handle_t {
62- struct native_handle nativeHandle;
63-#endif
64-
65- enum {
66- PRIV_FLAGS_FRAMEBUFFER = 0x00000001
67- };
68-
69- // file-descriptors
70- int fd;
71- // ints
72- int magic;
73- int flags;
74- int size;
75- int offset;
76-
77- // FIXME: the attributes below should be out-of-line
78- int base;
79- int pid;
80-
81-#ifdef __cplusplus
82- static const int sNumInts = 6;
83- static const int sNumFds = 1;
84- static const int sMagic = 0x3141592;
85-
86- private_handle_t(int fd, int size, int flags) :
87- fd(fd), magic(sMagic), flags(flags), size(size), offset(0),
88- base(0), pid(getpid())
89- {
90- version = sizeof(native_handle);
91- numInts = sNumInts;
92- numFds = sNumFds;
93- }
94- ~private_handle_t() {
95- magic = 0;
96- }
97-
98- static int validate(const native_handle* h) {
99- const private_handle_t* hnd = (const private_handle_t*)h;
100- if (!h || h->version != sizeof(native_handle) ||
101- h->numInts != sNumInts || h->numFds != sNumFds ||
102- hnd->magic != sMagic)
103- {
104- LOGE("invalid gralloc handle (at %p)", h);
105- return -EINVAL;
106- }
107- return 0;
108- }
109-#endif
110-};
111-
112-#endif /* GRALLOC_PRIV_H_ */
--- a/libgralloc/mapper.cpp
+++ /dev/null
@@ -1,169 +0,0 @@
1-/*
2- * Copyright (C) 2008 The Android Open Source Project
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
16-
17-#include <limits.h>
18-#include <errno.h>
19-#include <pthread.h>
20-#include <unistd.h>
21-#include <string.h>
22-
23-#include <sys/mman.h>
24-#include <sys/stat.h>
25-#include <sys/types.h>
26-
27-#include <cutils/log.h>
28-#include <cutils/atomic.h>
29-
30-#include <hardware/hardware.h>
31-#include <hardware/gralloc.h>
32-
33-#include "gralloc_priv.h"
34-
35-
36-/* desktop Linux needs a little help with gettid() */
37-#if defined(ARCH_X86) && !defined(HAVE_ANDROID_OS)
38-#define __KERNEL__
39-# include <linux/unistd.h>
40-pid_t gettid() { return syscall(__NR_gettid);}
41-#undef __KERNEL__
42-#endif
43-
44-/*****************************************************************************/
45-
46-static int gralloc_map(gralloc_module_t const* module,
47- buffer_handle_t handle,
48- void** vaddr)
49-{
50- private_handle_t* hnd = (private_handle_t*)handle;
51- if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)) {
52- size_t size = hnd->size;
53- void* mappedAddress = mmap(0, size,
54- PROT_READ|PROT_WRITE, MAP_SHARED, hnd->fd, 0);
55- if (mappedAddress == MAP_FAILED) {
56- LOGE("Could not mmap %s", strerror(errno));
57- return -errno;
58- }
59- hnd->base = intptr_t(mappedAddress) + hnd->offset;
60- //LOGD("gralloc_map() succeeded fd=%d, off=%d, size=%d, vaddr=%p",
61- // hnd->fd, hnd->offset, hnd->size, mappedAddress);
62- }
63- *vaddr = (void*)hnd->base;
64- return 0;
65-}
66-
67-static int gralloc_unmap(gralloc_module_t const* module,
68- buffer_handle_t handle)
69-{
70- private_handle_t* hnd = (private_handle_t*)handle;
71- if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)) {
72- void* base = (void*)hnd->base;
73- size_t size = hnd->size;
74- //LOGD("unmapping from %p, size=%d", base, size);
75- if (munmap(base, size) < 0) {
76- LOGE("Could not unmap %s", strerror(errno));
77- }
78- }
79- hnd->base = 0;
80- return 0;
81-}
82-
83-/*****************************************************************************/
84-
85-static pthread_mutex_t sMapLock = PTHREAD_MUTEX_INITIALIZER;
86-
87-/*****************************************************************************/
88-
89-int gralloc_register_buffer(gralloc_module_t const* module,
90- buffer_handle_t handle)
91-{
92- if (private_handle_t::validate(handle) < 0)
93- return -EINVAL;
94-
95- // if this handle was created in this process, then we keep it as is.
96- int err = 0;
97- private_handle_t* hnd = (private_handle_t*)handle;
98- if (hnd->pid != getpid()) {
99- void *vaddr;
100- err = gralloc_map(module, handle, &vaddr);
101- }
102- return err;
103-}
104-
105-int gralloc_unregister_buffer(gralloc_module_t const* module,
106- buffer_handle_t handle)
107-{
108- if (private_handle_t::validate(handle) < 0)
109- return -EINVAL;
110-
111- // never unmap buffers that were created in this process
112- private_handle_t* hnd = (private_handle_t*)handle;
113- if (hnd->pid != getpid()) {
114- if (hnd->base) {
115- gralloc_unmap(module, handle);
116- }
117- }
118- return 0;
119-}
120-
121-int mapBuffer(gralloc_module_t const* module,
122- private_handle_t* hnd)
123-{
124- void* vaddr;
125- return gralloc_map(module, hnd, &vaddr);
126-}
127-
128-int terminateBuffer(gralloc_module_t const* module,
129- private_handle_t* hnd)
130-{
131- if (hnd->base) {
132- // this buffer was mapped, unmap it now
133- gralloc_unmap(module, hnd);
134- }
135-
136- return 0;
137-}
138-
139-int gralloc_lock(gralloc_module_t const* module,
140- buffer_handle_t handle, int usage,
141- int l, int t, int w, int h,
142- void** vaddr)
143-{
144- // this is called when a buffer is being locked for software
145- // access. in thin implementation we have nothing to do since
146- // not synchronization with the h/w is needed.
147- // typically this is used to wait for the h/w to finish with
148- // this buffer if relevant. the data cache may need to be
149- // flushed or invalidated depending on the usage bits and the
150- // hardware.
151-
152- if (private_handle_t::validate(handle) < 0)
153- return -EINVAL;
154-
155- private_handle_t* hnd = (private_handle_t*)handle;
156- *vaddr = (void*)hnd->base;
157- return 0;
158-}
159-
160-int gralloc_unlock(gralloc_module_t const* module,
161- buffer_handle_t handle)
162-{
163- // we're done with a software buffer. nothing to do in this
164- // implementation. typically this is used to flush the data cache.
165-
166- if (private_handle_t::validate(handle) < 0)
167- return -EINVAL;
168- return 0;
169-}
Show on old repository browser