display: Cleanup unused code
CRs-Fixed: 2048735
Change-Id: Ief7f8ae4006ab211272191b66bd4bd854d9098b2
diff --git a/libgralloc/MODULE_LICENSE_APACHE2 b/libgralloc/MODULE_LICENSE_APACHE2
deleted file mode 100644
index e69de29..0000000
--- a/libgralloc/MODULE_LICENSE_APACHE2
+++ /dev/null
diff --git a/libgralloc/NOTICE b/libgralloc/NOTICE
deleted file mode 100644
index 3237da6..0000000
--- a/libgralloc/NOTICE
+++ /dev/null
@@ -1,190 +0,0 @@
-
- Copyright (c) 2008-2009, The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
-
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
diff --git a/libgralloc/alloc_controller.h b/libgralloc/alloc_controller.h
deleted file mode 100644
index 45977e2..0000000
--- a/libgralloc/alloc_controller.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
-
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- * * Neither the name of The Linux Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
- * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#ifndef GRALLOC_ALLOCCONTROLLER_H
-#define GRALLOC_ALLOCCONTROLLER_H
-
-#define SZ_2M 0x200000
-#define SZ_1M 0x100000
-#define SZ_4K 0x1000
-
-/* TODO: Move this to the common makefile */
-#ifdef MASTER_SIDE_CP
-#define SECURE_ALIGN SZ_4K
-#else
-#define SECURE_ALIGN SZ_1M
-#endif
-
-namespace gralloc {
-
-struct alloc_data;
-class IMemAlloc;
-class IonAlloc;
-
-class IAllocController {
-
- public:
- /* Allocate using a suitable method
- * Returns the type of buffer allocated
- */
- virtual int allocate(alloc_data& data, int usage) = 0;
-
- virtual IMemAlloc* getAllocator(int flags) = 0;
-
- virtual bool isDisableUBWCForEncoder() = 0;
-
- virtual ~IAllocController() {};
-
- static IAllocController* getInstance(void);
-
- private:
- static IAllocController* sController;
-
-};
-
-class IonController : public IAllocController {
-
- public:
- virtual int allocate(alloc_data& data, int usage);
-
- virtual IMemAlloc* getAllocator(int flags);
-
- virtual bool isDisableUBWCForEncoder() {
- return mDisableUBWCForEncode;
- }
-
- IonController();
-
- private:
- IonAlloc* mIonAlloc;
- bool mDisableUBWCForEncode;
- void allocateIonMem();
-
-};
-} //end namespace gralloc
-#endif // GRALLOC_ALLOCCONTROLLER_H
diff --git a/libgralloc/fb_priv.h b/libgralloc/fb_priv.h
deleted file mode 100644
index e2eba6a..0000000
--- a/libgralloc/fb_priv.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef FB_PRIV_H
-#define FB_PRIV_H
-#include <linux/fb.h>
-#include <linux/msm_mdp.h>
-
-#define NUM_FRAMEBUFFERS_MIN 2
-#define NUM_FRAMEBUFFERS_MAX 3
-
-#define NO_SURFACEFLINGER_SWAPINTERVAL
-#define COLOR_FORMAT(x) (x & 0xFFF) // Max range for colorFormats is 0 - FFF
-
-struct private_handle_t;
-
-enum {
- // flag to indicate we'll post this buffer
- PRIV_USAGE_LOCKED_FOR_POST = 0x80000000,
- PRIV_MIN_SWAP_INTERVAL = 0,
- PRIV_MAX_SWAP_INTERVAL = 1,
-};
-
-struct private_module_t {
- gralloc_module_t base;
- struct private_handle_t* framebuffer;
- uint32_t fbFormat;
- uint32_t flags;
- uint32_t numBuffers;
- uint32_t bufferMask;
- pthread_mutex_t lock;
- struct fb_var_screeninfo info;
- struct fb_fix_screeninfo finfo;
- float xdpi;
- float ydpi;
- float fps;
- uint32_t swapInterval;
-};
-
-
-
-#endif /* FB_PRIV_H */
diff --git a/libgralloc/framebuffer.cpp b/libgralloc/framebuffer.cpp
deleted file mode 100644
index dd4842f..0000000
--- a/libgralloc/framebuffer.cpp
+++ /dev/null
@@ -1,457 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * Copyright (c) 2010-2014 The Linux Foundation. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <sys/mman.h>
-
-#include <cutils/log.h>
-#include <cutils/properties.h>
-#include <dlfcn.h>
-
-#include <hardware/hardware.h>
-
-#include <fcntl.h>
-#include <errno.h>
-#include <sys/ioctl.h>
-#include <string.h>
-#include <stdlib.h>
-#include <pthread.h>
-#include <cutils/atomic.h>
-
-#include <linux/fb.h>
-#include <linux/msm_mdp.h>
-
-#ifndef TARGET_HEADLESS
-#include <GLES/gl.h>
-#endif
-
-#include "gralloc_priv.h"
-#include "fb_priv.h"
-#include "gr.h"
-#include <cutils/properties.h>
-#include <profiler.h>
-
-#define EVEN_OUT(x) if (x & 0x0001) {x--;}
-
-enum {
- PAGE_FLIP = 0x00000001,
-};
-
-struct fb_context_t {
- framebuffer_device_t device;
- //fd - which is returned on open
- int fbFd;
-};
-
-static int fb_setSwapInterval(struct framebuffer_device_t* dev,
- int interval)
-{
- //XXX: Get the value here and implement along with
- //single vsync in HWC
- char pval[PROPERTY_VALUE_MAX];
- property_get("debug.egl.swapinterval", pval, "-1");
- int property_interval = atoi(pval);
- if (property_interval >= 0)
- interval = property_interval;
-
- private_module_t* m = reinterpret_cast<private_module_t*>(
- dev->common.module);
- if (interval < dev->minSwapInterval || interval > dev->maxSwapInterval)
- return -EINVAL;
-
- m->swapInterval = interval;
- return 0;
-}
-
-static int fb_post(struct framebuffer_device_t* dev, buffer_handle_t buffer)
-{
- private_module_t* m =
- reinterpret_cast<private_module_t*>(dev->common.module);
- private_handle_t *hnd = static_cast<private_handle_t*>
- (const_cast<native_handle_t*>(buffer));
- fb_context_t *ctx = reinterpret_cast<fb_context_t*>(dev);
- const unsigned int offset = (unsigned int) (hnd->base -
- m->framebuffer->base);
- m->info.activate = FB_ACTIVATE_VBL;
- m->info.yoffset = (int)(offset / m->finfo.line_length);
- if (ioctl(ctx->fbFd, FBIOPUT_VSCREENINFO, &m->info) == -1) {
- ALOGE("%s: FBIOPUT_VSCREENINFO for primary failed, str: %s",
- __FUNCTION__, strerror(errno));
- return -errno;
- }
- return 0;
-}
-
-static int fb_compositionComplete(struct framebuffer_device_t* dev)
-{
- // TODO: Properly implement composition complete callback
- if(!dev) {
- return -1;
- }
-#ifndef TARGET_HEADLESS
- glFinish();
-#endif
-
- return 0;
-}
-
-int mapFrameBufferLocked(framebuffer_device_t *dev)
-{
- private_module_t* module =
- reinterpret_cast<private_module_t*>(dev->common.module);
- fb_context_t *ctx = reinterpret_cast<fb_context_t*>(dev);
- // already initialized...
- if (module->framebuffer) {
- return 0;
- }
- char const * const device_template[] = {
- "/dev/graphics/fb%u",
- "/dev/fb%u",
- 0 };
-
- int fd = -1;
- int i=0;
- char name[64];
- char property[PROPERTY_VALUE_MAX];
-
- while ((fd==-1) && device_template[i]) {
- snprintf(name, 64, device_template[i], 0);
- fd = open(name, O_RDWR, 0);
- i++;
- }
- if (fd < 0)
- return -errno;
-
- struct fb_fix_screeninfo finfo;
- if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo) == -1) {
- close(fd);
- return -errno;
- }
-
- struct fb_var_screeninfo info;
- if (ioctl(fd, FBIOGET_VSCREENINFO, &info) == -1) {
- close(fd);
- return -errno;
- }
-
- info.reserved[0] = 0;
- info.reserved[1] = 0;
- info.reserved[2] = 0;
- info.xoffset = 0;
- info.yoffset = 0;
- info.activate = FB_ACTIVATE_NOW;
-
- /* Interpretation of offset for color fields: All offsets are from the
- * right, inside a "pixel" value, which is exactly 'bits_per_pixel' wide
- * (means: you can use the offset as right argument to <<). A pixel
- * afterwards is a bit stream and is written to video memory as that
- * unmodified. This implies big-endian byte order if bits_per_pixel is
- * greater than 8.
- */
-
- if(info.bits_per_pixel == 32) {
- /*
- * Explicitly request RGBA_8888
- */
- info.bits_per_pixel = 32;
- info.red.offset = 24;
- info.red.length = 8;
- info.green.offset = 16;
- info.green.length = 8;
- info.blue.offset = 8;
- info.blue.length = 8;
- info.transp.offset = 0;
- info.transp.length = 8;
-
- /* Note: the GL driver does not have a r=8 g=8 b=8 a=0 config, so if we
- * do not use the MDP for composition (i.e. hw composition == 0), ask
- * for RGBA instead of RGBX. */
- if (property_get("debug.sf.hw", property, NULL) > 0 &&
- atoi(property) == 0)
- module->fbFormat = HAL_PIXEL_FORMAT_RGBX_8888;
- else if(property_get("debug.composition.type", property, NULL) > 0 &&
- (strncmp(property, "mdp", 3) == 0))
- module->fbFormat = HAL_PIXEL_FORMAT_RGBX_8888;
- else
- module->fbFormat = HAL_PIXEL_FORMAT_RGBA_8888;
- } else {
- /*
- * Explicitly request 5/6/5
- */
- info.bits_per_pixel = 16;
- info.red.offset = 11;
- info.red.length = 5;
- info.green.offset = 5;
- info.green.length = 6;
- info.blue.offset = 0;
- info.blue.length = 5;
- info.transp.offset = 0;
- info.transp.length = 0;
- module->fbFormat = HAL_PIXEL_FORMAT_RGB_565;
- }
-
- //adreno needs 4k aligned offsets. Max hole size is 4096-1
- unsigned int size = roundUpToPageSize(info.yres * info.xres *
- (info.bits_per_pixel/8));
-
- /*
- * Request NUM_BUFFERS screens (at least 2 for page flipping)
- */
- int numberOfBuffers = (int)(finfo.smem_len/size);
- ALOGV("num supported framebuffers in kernel = %d", numberOfBuffers);
-
- if (property_get("debug.gr.numframebuffers", property, NULL) > 0) {
- int num = atoi(property);
- if ((num >= NUM_FRAMEBUFFERS_MIN) && (num <= NUM_FRAMEBUFFERS_MAX)) {
- numberOfBuffers = num;
- }
- }
- if (numberOfBuffers > NUM_FRAMEBUFFERS_MAX)
- numberOfBuffers = NUM_FRAMEBUFFERS_MAX;
-
- ALOGV("We support %d buffers", numberOfBuffers);
-
- //consider the included hole by 4k alignment
- uint32_t line_length = (info.xres * info.bits_per_pixel / 8);
- info.yres_virtual = (uint32_t) ((size * numberOfBuffers) / line_length);
-
- uint32_t flags = PAGE_FLIP;
-
- if (info.yres_virtual < ((size * 2) / line_length) ) {
- // we need at least 2 for page-flipping
- info.yres_virtual = (int)(size / line_length);
- flags &= ~PAGE_FLIP;
- ALOGW("page flipping not supported (yres_virtual=%d, requested=%d)",
- info.yres_virtual, info.yres*2);
- }
-
- if (ioctl(fd, FBIOGET_VSCREENINFO, &info) == -1) {
- close(fd);
- return -errno;
- }
-
- if (int(info.width) <= 0 || int(info.height) <= 0) {
- // the driver doesn't return that information
- // default to 160 dpi
- info.width = (uint32_t)(((float)(info.xres) * 25.4f)/160.0f + 0.5f);
- info.height = (uint32_t)(((float)(info.yres) * 25.4f)/160.0f + 0.5f);
- }
-
- float xdpi = ((float)(info.xres) * 25.4f) / (float)info.width;
- float ydpi = ((float)(info.yres) * 25.4f) / (float)info.height;
-
-#ifdef MSMFB_METADATA_GET
- struct msmfb_metadata metadata;
- memset(&metadata, 0 , sizeof(metadata));
- metadata.op = metadata_op_frame_rate;
- if (ioctl(fd, MSMFB_METADATA_GET, &metadata) == -1) {
- ALOGE("Error retrieving panel frame rate");
- close(fd);
- return -errno;
- }
- float fps = (float)metadata.data.panel_frame_rate;
-#else
- //XXX: Remove reserved field usage on all baselines
- //The reserved[3] field is used to store FPS by the driver.
- float fps = info.reserved[3] & 0xFF;
-#endif
- ALOGI("using (fd=%d)\n"
- "id = %s\n"
- "xres = %d px\n"
- "yres = %d px\n"
- "xres_virtual = %d px\n"
- "yres_virtual = %d px\n"
- "bpp = %d\n"
- "r = %2u:%u\n"
- "g = %2u:%u\n"
- "b = %2u:%u\n",
- fd,
- finfo.id,
- info.xres,
- info.yres,
- info.xres_virtual,
- info.yres_virtual,
- info.bits_per_pixel,
- info.red.offset, info.red.length,
- info.green.offset, info.green.length,
- info.blue.offset, info.blue.length
- );
-
- ALOGI("width = %d mm (%f dpi)\n"
- "height = %d mm (%f dpi)\n"
- "refresh rate = %.2f Hz\n",
- info.width, xdpi,
- info.height, ydpi,
- fps
- );
-
-
- if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo) == -1) {
- close(fd);
- return -errno;
- }
-
- if (finfo.smem_len <= 0) {
- close(fd);
- return -errno;
- }
-
- module->flags = flags;
- module->info = info;
- module->finfo = finfo;
- module->xdpi = xdpi;
- module->ydpi = ydpi;
- module->fps = fps;
- module->swapInterval = 1;
-
- CALC_INIT();
-
- /*
- * map the framebuffer
- */
-
- module->numBuffers = info.yres_virtual / info.yres;
- module->bufferMask = 0;
- //adreno needs page aligned offsets. Align the fbsize to pagesize.
- unsigned int fbSize = roundUpToPageSize(finfo.line_length * info.yres)*
- module->numBuffers;
- void* vaddr = mmap(0, fbSize, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
- if (vaddr == MAP_FAILED) {
- ALOGE("Error mapping the framebuffer (%s)", strerror(errno));
- close(fd);
- return -errno;
- }
- //store the framebuffer fd in the ctx
- ctx->fbFd = fd;
-#ifdef MSMFB_METADATA_GET
- memset(&metadata, 0 , sizeof(metadata));
- metadata.op = metadata_op_get_ion_fd;
- // get the ION fd for the framebuffer, as GPU needs ION fd
- if (ioctl(fd, MSMFB_METADATA_GET, &metadata) == -1) {
- ALOGE("Error getting ION fd (%s)", strerror(errno));
- close(fd);
- return -errno;
- }
- if(metadata.data.fbmem_ionfd < 0) {
- ALOGE("Error: Ioctl returned invalid ION fd = %d",
- metadata.data.fbmem_ionfd);
- close(fd);
- return -errno;
- }
- fd = metadata.data.fbmem_ionfd;
-#endif
- // Create framebuffer handle using the ION fd
- module->framebuffer = new private_handle_t(fd, fbSize,
- private_handle_t::PRIV_FLAGS_USES_ION,
- BUFFER_TYPE_UI,
- module->fbFormat, info.xres, info.yres);
- module->framebuffer->base = uint64_t(vaddr);
- memset(vaddr, 0, fbSize);
- //Enable vsync
- int enable = 1;
- ioctl(ctx->fbFd, MSMFB_OVERLAY_VSYNC_CTRL, &enable);
- return 0;
-}
-
-static int mapFrameBuffer(framebuffer_device_t *dev)
-{
- int err = -1;
- char property[PROPERTY_VALUE_MAX];
- if((property_get("debug.gralloc.map_fb_memory", property, NULL) > 0) &&
- (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
- (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
- private_module_t* module =
- reinterpret_cast<private_module_t*>(dev->common.module);
- pthread_mutex_lock(&module->lock);
- err = mapFrameBufferLocked(dev);
- pthread_mutex_unlock(&module->lock);
- }
- return err;
-}
-
-/*****************************************************************************/
-
-static int fb_close(struct hw_device_t *dev)
-{
- fb_context_t* ctx = (fb_context_t*)dev;
- if (ctx) {
-#ifdef MSMFB_METADATA_GET
- if(ctx->fbFd >=0) {
- close(ctx->fbFd);
- }
-#endif
- //Hack until fbdev is removed. Framework could close this causing hwc a
- //pain.
- //free(ctx);
- }
- return 0;
-}
-
-int fb_device_open(hw_module_t const* module, const char* name,
- hw_device_t** device)
-{
- int status = -EINVAL;
- if (!strcmp(name, GRALLOC_HARDWARE_FB0)) {
- alloc_device_t* gralloc_device;
- status = gralloc_open(module, &gralloc_device);
- if (status < 0)
- return status;
-
- /* initialize our state here */
- fb_context_t *dev = (fb_context_t*)malloc(sizeof(*dev));
- if(dev == NULL) {
- gralloc_close(gralloc_device);
- return status;
- }
- memset(dev, 0, sizeof(*dev));
-
- /* initialize the procs */
- dev->device.common.tag = HARDWARE_DEVICE_TAG;
- dev->device.common.version = 0;
- dev->device.common.module = const_cast<hw_module_t*>(module);
- dev->device.common.close = fb_close;
- dev->device.setSwapInterval = fb_setSwapInterval;
- dev->device.post = fb_post;
- dev->device.setUpdateRect = 0;
- dev->device.compositionComplete = fb_compositionComplete;
-
- status = mapFrameBuffer((framebuffer_device_t*)dev);
- private_module_t* m = (private_module_t*)dev->device.common.module;
- if (status >= 0) {
- int stride = m->finfo.line_length / (m->info.bits_per_pixel >> 3);
- const_cast<uint32_t&>(dev->device.flags) = 0;
- const_cast<uint32_t&>(dev->device.width) = m->info.xres;
- const_cast<uint32_t&>(dev->device.height) = m->info.yres;
- const_cast<int&>(dev->device.stride) = stride;
- const_cast<int&>(dev->device.format) = m->fbFormat;
- const_cast<float&>(dev->device.xdpi) = m->xdpi;
- const_cast<float&>(dev->device.ydpi) = m->ydpi;
- const_cast<float&>(dev->device.fps) = m->fps;
- const_cast<int&>(dev->device.minSwapInterval) =
- PRIV_MIN_SWAP_INTERVAL;
- const_cast<int&>(dev->device.maxSwapInterval) =
- PRIV_MAX_SWAP_INTERVAL;
- const_cast<int&>(dev->device.numFramebuffers) = m->numBuffers;
- dev->device.setUpdateRect = 0;
-
- *device = &dev->device.common;
- }
-
- // Close the gralloc module
- gralloc_close(gralloc_device);
- }
- return status;
-}
diff --git a/libgralloc/gpu.h b/libgralloc/gpu.h
deleted file mode 100644
index 2248d30..0000000
--- a/libgralloc/gpu.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef GRALLOC_GPU_H_
-#define GRALLOC_GPU_H_
-
-#include <errno.h>
-#include <pthread.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <cutils/log.h>
-
-#include "gralloc_priv.h"
-#include "fb_priv.h"
-
-namespace gralloc {
-class IAllocController;
-class gpu_context_t : public alloc_device_t {
- public:
- gpu_context_t(const private_module_t* module,
- IAllocController* alloc_ctrl);
-
- int gralloc_alloc_buffer(unsigned int size, int usage,
- buffer_handle_t* pHandle,
- int bufferType, int format,
- int width, int height);
-
- int free_impl(private_handle_t const* hnd);
-
- int alloc_impl(int w, int h, int format, int usage,
- buffer_handle_t* pHandle, int* pStride,
- unsigned int bufferSize = 0);
-
- static int gralloc_alloc(alloc_device_t* dev, int w, int h,
- int format, int usage,
- buffer_handle_t* pHandle,
- int* pStride);
- int gralloc_alloc_framebuffer_locked(int usage,
- buffer_handle_t* pHandle);
-
- int gralloc_alloc_framebuffer(int usage,
- buffer_handle_t* pHandle);
-
- static int gralloc_free(alloc_device_t* dev, buffer_handle_t handle);
-
- static int gralloc_alloc_size(alloc_device_t* dev,
- int w, int h, int format,
- int usage, buffer_handle_t* pHandle,
- int* pStride, int bufferSize);
-
- static int gralloc_close(struct hw_device_t *dev);
-
- private:
- IAllocController* mAllocCtrl;
- void getGrallocInformationFromFormat(int inputFormat,
- int *bufferType);
-};
-}
-#endif // GRALLOC_GPU_H
diff --git a/libgralloc/gralloc.cpp b/libgralloc/gralloc.cpp
deleted file mode 100644
index 237b8a8..0000000
--- a/libgralloc/gralloc.cpp
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright (C) 2008, The Android Open Source Project
- * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <unistd.h>
-#include <fcntl.h>
-
-#include <sys/mman.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <cutils/properties.h>
-
-#include "gr.h"
-#include "gpu.h"
-#include "memalloc.h"
-#include "alloc_controller.h"
-
-using namespace gralloc;
-
-int fb_device_open(const hw_module_t* module, const char* name,
- hw_device_t** device);
-
-static int gralloc_device_open(const hw_module_t* module, const char* name,
- hw_device_t** device);
-
-extern int gralloc_lock(gralloc_module_t const* module,
- buffer_handle_t handle, int usage,
- int l, int t, int w, int h,
- void** vaddr);
-
-extern int gralloc_lock_ycbcr(gralloc_module_t const* module,
- buffer_handle_t handle, int usage,
- int l, int t, int w, int h,
- struct android_ycbcr *ycbcr);
-
-extern int gralloc_unlock(gralloc_module_t const* module,
- buffer_handle_t handle);
-
-extern int gralloc_register_buffer(gralloc_module_t const* module,
- buffer_handle_t handle);
-
-extern int gralloc_unregister_buffer(gralloc_module_t const* module,
- buffer_handle_t handle);
-
-extern int gralloc_perform(struct gralloc_module_t const* module,
- int operation, ... );
-
-// HAL module methods
-static struct hw_module_methods_t gralloc_module_methods = {
- .open = gralloc_device_open
-};
-
-// HAL module initialize
-struct private_module_t HAL_MODULE_INFO_SYM = {
- .base = {
- .common = {
- .tag = HARDWARE_MODULE_TAG,
- .version_major = 1,
- .version_minor = 0,
- .id = GRALLOC_HARDWARE_MODULE_ID,
- .name = "Graphics Memory Allocator Module",
- .author = "The Android Open Source Project",
- .methods = &gralloc_module_methods,
- .dso = 0,
- .reserved = {0},
- },
- .registerBuffer = gralloc_register_buffer,
- .unregisterBuffer = gralloc_unregister_buffer,
- .lock = gralloc_lock,
- .unlock = gralloc_unlock,
- .perform = gralloc_perform,
- .lock_ycbcr = gralloc_lock_ycbcr,
- },
- .framebuffer = 0,
- .fbFormat = 0,
- .flags = 0,
- .numBuffers = 0,
- .bufferMask = 0,
- .lock = PTHREAD_MUTEX_INITIALIZER,
-};
-
-// Open Gralloc device
-int gralloc_device_open(const hw_module_t* module, const char* name,
- hw_device_t** device)
-{
- int status = -EINVAL;
- if (!strcmp(name, GRALLOC_HARDWARE_GPU0)) {
- const private_module_t* m = reinterpret_cast<const private_module_t*>(
- module);
- gpu_context_t *dev;
- IAllocController* alloc_ctrl = IAllocController::getInstance();
- dev = new gpu_context_t(m, alloc_ctrl);
- if(!dev)
- return status;
-
- *device = &dev->common;
- status = 0;
- } else {
- status = fb_device_open(module, name, device);
- }
- return status;
-}
diff --git a/libgralloc/gralloc_priv.h b/libgralloc/gralloc_priv.h
index 0f1f97a..f0c6b4d 100644
--- a/libgralloc/gralloc_priv.h
+++ b/libgralloc/gralloc_priv.h
@@ -26,6 +26,14 @@
#include <errno.h>
#include <unistd.h>
+
+/* DEPRECATION NOTICE: This file is no longer used, please use the new
+ * implementation in libgralloc1
+ */
+
+
+
+
#include <cutils/native_handle.h>
#include <cutils/log.h>
diff --git a/libgralloc/ionalloc.cpp b/libgralloc/ionalloc.cpp
deleted file mode 100644
index 329e30f..0000000
--- a/libgralloc/ionalloc.cpp
+++ /dev/null
@@ -1,236 +0,0 @@
-/*
- * Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
-
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- * * Neither the name of The Linux Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
- * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#define DEBUG 0
-#define ATRACE_TAG (ATRACE_TAG_GRAPHICS | ATRACE_TAG_HAL)
-#include <sys/ioctl.h>
-#include <sys/mman.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <cutils/log.h>
-#include <errno.h>
-#include <utils/Trace.h>
-#include <cutils/trace.h>
-#include "gralloc_priv.h"
-#include "ionalloc.h"
-
-using gralloc::IonAlloc;
-
-#define ION_DEVICE "/dev/ion"
-
-int IonAlloc::open_device()
-{
- if(mIonFd == FD_INIT)
- mIonFd = open(ION_DEVICE, O_RDONLY);
-
- if(mIonFd < 0 ) {
- ALOGE("%s: Failed to open ion device - %s",
- __FUNCTION__, strerror(errno));
- mIonFd = FD_INIT;
- return -errno;
- }
- return 0;
-}
-
-void IonAlloc::close_device()
-{
- if(mIonFd >= 0)
- close(mIonFd);
- mIonFd = FD_INIT;
-}
-
-int IonAlloc::alloc_buffer(alloc_data& data)
-{
- ATRACE_CALL();
- Locker::Autolock _l(mLock);
- int err = 0;
- struct ion_handle_data handle_data;
- struct ion_fd_data fd_data;
- struct ion_allocation_data ionAllocData;
- void *base = 0;
-
- ionAllocData.len = data.size;
- ionAllocData.align = data.align;
- ionAllocData.heap_id_mask = data.heapId;
- ionAllocData.flags = data.flags;
- ionAllocData.flags |= data.uncached ? 0 : ION_FLAG_CACHED;
- err = open_device();
- if (err)
- return err;
- if(ioctl(mIonFd, ION_IOC_ALLOC, &ionAllocData)) {
- err = -errno;
- ALOGE("ION_IOC_ALLOC failed with error - %s", strerror(errno));
- return err;
- }
-
- fd_data.handle = ionAllocData.handle;
- handle_data.handle = ionAllocData.handle;
- if(ioctl(mIonFd, ION_IOC_MAP, &fd_data)) {
- err = -errno;
- ALOGE("%s: ION_IOC_MAP failed with error - %s",
- __FUNCTION__, strerror(errno));
- ioctl(mIonFd, ION_IOC_FREE, &handle_data);
- return err;
- }
-
- if(!(data.flags & ION_SECURE)) {
- base = mmap(0, ionAllocData.len, PROT_READ|PROT_WRITE,
- MAP_SHARED, fd_data.fd, 0);
- if(base == MAP_FAILED) {
- err = -errno;
- ALOGE("%s: Failed to map the allocated memory: %s",
- __FUNCTION__, strerror(errno));
- ioctl(mIonFd, ION_IOC_FREE, &handle_data);
- return err;
- }
- }
-
- data.base = base;
- data.fd = fd_data.fd;
- ioctl(mIonFd, ION_IOC_FREE, &handle_data);
- ALOGD_IF(DEBUG, "ion: Allocated buffer base:%p size:%zu fd:%d",
- data.base, ionAllocData.len, data.fd);
- return 0;
-}
-
-
-int IonAlloc::free_buffer(void* base, unsigned int size, unsigned int offset,
- int fd)
-{
- ATRACE_CALL();
- Locker::Autolock _l(mLock);
- ALOGD_IF(DEBUG, "ion: Freeing buffer base:%p size:%u fd:%d",
- base, size, fd);
- int err = 0;
- err = open_device();
- if (err)
- return err;
-
- if(base)
- err = unmap_buffer(base, size, offset);
- close(fd);
- return err;
-}
-
-int IonAlloc::map_buffer(void **pBase, unsigned int size, unsigned int offset,
- int fd)
-{
- ATRACE_CALL();
- int err = 0;
- void *base = 0;
- // It is a (quirky) requirement of ION to have opened the
- // ion fd in the process that is doing the mapping
- err = open_device();
- if (err)
- return err;
-
- base = mmap(0, size, PROT_READ| PROT_WRITE,
- MAP_SHARED, fd, 0);
- *pBase = base;
- if(base == MAP_FAILED) {
- err = -errno;
- ALOGE("ion: Failed to map memory in the client: %s",
- strerror(errno));
- } else {
- ALOGD_IF(DEBUG, "ion: Mapped buffer base:%p size:%u offset:%u fd:%d",
- base, size, offset, fd);
- }
- return err;
-}
-
-int IonAlloc::unmap_buffer(void *base, unsigned int size,
- unsigned int /*offset*/)
-{
- ATRACE_CALL();
- ALOGD_IF(DEBUG, "ion: Unmapping buffer base:%p size:%u", base, size);
- int err = 0;
- if(munmap(base, size)) {
- err = -errno;
- ALOGE("ion: Failed to unmap memory at %p : %s",
- base, strerror(errno));
- }
- return err;
-
-}
-int IonAlloc::clean_buffer(void *base, unsigned int size, unsigned int offset,
- int fd, int op)
-{
- ATRACE_CALL();
- ATRACE_INT("operation id", op);
- struct ion_flush_data flush_data;
- struct ion_fd_data fd_data;
- struct ion_handle_data handle_data;
- int err = 0;
-
- err = open_device();
- if (err)
- return err;
-
- fd_data.fd = fd;
- if (ioctl(mIonFd, ION_IOC_IMPORT, &fd_data)) {
- err = -errno;
- ALOGE("%s: ION_IOC_IMPORT failed with error - %s",
- __FUNCTION__, strerror(errno));
- return err;
- }
-
- handle_data.handle = fd_data.handle;
- flush_data.handle = fd_data.handle;
- flush_data.vaddr = base;
- // offset and length are unsigned int
- flush_data.offset = offset;
- flush_data.length = size;
-
- struct ion_custom_data d;
- switch(op) {
- case CACHE_CLEAN:
- d.cmd = ION_IOC_CLEAN_CACHES;
- break;
- case CACHE_INVALIDATE:
- d.cmd = ION_IOC_INV_CACHES;
- break;
- case CACHE_CLEAN_AND_INVALIDATE:
- default:
- d.cmd = ION_IOC_CLEAN_INV_CACHES;
- }
-
- d.arg = (unsigned long int)&flush_data;
-
- if(ioctl(mIonFd, ION_IOC_CUSTOM, &d)) {
- err = -errno;
- ALOGE("%s: ION_IOC_CLEAN_INV_CACHES failed with error - %s",
-
- __FUNCTION__, strerror(errno));
- ioctl(mIonFd, ION_IOC_FREE, &handle_data);
- return err;
- }
- ioctl(mIonFd, ION_IOC_FREE, &handle_data);
- return 0;
-}
-
diff --git a/libgralloc/ionalloc.h b/libgralloc/ionalloc.h
deleted file mode 100644
index 635bda5..0000000
--- a/libgralloc/ionalloc.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
-
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- * * Neither the name of The Linux Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
- * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GRALLOC_IONALLOC_H
-#define GRALLOC_IONALLOC_H
-
-#include <linux/msm_ion.h>
-#include "memalloc.h"
-#include "gr.h"
-
-namespace gralloc {
-
-class IonAlloc : public IMemAlloc {
-
- public:
- virtual int alloc_buffer(alloc_data& data);
-
- virtual int free_buffer(void *base, unsigned int size,
- unsigned int offset, int fd);
-
- virtual int map_buffer(void **pBase, unsigned int size,
- unsigned int offset, int fd);
-
- virtual int unmap_buffer(void *base, unsigned int size,
- unsigned int offset);
-
- virtual int clean_buffer(void*base, unsigned int size,
- unsigned int offset, int fd, int op);
-
- IonAlloc() { mIonFd = FD_INIT; }
-
- ~IonAlloc() { close_device(); }
-
- private:
- int mIonFd;
-
- int open_device();
-
- void close_device();
-
- mutable Locker mLock;
-
-};
-
-}
-
-#endif /* GRALLOC_IONALLOC_H */
-
diff --git a/libgralloc/mapper.cpp b/libgralloc/mapper.cpp
deleted file mode 100644
index acf5e2c..0000000
--- a/libgralloc/mapper.cpp
+++ /dev/null
@@ -1,523 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * Copyright (c) 2011-2017, The Linux Foundation. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define ATRACE_TAG (ATRACE_TAG_GRAPHICS | ATRACE_TAG_HAL)
-#include <limits.h>
-#include <errno.h>
-#include <pthread.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdarg.h>
-
-#include <sys/mman.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/ioctl.h>
-
-#include <cutils/log.h>
-#include <cutils/atomic.h>
-#include <utils/Trace.h>
-
-#include <hardware/hardware.h>
-#include <hardware/gralloc.h>
-
-#include "gralloc_priv.h"
-#include "gr.h"
-#include "alloc_controller.h"
-#include "memalloc.h"
-#include <qdMetaData.h>
-
-
-using namespace gralloc;
-/*****************************************************************************/
-
-// Return the type of allocator -
-// these are used for mapping/unmapping
-static IMemAlloc* getAllocator(int flags)
-{
- IMemAlloc* memalloc;
- IAllocController* alloc_ctrl = IAllocController::getInstance();
- memalloc = alloc_ctrl->getAllocator(flags);
- return memalloc;
-}
-
-static int gralloc_map_metadata(buffer_handle_t handle) {
- private_handle_t* hnd = (private_handle_t*)handle;
- hnd->base_metadata = 0;
- IMemAlloc* memalloc = getAllocator(hnd->flags) ;
- void *mappedAddress = MAP_FAILED;
- unsigned int size = 0;
- if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)) {
- mappedAddress = MAP_FAILED;
- size = ROUND_UP_PAGESIZE(sizeof(MetaData_t));
- int ret = memalloc->map_buffer(&mappedAddress, size,
- hnd->offset_metadata, hnd->fd_metadata);
- if(ret || mappedAddress == MAP_FAILED) {
- ALOGE("Could not mmap metadata for handle %p, fd=%d (%s)",
- hnd, hnd->fd_metadata, strerror(errno));
- return -errno;
- }
- hnd->base_metadata = uint64_t(mappedAddress) + hnd->offset_metadata;
- }
- return 0;
-}
-
-static int gralloc_map(gralloc_module_t const* module,
- buffer_handle_t handle)
-{
- ATRACE_CALL();
- if(!module)
- return -EINVAL;
-
- private_handle_t* hnd = (private_handle_t*)handle;
- unsigned int size = 0;
- int err = 0;
- IMemAlloc* memalloc = getAllocator(hnd->flags) ;
- void *mappedAddress = MAP_FAILED;
- hnd->base = 0;
-
- // Dont map framebuffer and secure buffers
- if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER) &&
- !(hnd->flags & private_handle_t::PRIV_FLAGS_SECURE_BUFFER)) {
- size = hnd->size;
- err = memalloc->map_buffer(&mappedAddress, size,
- hnd->offset, hnd->fd);
- if(err || mappedAddress == MAP_FAILED) {
- ALOGE("Could not mmap handle %p, fd=%d (%s)",
- handle, hnd->fd, strerror(errno));
- return -errno;
- }
-
- hnd->base = uint64_t(mappedAddress) + hnd->offset;
- } else {
- // Cannot map secure buffers or framebuffers, but still need to map
- // metadata for secure buffers.
- // If mapping a secure buffers fails, the framework needs to get
- // an error code.
- err = -EACCES;
- }
-
- //Allow mapping of metadata for all buffers including secure ones, but not
- //of framebuffer
- int metadata_err = gralloc_map_metadata(handle);
- if (!err) {
- err = metadata_err;
- }
- return err;
-}
-
-static int gralloc_unmap(gralloc_module_t const* module,
- buffer_handle_t handle)
-{
- ATRACE_CALL();
- int err = -EINVAL;
- if(!module)
- return err;
-
- private_handle_t* hnd = (private_handle_t*)handle;
- IMemAlloc* memalloc = getAllocator(hnd->flags) ;
- if(!memalloc)
- return err;
-
- if(hnd->base) {
- err = memalloc->unmap_buffer((void*)hnd->base, hnd->size, hnd->offset);
- if (err) {
- ALOGE("Could not unmap memory at address %p, %s", (void*) hnd->base,
- strerror(errno));
- return -errno;
- }
- hnd->base = 0;
- }
-
- if(hnd->base_metadata) {
- unsigned int size = ROUND_UP_PAGESIZE(sizeof(MetaData_t));
- err = memalloc->unmap_buffer((void*)hnd->base_metadata,
- size, hnd->offset_metadata);
- if (err) {
- ALOGE("Could not unmap memory at address %p, %s",
- (void*) hnd->base_metadata, strerror(errno));
- return -errno;
- }
- hnd->base_metadata = 0;
- }
-
- return 0;
-}
-
-/*****************************************************************************/
-
-static pthread_mutex_t sMapLock = PTHREAD_MUTEX_INITIALIZER;
-
-/*****************************************************************************/
-
-int gralloc_register_buffer(gralloc_module_t const* module,
- buffer_handle_t handle)
-{
- ATRACE_CALL();
- if (!module || private_handle_t::validate(handle) < 0)
- return -EINVAL;
-
- int err = gralloc_map(module, handle);
- /* Do not fail register_buffer for secure buffers*/
- if (err == -EACCES)
- err = 0;
- return err;
-}
-
-int gralloc_unregister_buffer(gralloc_module_t const* module,
- buffer_handle_t handle)
-{
- ATRACE_CALL();
- if (!module || private_handle_t::validate(handle) < 0)
- return -EINVAL;
-
- /*
- * If the buffer has been mapped during a lock operation, it's time
- * to un-map it. It's an error to be here with a locked buffer.
- * NOTE: the framebuffer is handled differently and is never unmapped.
- * Also base and base_metadata are reset.
- */
- return gralloc_unmap(module, handle);
-}
-
-int terminateBuffer(gralloc_module_t const* module,
- private_handle_t* hnd)
-{
- ATRACE_CALL();
- if(!module)
- return -EINVAL;
-
- /*
- * If the buffer has been mapped during a lock operation, it's time
- * to un-map it. It's an error to be here with a locked buffer.
- * NOTE: the framebuffer is handled differently and is never unmapped.
- * Also base and base_metadata are reset.
- */
- return gralloc_unmap(module, hnd);
-}
-
-static int gralloc_map_and_invalidate (gralloc_module_t const* module,
- buffer_handle_t handle, int usage)
-{
- ATRACE_CALL();
- if (!module || private_handle_t::validate(handle) < 0)
- return -EINVAL;
-
- int err = 0;
- private_handle_t* hnd = (private_handle_t*)handle;
- if (usage & (GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK)) {
- if (hnd->base == 0) {
- // we need to map for real
- pthread_mutex_t* const lock = &sMapLock;
- pthread_mutex_lock(lock);
- err = gralloc_map(module, handle);
- pthread_mutex_unlock(lock);
- }
- if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_ION and
- hnd->flags & private_handle_t::PRIV_FLAGS_CACHED) {
- //Invalidate if CPU reads in software and there are non-CPU
- //writers. No need to do this for the metadata buffer as it is
- //only read/written in software.
- if ((usage & GRALLOC_USAGE_SW_READ_MASK) and
- (hnd->flags & private_handle_t::PRIV_FLAGS_NON_CPU_WRITER))
- {
- IMemAlloc* memalloc = getAllocator(hnd->flags) ;
- err = memalloc->clean_buffer((void*)hnd->base,
- hnd->size, hnd->offset, hnd->fd,
- CACHE_INVALIDATE);
- }
- //Mark the buffer to be flushed after CPU write.
- if (usage & GRALLOC_USAGE_SW_WRITE_MASK) {
- hnd->flags |= private_handle_t::PRIV_FLAGS_NEEDS_FLUSH;
- }
- }
- }
-
- return err;
-}
-
-int gralloc_lock(gralloc_module_t const* module,
- buffer_handle_t handle, int usage,
- int /*l*/, int /*t*/, int /*w*/, int /*h*/,
- void** vaddr)
-{
- ATRACE_CALL();
- private_handle_t* hnd = (private_handle_t*)handle;
- int err = gralloc_map_and_invalidate(module, handle, usage);
- if(!err)
- *vaddr = (void*)hnd->base;
- return err;
-}
-
-int gralloc_lock_ycbcr(gralloc_module_t const* module,
- buffer_handle_t handle, int usage,
- int /*l*/, int /*t*/, int /*w*/, int /*h*/,
- struct android_ycbcr *ycbcr)
-{
- ATRACE_CALL();
- private_handle_t* hnd = (private_handle_t*)handle;
- int err = gralloc_map_and_invalidate(module, handle, usage);
- if(!err)
- err = getYUVPlaneInfo(hnd, ycbcr);
- return err;
-}
-
-int gralloc_unlock(gralloc_module_t const* module,
- buffer_handle_t handle)
-{
- ATRACE_CALL();
- if (!module || private_handle_t::validate(handle) < 0)
- return -EINVAL;
-
- int err = 0;
- private_handle_t* hnd = (private_handle_t*)handle;
-
- IMemAlloc* memalloc = getAllocator(hnd->flags);
- if (hnd->flags & private_handle_t::PRIV_FLAGS_NEEDS_FLUSH) {
- err = memalloc->clean_buffer((void*)hnd->base,
- hnd->size, hnd->offset, hnd->fd,
- CACHE_CLEAN);
- hnd->flags &= ~private_handle_t::PRIV_FLAGS_NEEDS_FLUSH;
- }
-
- return err;
-}
-
-/*****************************************************************************/
-
-int gralloc_perform(struct gralloc_module_t const* module,
- int operation, ... )
-{
- int res = -EINVAL;
- va_list args;
- if(!module)
- return res;
-
- va_start(args, operation);
- switch (operation) {
- case GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER:
- {
- int fd = va_arg(args, int);
- unsigned int size = va_arg(args, unsigned int);
- unsigned int offset = va_arg(args, unsigned int);
- void* base = va_arg(args, void*);
- int width = va_arg(args, int);
- int height = va_arg(args, int);
- int format = va_arg(args, int);
- int alignedw = 0, alignedh = 0;
-
- native_handle_t** handle = va_arg(args, native_handle_t**);
- private_handle_t* hnd = (private_handle_t*)native_handle_create(
- private_handle_t::sNumFds, private_handle_t::sNumInts());
- if (hnd) {
- hnd->magic = private_handle_t::sMagic;
- hnd->fd = fd;
- hnd->flags = private_handle_t::PRIV_FLAGS_USES_ION;
- hnd->size = size;
- hnd->offset = offset;
- hnd->base = uint64_t(base) + offset;
- hnd->gpuaddr = 0;
- AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(width,
- height, format, 0, alignedw, alignedh);
- hnd->width = alignedw;
- hnd->height = alignedh;
- hnd->unaligned_width = width;
- hnd->unaligned_height = height;
- hnd->format = format;
- *handle = (native_handle_t *)hnd;
- res = 0;
- }
- break;
-
- }
- case GRALLOC_MODULE_PERFORM_GET_STRIDE:
- {
- int width = va_arg(args, int);
- int format = va_arg(args, int);
- int *stride = va_arg(args, int *);
- int alignedw = 0, alignedh = 0;
- AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(width,
- 0, format, 0, alignedw, alignedh);
- *stride = alignedw;
- res = 0;
- } break;
-
- case GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_FROM_HANDLE:
- {
- const private_handle_t* hnd = va_arg(args, private_handle_t*);
- int *stride = va_arg(args, int *);
- if (private_handle_t::validate(hnd)) {
- return res;
- }
-
- int alignedw = 0, alignedh = 0;
- AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(hnd, alignedw, alignedh);
- *stride = alignedw;
-
- res = 0;
- } break;
-
- case GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_AND_HEIGHT_FROM_HANDLE:
- {
- const private_handle_t* hnd = va_arg(args, private_handle_t*);
- int *stride = va_arg(args, int *);
- int *height = va_arg(args, int *);
- if (private_handle_t::validate(hnd)) {
- return res;
- }
-
- int alignedw = 0, alignedh = 0;
- AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(hnd, alignedw, alignedh);
- *stride = alignedw;
- *height = alignedh;
-
- res = 0;
- } break;
-
- case GRALLOC_MODULE_PERFORM_GET_ATTRIBUTES:
- {
- int width = va_arg(args, int);
- int height = va_arg(args, int);
- int format = va_arg(args, int);
- int usage = va_arg(args, int);
- int *alignedWidth = va_arg(args, int *);
- int *alignedHeight = va_arg(args, int *);
- int *tileEnabled = va_arg(args,int *);
- *tileEnabled = isUBwcEnabled(format, usage);
- AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(width,
- height, format, usage, *alignedWidth, *alignedHeight);
- res = 0;
- } break;
-
- case GRALLOC_MODULE_PERFORM_GET_COLOR_SPACE_FROM_HANDLE:
- {
- private_handle_t* hnd = va_arg(args, private_handle_t*);
- int *color_space = va_arg(args, int *);
- if (private_handle_t::validate(hnd)) {
- return res;
- }
- MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
- if (!metadata) {
- break;
-#ifdef USE_COLOR_METADATA
- } else if (metadata->operation & COLOR_METADATA) {
- ColorMetaData *colorMetadata = &metadata->color;
- res = 0;
- switch (colorMetadata->colorPrimaries) {
- case ColorPrimaries_BT709_5:
- *color_space = HAL_CSC_ITU_R_709;
- break;
- case ColorPrimaries_BT601_6_525:
- *color_space = ((colorMetadata->range) ?
- HAL_CSC_ITU_R_601_FR : HAL_CSC_ITU_R_601);
- break;
- case ColorPrimaries_BT2020:
- *color_space = (colorMetadata->range) ?
- HAL_CSC_ITU_R_2020_FR : HAL_CSC_ITU_R_2020;
- break;
- default:
- res = -EINVAL;
- break;
- }
-#endif
- } else if(metadata->operation & UPDATE_COLOR_SPACE) {
- *color_space = metadata->colorSpace;
- res = 0;
- }
- } break;
-
- case GRALLOC_MODULE_PERFORM_GET_YUV_PLANE_INFO:
- {
- private_handle_t* hnd = va_arg(args, private_handle_t*);
- android_ycbcr* ycbcr = va_arg(args, struct android_ycbcr *);
- if (!private_handle_t::validate(hnd)) {
- res = getYUVPlaneInfo(hnd, ycbcr);
- }
- } break;
-
- case GRALLOC_MODULE_PERFORM_GET_MAP_SECURE_BUFFER_INFO:
- {
- private_handle_t* hnd = va_arg(args, private_handle_t*);
- int *map_secure_buffer = va_arg(args, int *);
- if (private_handle_t::validate(hnd)) {
- return res;
- }
- MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
- if(metadata && metadata->operation & MAP_SECURE_BUFFER) {
- *map_secure_buffer = metadata->mapSecureBuffer;
- res = 0;
- } else {
- *map_secure_buffer = 0;
- }
- } break;
-
- case GRALLOC_MODULE_PERFORM_GET_UBWC_FLAG:
- {
- private_handle_t* hnd = va_arg(args, private_handle_t*);
- int *flag = va_arg(args, int *);
- if (private_handle_t::validate(hnd)) {
- return res;
- }
- *flag = hnd->flags & private_handle_t::PRIV_FLAGS_UBWC_ALIGNED;
- MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
- if (metadata && (metadata->operation & LINEAR_FORMAT)) {
- *flag = 0;
- }
- res = 0;
- } break;
-
- case GRALLOC_MODULE_PERFORM_GET_RGB_DATA_ADDRESS:
- {
- private_handle_t* hnd = va_arg(args, private_handle_t*);
- void** rgb_data = va_arg(args, void**);
- if (!private_handle_t::validate(hnd)) {
- res = getRgbDataAddress(hnd, rgb_data);
- }
- } break;
-
- case GRALLOC_MODULE_PERFORM_GET_IGC:
- {
- private_handle_t* hnd = va_arg(args, private_handle_t*);
- uint32_t *igc = va_arg(args, uint32_t *);
- if (!private_handle_t::validate(hnd) && igc) {
- MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
- if (metadata && (metadata->operation & SET_IGC)) {
- *igc = metadata->igc;
- res = 0;
- }
- }
- } break;
-
- case GRALLOC_MODULE_PERFORM_SET_IGC:
- res = 0;
- break;
-
- case GRALLOC_MODULE_PERFORM_SET_SINGLE_BUFFER_MODE:
- {
- private_handle_t* hnd = va_arg(args, private_handle_t*);
- uint32_t *enable = va_arg(args, uint32_t*);
- if (!private_handle_t::validate(hnd)) {
- setMetaData(hnd, SET_SINGLE_BUFFER_MODE, enable);
- res = 0;
- }
- } break;
- default:
- break;
- }
- va_end(args);
- return res;
-}
diff --git a/libgralloc/memalloc.h b/libgralloc/memalloc.h
deleted file mode 100644
index 598d983..0000000
--- a/libgralloc/memalloc.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
-
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- * * Neither the name of The Linux Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
- * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
- * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GRALLOC_MEMALLOC_H
-#define GRALLOC_MEMALLOC_H
-
-#include <stdlib.h>
-
-namespace gralloc {
-
-enum {
- CACHE_CLEAN = 0x1,
- CACHE_INVALIDATE,
- CACHE_CLEAN_AND_INVALIDATE,
-};
-
-struct alloc_data {
- void *base;
- int fd;
- unsigned int offset;
- unsigned int size;
- unsigned int align;
- uintptr_t pHandle;
- bool uncached;
- unsigned int flags;
- unsigned int heapId;
- int allocType;
-};
-
-class IMemAlloc {
-
- public:
- // Allocate buffer - fill in the alloc_data
- // structure and pass it in. Mapped address
- // and fd are returned in the alloc_data struct
- virtual int alloc_buffer(alloc_data& data) = 0;
-
- // Free buffer
- virtual int free_buffer(void *base, unsigned int size,
- unsigned int offset, int fd) = 0;
-
- // Map buffer
- virtual int map_buffer(void **pBase, unsigned int size,
- unsigned int offset, int fd) = 0;
-
- // Unmap buffer
- virtual int unmap_buffer(void *base, unsigned int size,
- unsigned int offset) = 0;
-
- // Clean and invalidate
- virtual int clean_buffer(void *base, unsigned int size,
- unsigned int offset, int fd, int op) = 0;
-
- // Destructor
- virtual ~IMemAlloc() {};
-
- enum {
- FD_INIT = -1,
- };
-
-};
-
-} // end gralloc namespace
-#endif // GRALLOC_MEMALLOC_H