Jorge E. Moreira | 9cf0f1f | 2017-08-10 15:55:21 -0700 | [diff] [blame] | 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> |
Jorge E. Moreira | 4b9bbb1 | 2017-12-28 15:49:06 -0800 | [diff] [blame] | 21 | #include <memory> |
Jorge E. Moreira | 9cf0f1f | 2017-08-10 15:55:21 -0700 | [diff] [blame] | 22 | #include <stdlib.h> |
| 23 | |
| 24 | namespace vsoc { |
| 25 | namespace gralloc { |
| 26 | |
Greg Hartman | d072a34 | 2017-12-05 20:27:40 -0800 | [diff] [blame] | 27 | class GrallocRegionView : public vsoc::ManagerRegionView< |
Ryan Haining | 59063a9 | 2018-02-08 17:32:22 -0800 | [diff] [blame^] | 28 | GrallocRegionView, |
Jorge E. Moreira | 9cf0f1f | 2017-08-10 15:55:21 -0700 | [diff] [blame] | 29 | vsoc::layout::gralloc::GrallocManagerLayout> { |
| 30 | public: |
Ryan Haining | 59063a9 | 2018-02-08 17:32:22 -0800 | [diff] [blame^] | 31 | friend TypedRegionView< |
| 32 | GrallocRegionView, vsoc::layout::gralloc::GrallocManagerLayout>; |
Jorge E. Moreira | 4b9bbb1 | 2017-12-28 15:49:06 -0800 | [diff] [blame] | 33 | GrallocRegionView() = default; |
Jorge E. Moreira | 9cf0f1f | 2017-08-10 15:55:21 -0700 | [diff] [blame] | 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 | |
Jorge E. Moreira | 9cf0f1f | 2017-08-10 15:55:21 -0700 | [diff] [blame] | 41 | protected: |
Greg Hartman | d072a34 | 2017-12-05 20:27:40 -0800 | [diff] [blame] | 42 | GrallocRegionView(const GrallocRegionView&) = delete; |
| 43 | GrallocRegionView & operator=(const GrallocRegionView&) = delete; |
Jorge E. Moreira | 9cf0f1f | 2017-08-10 15:55:21 -0700 | [diff] [blame] | 44 | |
Greg Hartman | 6da4302 | 2017-12-05 11:16:02 -0800 | [diff] [blame] | 45 | bool Open(); |
Jorge E. Moreira | 9cf0f1f | 2017-08-10 15:55:21 -0700 | [diff] [blame] | 46 | |
| 47 | vsoc_reg_off_t offset_of_buffer_memory_{}; |
| 48 | uint32_t total_buffer_memory_{}; |
Jorge E. Moreira | 9cf0f1f | 2017-08-10 15:55:21 -0700 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | } // namespace gralloc |
| 52 | } // namespace vsoc |