Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

device-motion-m1400: Commit

device/motion/m1400


Commit MetaInfo

Revisione20ee2f6e4ec97a047b7cf7bff3a57c9f7cea067 (tree)
Time2011-04-30 03:20:41
Authorfonix232 <fonix232@gmai...>
Commiterfonix232

Log Message

Added libgralloc
Removed problematic app(s)
Fixed license

Change Summary

Incremental Difference

Binary files a/app/TabletLauncher.apk and /dev/null differ
--- /dev/null
+++ b/fingerprint/gpl-2.0.txt
@@ -0,0 +1,339 @@
1+ GNU GENERAL PUBLIC LICENSE
2+ Version 2, June 1991
3+
4+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6+ Everyone is permitted to copy and distribute verbatim copies
7+ of this license document, but changing it is not allowed.
8+
9+ Preamble
10+
11+ The licenses for most software are designed to take away your
12+freedom to share and change it. By contrast, the GNU General Public
13+License is intended to guarantee your freedom to share and change free
14+software--to make sure the software is free for all its users. This
15+General Public License applies to most of the Free Software
16+Foundation's software and to any other program whose authors commit to
17+using it. (Some other Free Software Foundation software is covered by
18+the GNU Lesser General Public License instead.) You can apply it to
19+your programs, too.
20+
21+ When we speak of free software, we are referring to freedom, not
22+price. Our General Public Licenses are designed to make sure that you
23+have the freedom to distribute copies of free software (and charge for
24+this service if you wish), that you receive source code or can get it
25+if you want it, that you can change the software or use pieces of it
26+in new free programs; and that you know you can do these things.
27+
28+ To protect your rights, we need to make restrictions that forbid
29+anyone to deny you these rights or to ask you to surrender the rights.
30+These restrictions translate to certain responsibilities for you if you
31+distribute copies of the software, or if you modify it.
32+
33+ For example, if you distribute copies of such a program, whether
34+gratis or for a fee, you must give the recipients all the rights that
35+you have. You must make sure that they, too, receive or can get the
36+source code. And you must show them these terms so they know their
37+rights.
38+
39+ We protect your rights with two steps: (1) copyright the software, and
40+(2) offer you this license which gives you legal permission to copy,
41+distribute and/or modify the software.
42+
43+ Also, for each author's protection and ours, we want to make certain
44+that everyone understands that there is no warranty for this free
45+software. If the software is modified by someone else and passed on, we
46+want its recipients to know that what they have is not the original, so
47+that any problems introduced by others will not reflect on the original
48+authors' reputations.
49+
50+ Finally, any free program is threatened constantly by software
51+patents. We wish to avoid the danger that redistributors of a free
52+program will individually obtain patent licenses, in effect making the
53+program proprietary. To prevent this, we have made it clear that any
54+patent must be licensed for everyone's free use or not licensed at all.
55+
56+ The precise terms and conditions for copying, distribution and
57+modification follow.
58+
59+ GNU GENERAL PUBLIC LICENSE
60+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61+
62+ 0. This License applies to any program or other work which contains
63+a notice placed by the copyright holder saying it may be distributed
64+under the terms of this General Public License. The "Program", below,
65+refers to any such program or work, and a "work based on the Program"
66+means either the Program or any derivative work under copyright law:
67+that is to say, a work containing the Program or a portion of it,
68+either verbatim or with modifications and/or translated into another
69+language. (Hereinafter, translation is included without limitation in
70+the term "modification".) Each licensee is addressed as "you".
71+
72+Activities other than copying, distribution and modification are not
73+covered by this License; they are outside its scope. The act of
74+running the Program is not restricted, and the output from the Program
75+is covered only if its contents constitute a work based on the
76+Program (independent of having been made by running the Program).
77+Whether that is true depends on what the Program does.
78+
79+ 1. You may copy and distribute verbatim copies of the Program's
80+source code as you receive it, in any medium, provided that you
81+conspicuously and appropriately publish on each copy an appropriate
82+copyright notice and disclaimer of warranty; keep intact all the
83+notices that refer to this License and to the absence of any warranty;
84+and give any other recipients of the Program a copy of this License
85+along with the Program.
86+
87+You may charge a fee for the physical act of transferring a copy, and
88+you may at your option offer warranty protection in exchange for a fee.
89+
90+ 2. You may modify your copy or copies of the Program or any portion
91+of it, thus forming a work based on the Program, and copy and
92+distribute such modifications or work under the terms of Section 1
93+above, provided that you also meet all of these conditions:
94+
95+ a) You must cause the modified files to carry prominent notices
96+ stating that you changed the files and the date of any change.
97+
98+ b) You must cause any work that you distribute or publish, that in
99+ whole or in part contains or is derived from the Program or any
100+ part thereof, to be licensed as a whole at no charge to all third
101+ parties under the terms of this License.
102+
103+ c) If the modified program normally reads commands interactively
104+ when run, you must cause it, when started running for such
105+ interactive use in the most ordinary way, to print or display an
106+ announcement including an appropriate copyright notice and a
107+ notice that there is no warranty (or else, saying that you provide
108+ a warranty) and that users may redistribute the program under
109+ these conditions, and telling the user how to view a copy of this
110+ License. (Exception: if the Program itself is interactive but
111+ does not normally print such an announcement, your work based on
112+ the Program is not required to print an announcement.)
113+
114+These requirements apply to the modified work as a whole. If
115+identifiable sections of that work are not derived from the Program,
116+and can be reasonably considered independent and separate works in
117+themselves, then this License, and its terms, do not apply to those
118+sections when you distribute them as separate works. But when you
119+distribute the same sections as part of a whole which is a work based
120+on the Program, the distribution of the whole must be on the terms of
121+this License, whose permissions for other licensees extend to the
122+entire whole, and thus to each and every part regardless of who wrote it.
123+
124+Thus, it is not the intent of this section to claim rights or contest
125+your rights to work written entirely by you; rather, the intent is to
126+exercise the right to control the distribution of derivative or
127+collective works based on the Program.
128+
129+In addition, mere aggregation of another work not based on the Program
130+with the Program (or with a work based on the Program) on a volume of
131+a storage or distribution medium does not bring the other work under
132+the scope of this License.
133+
134+ 3. You may copy and distribute the Program (or a work based on it,
135+under Section 2) in object code or executable form under the terms of
136+Sections 1 and 2 above provided that you also do one of the following:
137+
138+ a) Accompany it with the complete corresponding machine-readable
139+ source code, which must be distributed under the terms of Sections
140+ 1 and 2 above on a medium customarily used for software interchange; or,
141+
142+ b) Accompany it with a written offer, valid for at least three
143+ years, to give any third party, for a charge no more than your
144+ cost of physically performing source distribution, a complete
145+ machine-readable copy of the corresponding source code, to be
146+ distributed under the terms of Sections 1 and 2 above on a medium
147+ customarily used for software interchange; or,
148+
149+ c) Accompany it with the information you received as to the offer
150+ to distribute corresponding source code. (This alternative is
151+ allowed only for noncommercial distribution and only if you
152+ received the program in object code or executable form with such
153+ an offer, in accord with Subsection b above.)
154+
155+The source code for a work means the preferred form of the work for
156+making modifications to it. For an executable work, complete source
157+code means all the source code for all modules it contains, plus any
158+associated interface definition files, plus the scripts used to
159+control compilation and installation of the executable. However, as a
160+special exception, the source code distributed need not include
161+anything that is normally distributed (in either source or binary
162+form) with the major components (compiler, kernel, and so on) of the
163+operating system on which the executable runs, unless that component
164+itself accompanies the executable.
165+
166+If distribution of executable or object code is made by offering
167+access to copy from a designated place, then offering equivalent
168+access to copy the source code from the same place counts as
169+distribution of the source code, even though third parties are not
170+compelled to copy the source along with the object code.
171+
172+ 4. You may not copy, modify, sublicense, or distribute the Program
173+except as expressly provided under this License. Any attempt
174+otherwise to copy, modify, sublicense or distribute the Program is
175+void, and will automatically terminate your rights under this License.
176+However, parties who have received copies, or rights, from you under
177+this License will not have their licenses terminated so long as such
178+parties remain in full compliance.
179+
180+ 5. You are not required to accept this License, since you have not
181+signed it. However, nothing else grants you permission to modify or
182+distribute the Program or its derivative works. These actions are
183+prohibited by law if you do not accept this License. Therefore, by
184+modifying or distributing the Program (or any work based on the
185+Program), you indicate your acceptance of this License to do so, and
186+all its terms and conditions for copying, distributing or modifying
187+the Program or works based on it.
188+
189+ 6. Each time you redistribute the Program (or any work based on the
190+Program), the recipient automatically receives a license from the
191+original licensor to copy, distribute or modify the Program subject to
192+these terms and conditions. You may not impose any further
193+restrictions on the recipients' exercise of the rights granted herein.
194+You are not responsible for enforcing compliance by third parties to
195+this License.
196+
197+ 7. If, as a consequence of a court judgment or allegation of patent
198+infringement or for any other reason (not limited to patent issues),
199+conditions are imposed on you (whether by court order, agreement or
200+otherwise) that contradict the conditions of this License, they do not
201+excuse you from the conditions of this License. If you cannot
202+distribute so as to satisfy simultaneously your obligations under this
203+License and any other pertinent obligations, then as a consequence you
204+may not distribute the Program at all. For example, if a patent
205+license would not permit royalty-free redistribution of the Program by
206+all those who receive copies directly or indirectly through you, then
207+the only way you could satisfy both it and this License would be to
208+refrain entirely from distribution of the Program.
209+
210+If any portion of this section is held invalid or unenforceable under
211+any particular circumstance, the balance of the section is intended to
212+apply and the section as a whole is intended to apply in other
213+circumstances.
214+
215+It is not the purpose of this section to induce you to infringe any
216+patents or other property right claims or to contest validity of any
217+such claims; this section has the sole purpose of protecting the
218+integrity of the free software distribution system, which is
219+implemented by public license practices. Many people have made
220+generous contributions to the wide range of software distributed
221+through that system in reliance on consistent application of that
222+system; it is up to the author/donor to decide if he or she is willing
223+to distribute software through any other system and a licensee cannot
224+impose that choice.
225+
226+This section is intended to make thoroughly clear what is believed to
227+be a consequence of the rest of this License.
228+
229+ 8. If the distribution and/or use of the Program is restricted in
230+certain countries either by patents or by copyrighted interfaces, the
231+original copyright holder who places the Program under this License
232+may add an explicit geographical distribution limitation excluding
233+those countries, so that distribution is permitted only in or among
234+countries not thus excluded. In such case, this License incorporates
235+the limitation as if written in the body of this License.
236+
237+ 9. The Free Software Foundation may publish revised and/or new versions
238+of the General Public License from time to time. Such new versions will
239+be similar in spirit to the present version, but may differ in detail to
240+address new problems or concerns.
241+
242+Each version is given a distinguishing version number. If the Program
243+specifies a version number of this License which applies to it and "any
244+later version", you have the option of following the terms and conditions
245+either of that version or of any later version published by the Free
246+Software Foundation. If the Program does not specify a version number of
247+this License, you may choose any version ever published by the Free Software
248+Foundation.
249+
250+ 10. If you wish to incorporate parts of the Program into other free
251+programs whose distribution conditions are different, write to the author
252+to ask for permission. For software which is copyrighted by the Free
253+Software Foundation, write to the Free Software Foundation; we sometimes
254+make exceptions for this. Our decision will be guided by the two goals
255+of preserving the free status of all derivatives of our free software and
256+of promoting the sharing and reuse of software generally.
257+
258+ NO WARRANTY
259+
260+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268+REPAIR OR CORRECTION.
269+
270+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278+POSSIBILITY OF SUCH DAMAGES.
279+
280+ END OF TERMS AND CONDITIONS
281+
282+ How to Apply These Terms to Your New Programs
283+
284+ If you develop a new program, and you want it to be of the greatest
285+possible use to the public, the best way to achieve this is to make it
286+free software which everyone can redistribute and change under these terms.
287+
288+ To do so, attach the following notices to the program. It is safest
289+to attach them to the start of each source file to most effectively
290+convey the exclusion of warranty; and each file should have at least
291+the "copyright" line and a pointer to where the full notice is found.
292+
293+ <one line to give the program's name and a brief idea of what it does.>
294+ Copyright (C) <year> <name of author>
295+
296+ This program is free software; you can redistribute it and/or modify
297+ it under the terms of the GNU General Public License as published by
298+ the Free Software Foundation; either version 2 of the License, or
299+ (at your option) any later version.
300+
301+ This program is distributed in the hope that it will be useful,
302+ but WITHOUT ANY WARRANTY; without even the implied warranty of
303+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304+ GNU General Public License for more details.
305+
306+ You should have received a copy of the GNU General Public License along
307+ with this program; if not, write to the Free Software Foundation, Inc.,
308+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309+
310+Also add information on how to contact you by electronic and paper mail.
311+
312+If the program is interactive, make it output a short notice like this
313+when it starts in an interactive mode:
314+
315+ Gnomovision version 69, Copyright (C) year name of author
316+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317+ This is free software, and you are welcome to redistribute it
318+ under certain conditions; type `show c' for details.
319+
320+The hypothetical commands `show w' and `show c' should show the appropriate
321+parts of the General Public License. Of course, the commands you use may
322+be called something other than `show w' and `show c'; they could even be
323+mouse-clicks or menu items--whatever suits your program.
324+
325+You should also get your employer (if you work as a programmer) or your
326+school, if any, to sign a "copyright disclaimer" for the program, if
327+necessary. Here is a sample; alter the names:
328+
329+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
331+
332+ <signature of Ty Coon>, 1 April 1989
333+ Ty Coon, President of Vice
334+
335+This General Public License does not permit incorporating your program into
336+proprietary programs. If your program is a subroutine library, you may
337+consider it more useful to permit linking proprietary applications with the
338+library. If this is what you want to do, use the GNU Lesser General
339+Public License instead of this License.
--- a/init.m1400.sh
+++ b/init.m1400.sh
@@ -6,4 +6,10 @@ init_audio()
66 init_graphics()
77 {
88
9-}
\ No newline at end of file
9+}
10+
11+init_keys()
12+{
13+ setkeycodes e074 218
14+ setkeycodes e079 219
15+}
--- a/init.motion_m1400.rc
+++ b/init.motion_m1400.rc
@@ -1,7 +1,5 @@
11 on boot
22 chown system system /sys/class/backlight/acpi_video0/brightness
3- setkeycodes e074 218
4- setkeycodes e079 219
53
64 service wacom-input /system/xbin/wacom-input
75
--- a/keylayout/m1400_keyboard.kl
+++ b/keylayout/m1400_keyboard.kl
@@ -1,9 +1,12 @@
1+# Generic keys
12 key 1 BACK WAKE
2-# key 219 HOME WAKE
33 key 72 DPAD_UP
44 key 75 DPAD_LEFT
5-key 28 DPAD_CENTER
5+key 28 DPAD_CENTER WAKE
66 key 77 DPAD_RIGHT
77 key 80 DPAD_DOWN
8-# key 218 WIFI WAKE
98 key 50 MENU WAKE
9+
10+# Test keys
11+key 219 HOME WAKE
12+key 218 WIFI WAKE
\ No newline at end of file
--- /dev/null
+++ b/libgralloc/Android.mk
@@ -0,0 +1,33 @@
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
--- /dev/null
+++ b/libgralloc/framebuffer.cpp
@@ -0,0 +1,345 @@
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+}
--- /dev/null
+++ b/libgralloc/gr.h
@@ -0,0 +1,64 @@
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_ */
--- /dev/null
+++ b/libgralloc/gralloc.cpp
@@ -0,0 +1,311 @@
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+}
--- /dev/null
+++ b/libgralloc/gralloc_priv.h
@@ -0,0 +1,112 @@
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_ */
--- /dev/null
+++ b/libgralloc/mapper.cpp
@@ -0,0 +1,169 @@
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