Arun Kumar K.R | 2b75da3 | 2016-11-11 14:37:20 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2016, The Linux Foundation. All rights reserved. |
| 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 | |
| 25 | std::map<int, EGLImageBuffer *> EGLImageWrapper::eglImageBufferMap; |
| 26 | |
| 27 | //----------------------------------------------------------------------------- |
| 28 | EGLImageBuffer *EGLImageWrapper::wrap(const void *pvt_handle) |
| 29 | //----------------------------------------------------------------------------- |
| 30 | { |
| 31 | const private_handle_t *src = static_cast<const private_handle_t *>(pvt_handle); |
| 32 | |
| 33 | EGLImageBuffer *result = 0; |
| 34 | std::map<int, EGLImageBuffer *>::iterator it = eglImageBufferMap.find(src->fd); |
| 35 | if (it == eglImageBufferMap.end()) { |
| 36 | native_handle_t *native_handle = const_cast<private_handle_t *>(src); |
| 37 | |
| 38 | int flags = android::GraphicBuffer::USAGE_HW_TEXTURE | |
| 39 | android::GraphicBuffer::USAGE_SW_READ_NEVER | |
| 40 | android::GraphicBuffer::USAGE_SW_WRITE_NEVER; |
| 41 | if (src->flags & private_handle_t::PRIV_FLAGS_SECURE_BUFFER) { |
| 42 | flags |= android::GraphicBuffer::USAGE_PROTECTED; |
| 43 | } |
| 44 | |
| 45 | android::sp<android::GraphicBuffer> graphicBuffer = |
| 46 | new android::GraphicBuffer(src->width, src->height, src->format, flags, |
| 47 | src->width /*src->stride*/, native_handle, false); |
| 48 | |
| 49 | result = new EGLImageBuffer(graphicBuffer); |
| 50 | |
| 51 | eglImageBufferMap[src->fd] = result; |
| 52 | } else { |
| 53 | result = it->second; |
| 54 | } |
| 55 | |
| 56 | return result; |
| 57 | } |
| 58 | |
| 59 | //----------------------------------------------------------------------------- |
| 60 | void EGLImageWrapper::destroy() |
| 61 | //----------------------------------------------------------------------------- |
| 62 | { |
| 63 | std::map<int, EGLImageBuffer *>::iterator it = eglImageBufferMap.begin(); |
| 64 | for (; it != eglImageBufferMap.end(); it++) { |
| 65 | delete it->second; |
| 66 | } |
| 67 | eglImageBufferMap.clear(); |
| 68 | } |