blob: ad0a373b86f758700351cc6b1f5100498d4bf86a [file] [log] [blame]
Alistair Strachan71edaca2018-05-02 17:01:49 -07001/*
2 * Copyright (C) 2018 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#define LOG_TAG "hwc-platform-drm-minigbm"
18
Sean Paulf72cccd2018-08-27 13:59:08 -040019#include "platformminigbm.h"
Jorge E. Moreira5047b222018-09-19 15:34:07 -070020#include "drmdevice.h"
Alistair Strachan71edaca2018-05-02 17:01:49 -070021#include "platform.h"
Alistair Strachan71edaca2018-05-02 17:01:49 -070022
23#include <drm/drm_fourcc.h>
24#include <xf86drm.h>
25#include <xf86drmMode.h>
26
Alistair Strachan71edaca2018-05-02 17:01:49 -070027#include <hardware/gralloc.h>
Sean Paulf72cccd2018-08-27 13:59:08 -040028#include <log/log.h>
Alistair Strachan71edaca2018-05-02 17:01:49 -070029
30#include "cros_gralloc_handle.h"
31
32namespace android {
33
Jorge E. Moreira5047b222018-09-19 15:34:07 -070034Importer *Importer::CreateInstance(DrmDevice *drm) {
Alistair Strachan71edaca2018-05-02 17:01:49 -070035 DrmMinigbmImporter *importer = new DrmMinigbmImporter(drm);
36 if (!importer)
37 return NULL;
38
39 int ret = importer->Init();
40 if (ret) {
41 ALOGE("Failed to initialize the minigbm importer %d", ret);
42 delete importer;
43 return NULL;
44 }
45 return importer;
46}
47
Alistair Strachan71edaca2018-05-02 17:01:49 -070048int DrmMinigbmImporter::ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) {
49 cros_gralloc_handle *gr_handle = (cros_gralloc_handle *)handle;
50 if (!gr_handle)
51 return -EINVAL;
52
53 uint32_t gem_handle;
54 int ret = drmPrimeFDToHandle(drm_->fd(), gr_handle->fds[0], &gem_handle);
55 if (ret) {
56 ALOGE("failed to import prime fd %d ret=%d", gr_handle->fds[0], ret);
57 return ret;
58 }
59
60 memset(bo, 0, sizeof(hwc_drm_bo_t));
61 bo->width = gr_handle->width;
62 bo->height = gr_handle->height;
John Stultz616fb222018-08-24 16:08:57 -070063 bo->hal_format = gr_handle->droid_format;
Alistair Strachan71edaca2018-05-02 17:01:49 -070064 bo->format = gr_handle->format;
65 bo->usage = gr_handle->usage;
John Stultza4514832018-08-24 16:27:36 -070066 bo->pixel_stride = gr_handle->pixel_stride;
Alistair Strachan71edaca2018-05-02 17:01:49 -070067 bo->pitches[0] = gr_handle->strides[0];
68 bo->offsets[0] = gr_handle->offsets[0];
69 bo->gem_handles[0] = gem_handle;
70
71 ret = drmModeAddFB2(drm_->fd(), bo->width, bo->height, bo->format,
72 bo->gem_handles, bo->pitches, bo->offsets, &bo->fb_id, 0);
73 if (ret) {
74 ALOGE("could not create drm fb %d", ret);
75 return ret;
76 }
77
78 return ret;
79}
80
Jorge E. Moreira5047b222018-09-19 15:34:07 -070081std::unique_ptr<Planner> Planner::CreateInstance(DrmDevice *) {
Alistair Strachan71edaca2018-05-02 17:01:49 -070082 std::unique_ptr<Planner> planner(new Planner);
83 planner->AddStage<PlanStageGreedy>();
84 return planner;
85}
86
Sean Paulf72cccd2018-08-27 13:59:08 -040087} // namespace android