1 /* 2 * Copyright 2011 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 SYSTEM_HALS_CB_HANDLE_30_H 18 #define SYSTEM_HALS_CB_HANDLE_30_H 19 20 #include <gralloc_cb_bp.h> 21 #include "goldfish_address_space.h" 22 23 const uint32_t CB_HANDLE_MAGIC_30 = CB_HANDLE_MAGIC_BASE | 0x2; 24 25 struct cb_handle_30_t : public cb_handle_t { cb_handle_30_tcb_handle_30_t26 cb_handle_30_t(address_space_handle_t p_bufferFd, 27 QEMU_PIPE_HANDLE p_hostHandleRefCountFd, 28 uint32_t p_hostHandle, 29 int32_t p_usage, 30 int32_t p_width, 31 int32_t p_height, 32 int32_t p_format, 33 int32_t p_glFormat, 34 int32_t p_glType, 35 uint32_t p_bufSize, 36 void* p_bufPtr, 37 uint32_t p_mmapedSize, 38 uint64_t p_mmapedOffset, 39 uint32_t p_bytesPerPixel, 40 uint32_t p_stride) 41 : cb_handle_t(p_bufferFd, 42 p_hostHandleRefCountFd, 43 CB_HANDLE_MAGIC_30, 44 p_hostHandle, 45 p_usage, 46 p_width, 47 p_height, 48 p_format, 49 p_glFormat, 50 p_glType, 51 p_bufSize, 52 p_bufPtr, 53 p_mmapedOffset), 54 mmapedSize(p_mmapedSize), 55 bytesPerPixel(p_bytesPerPixel), 56 stride(p_stride) { 57 numInts = CB_HANDLE_NUM_INTS(numFds); 58 } 59 isValidcb_handle_30_t60 bool isValid() const { return (version == sizeof(native_handle_t)) && (magic == CB_HANDLE_MAGIC_30); } 61 fromcb_handle_30_t62 static cb_handle_30_t* from(void* p) { 63 if (!p) { return nullptr; } 64 cb_handle_30_t* cb = static_cast<cb_handle_30_t*>(p); 65 return cb->isValid() ? cb : nullptr; 66 } 67 fromcb_handle_30_t68 static const cb_handle_30_t* from(const void* p) { 69 return from(const_cast<void*>(p)); 70 } 71 from_unconstcb_handle_30_t72 static cb_handle_30_t* from_unconst(const void* p) { 73 return from(const_cast<void*>(p)); 74 } 75 76 uint32_t mmapedSize; // real allocation side 77 uint32_t bytesPerPixel; 78 uint32_t stride; 79 }; 80 81 #endif // SYSTEM_HALS_CB_HANDLE_30_H 82