Alistair Strachan | 71edaca | 2018-05-02 17:01:49 -0700 | [diff] [blame] | 1 | /* |
| 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 Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 19 | #include "platformminigbm.h" |
Jorge E. Moreira | 5047b22 | 2018-09-19 15:34:07 -0700 | [diff] [blame] | 20 | #include "drmdevice.h" |
Alistair Strachan | 71edaca | 2018-05-02 17:01:49 -0700 | [diff] [blame] | 21 | #include "platform.h" |
Alistair Strachan | 71edaca | 2018-05-02 17:01:49 -0700 | [diff] [blame] | 22 | |
Alistair Strachan | 71edaca | 2018-05-02 17:01:49 -0700 | [diff] [blame] | 23 | #include <xf86drm.h> |
| 24 | #include <xf86drmMode.h> |
| 25 | |
Alistair Strachan | 71edaca | 2018-05-02 17:01:49 -0700 | [diff] [blame] | 26 | #include <hardware/gralloc.h> |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 27 | #include <log/log.h> |
Alistair Strachan | 71edaca | 2018-05-02 17:01:49 -0700 | [diff] [blame] | 28 | |
| 29 | #include "cros_gralloc_handle.h" |
| 30 | |
| 31 | namespace android { |
| 32 | |
Jorge E. Moreira | 5047b22 | 2018-09-19 15:34:07 -0700 | [diff] [blame] | 33 | Importer *Importer::CreateInstance(DrmDevice *drm) { |
Alistair Strachan | 71edaca | 2018-05-02 17:01:49 -0700 | [diff] [blame] | 34 | DrmMinigbmImporter *importer = new DrmMinigbmImporter(drm); |
| 35 | if (!importer) |
| 36 | return NULL; |
| 37 | |
| 38 | int ret = importer->Init(); |
| 39 | if (ret) { |
| 40 | ALOGE("Failed to initialize the minigbm importer %d", ret); |
| 41 | delete importer; |
| 42 | return NULL; |
| 43 | } |
| 44 | return importer; |
| 45 | } |
| 46 | |
Alistair Strachan | 71edaca | 2018-05-02 17:01:49 -0700 | [diff] [blame] | 47 | int DrmMinigbmImporter::ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) { |
| 48 | cros_gralloc_handle *gr_handle = (cros_gralloc_handle *)handle; |
| 49 | if (!gr_handle) |
| 50 | return -EINVAL; |
| 51 | |
| 52 | uint32_t gem_handle; |
| 53 | int ret = drmPrimeFDToHandle(drm_->fd(), gr_handle->fds[0], &gem_handle); |
| 54 | if (ret) { |
| 55 | ALOGE("failed to import prime fd %d ret=%d", gr_handle->fds[0], ret); |
| 56 | return ret; |
| 57 | } |
| 58 | |
| 59 | memset(bo, 0, sizeof(hwc_drm_bo_t)); |
| 60 | bo->width = gr_handle->width; |
| 61 | bo->height = gr_handle->height; |
John Stultz | 616fb22 | 2018-08-24 16:08:57 -0700 | [diff] [blame] | 62 | bo->hal_format = gr_handle->droid_format; |
Alistair Strachan | 71edaca | 2018-05-02 17:01:49 -0700 | [diff] [blame] | 63 | bo->format = gr_handle->format; |
| 64 | bo->usage = gr_handle->usage; |
John Stultz | a451483 | 2018-08-24 16:27:36 -0700 | [diff] [blame] | 65 | bo->pixel_stride = gr_handle->pixel_stride; |
Alistair Strachan | 71edaca | 2018-05-02 17:01:49 -0700 | [diff] [blame] | 66 | bo->pitches[0] = gr_handle->strides[0]; |
| 67 | bo->offsets[0] = gr_handle->offsets[0]; |
| 68 | bo->gem_handles[0] = gem_handle; |
| 69 | |
| 70 | ret = drmModeAddFB2(drm_->fd(), bo->width, bo->height, bo->format, |
| 71 | bo->gem_handles, bo->pitches, bo->offsets, &bo->fb_id, 0); |
| 72 | if (ret) { |
| 73 | ALOGE("could not create drm fb %d", ret); |
| 74 | return ret; |
| 75 | } |
| 76 | |
Vincent Donnefort | f67c365 | 2019-08-02 11:18:35 +0100 | [diff] [blame] | 77 | ImportHandle(gem_handle); |
| 78 | |
Alistair Strachan | 71edaca | 2018-05-02 17:01:49 -0700 | [diff] [blame] | 79 | return ret; |
| 80 | } |
| 81 | |
Jorge E. Moreira | 5047b22 | 2018-09-19 15:34:07 -0700 | [diff] [blame] | 82 | std::unique_ptr<Planner> Planner::CreateInstance(DrmDevice *) { |
Alistair Strachan | 71edaca | 2018-05-02 17:01:49 -0700 | [diff] [blame] | 83 | std::unique_ptr<Planner> planner(new Planner); |
| 84 | planner->AddStage<PlanStageGreedy>(); |
| 85 | return planner; |
| 86 | } |
| 87 | |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 88 | } // namespace android |