blob: 1d5d57ee07f1f6cfe7be8f990210535ff58c091c [file] [log] [blame]
Arun Kumar K.R2b75da32016-11-11 14:37:20 -08001/*
Sushil Chauhan1cc416f2017-01-11 18:09:02 -08002 * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
Arun Kumar K.R2b75da32016-11-11 14:37:20 -08003 * Not a Contribution.
4 *
5 * Copyright 2015 The Android Open Source Project
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20#include "EGLImageWrapper.h"
21#include <cutils/native_handle.h>
22#include <gralloc_priv.h>
23#include <ui/GraphicBuffer.h>
24
Arun Kumar K.R2b75da32016-11-11 14:37:20 -080025//-----------------------------------------------------------------------------
26EGLImageBuffer *EGLImageWrapper::wrap(const void *pvt_handle)
27//-----------------------------------------------------------------------------
28{
29 const private_handle_t *src = static_cast<const private_handle_t *>(pvt_handle);
30
31 EGLImageBuffer *result = 0;
32 std::map<int, EGLImageBuffer *>::iterator it = eglImageBufferMap.find(src->fd);
33 if (it == eglImageBufferMap.end()) {
34 native_handle_t *native_handle = const_cast<private_handle_t *>(src);
35
36 int flags = android::GraphicBuffer::USAGE_HW_TEXTURE |
37 android::GraphicBuffer::USAGE_SW_READ_NEVER |
38 android::GraphicBuffer::USAGE_SW_WRITE_NEVER;
39 if (src->flags & private_handle_t::PRIV_FLAGS_SECURE_BUFFER) {
40 flags |= android::GraphicBuffer::USAGE_PROTECTED;
41 }
42
43 android::sp<android::GraphicBuffer> graphicBuffer =
Naseer Ahmedfeaed062017-01-17 15:34:02 -050044 new android::GraphicBuffer(src->width, src->height, src->format,
45#ifndef __NOUGAT__
46 1, // Layer count
47#endif
48 flags, src->width /*src->stride*/,
49 native_handle, false);
Arun Kumar K.R2b75da32016-11-11 14:37:20 -080050
51 result = new EGLImageBuffer(graphicBuffer);
52
53 eglImageBufferMap[src->fd] = result;
54 } else {
55 result = it->second;
56 }
57
58 return result;
59}
60
61//-----------------------------------------------------------------------------
62void EGLImageWrapper::destroy()
63//-----------------------------------------------------------------------------
64{
65 std::map<int, EGLImageBuffer *>::iterator it = eglImageBufferMap.begin();
66 for (; it != eglImageBufferMap.end(); it++) {
67 delete it->second;
68 }
69 eglImageBufferMap.clear();
Sushil Chauhan1cc416f2017-01-11 18:09:02 -080070}