1 #pragma once 2 3 /* 4 * Copyright (C) 2017 The Android Open Source Project 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 #include <common/vsoc/shm/gralloc_layout.h> 20 #include <guest/vsoc/lib/manager_region_view.h> 21 #include <memory> 22 #include <stdlib.h> 23 24 namespace vsoc { 25 namespace gralloc { 26 27 class GrallocRegionView : public vsoc::ManagerRegionView< 28 GrallocRegionView, 29 vsoc::layout::gralloc::GrallocManagerLayout> { 30 public: 31 friend TypedRegionView< 32 GrallocRegionView, vsoc::layout::gralloc::GrallocManagerLayout>; 33 GrallocRegionView() = default; 34 // Allocates a gralloc buffer of (at least) the specified size. Returns a file 35 // descriptor that exposes the buffer when mmapped from 0 to (the page 36 // aligned) size (and fails to mmap anything outside of that range) or a 37 // negative number in case of error (e.g not enough free memory left). 38 // TODO(jemoreira): Include debug info like stride, width, height, etc 39 int AllocateBuffer(size_t size, uint32_t* begin_offset = nullptr); 40 41 protected: 42 GrallocRegionView(const GrallocRegionView&) = delete; 43 GrallocRegionView & operator=(const GrallocRegionView&) = delete; 44 45 bool Open(); 46 47 uint32_t offset_of_buffer_memory_{}; 48 uint32_t total_buffer_memory_{}; 49 }; 50 51 } // namespace gralloc 52 } // namespace vsoc 53