Arun Kumar K.R | 2b75da3 | 2016-11-11 14:37:20 -0800 | [diff] [blame] | 1 | /* |
Sushil Chauhan | 1cc416f | 2017-01-11 18:09:02 -0800 | [diff] [blame] | 2 | * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. |
Arun Kumar K.R | 2b75da3 | 2016-11-11 14:37:20 -0800 | [diff] [blame] | 3 | * 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.R | 2b75da3 | 2016-11-11 14:37:20 -0800 | [diff] [blame] | 25 | //----------------------------------------------------------------------------- |
| 26 | EGLImageBuffer *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 = |
| 44 | new android::GraphicBuffer(src->width, src->height, src->format, flags, |
| 45 | src->width /*src->stride*/, native_handle, false); |
| 46 | |
| 47 | result = new EGLImageBuffer(graphicBuffer); |
| 48 | |
| 49 | eglImageBufferMap[src->fd] = result; |
| 50 | } else { |
| 51 | result = it->second; |
| 52 | } |
| 53 | |
| 54 | return result; |
| 55 | } |
| 56 | |
| 57 | //----------------------------------------------------------------------------- |
| 58 | void EGLImageWrapper::destroy() |
| 59 | //----------------------------------------------------------------------------- |
| 60 | { |
| 61 | std::map<int, EGLImageBuffer *>::iterator it = eglImageBufferMap.begin(); |
| 62 | for (; it != eglImageBufferMap.end(); it++) { |
| 63 | delete it->second; |
| 64 | } |
| 65 | eglImageBufferMap.clear(); |
Sushil Chauhan | 1cc416f | 2017-01-11 18:09:02 -0800 | [diff] [blame] | 66 | } |