blob: a32cff737291b1388e9373a2c1558768f6157439 [file] [log] [blame]
Jorge E. Moreira9cf0f1f2017-08-10 15:55:21 -07001#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. Moreira4b9bbb12017-12-28 15:49:06 -080021#include <memory>
Jorge E. Moreira9cf0f1f2017-08-10 15:55:21 -070022#include <stdlib.h>
23
24namespace vsoc {
25namespace gralloc {
26
Greg Hartmand072a342017-12-05 20:27:40 -080027class GrallocRegionView : public vsoc::ManagerRegionView<
Ryan Haining59063a92018-02-08 17:32:22 -080028 GrallocRegionView,
Jorge E. Moreira9cf0f1f2017-08-10 15:55:21 -070029 vsoc::layout::gralloc::GrallocManagerLayout> {
30 public:
Ryan Haining59063a92018-02-08 17:32:22 -080031 friend TypedRegionView<
32 GrallocRegionView, vsoc::layout::gralloc::GrallocManagerLayout>;
Jorge E. Moreira4b9bbb12017-12-28 15:49:06 -080033 GrallocRegionView() = default;
Jorge E. Moreira9cf0f1f2017-08-10 15:55:21 -070034 // 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. Moreira9cf0f1f2017-08-10 15:55:21 -070041 protected:
Greg Hartmand072a342017-12-05 20:27:40 -080042 GrallocRegionView(const GrallocRegionView&) = delete;
43 GrallocRegionView & operator=(const GrallocRegionView&) = delete;
Jorge E. Moreira9cf0f1f2017-08-10 15:55:21 -070044
Greg Hartman6da43022017-12-05 11:16:02 -080045 bool Open();
Jorge E. Moreira9cf0f1f2017-08-10 15:55:21 -070046
47 vsoc_reg_off_t offset_of_buffer_memory_{};
48 uint32_t total_buffer_memory_{};
Jorge E. Moreira9cf0f1f2017-08-10 15:55:21 -070049};
50
51} // namespace gralloc
52} // namespace vsoc