1 // Copyright (C) 2023 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License") override; 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma once 16 17 #include "Decoder.h" 18 #include "MonotonicMap.h" 19 #include "DrmDevice.h" 20 #include "Connection.h" 21 22 namespace gfxstream { 23 namespace magma { 24 25 // Magma decoder for running on an Intel DRM backend. 26 class IntelDrmDecoder : public Decoder { 27 public: 28 static std::unique_ptr<IntelDrmDecoder> create(uint32_t context_id); 29 30 private: 31 IntelDrmDecoder(); 32 magma_status_t magma_device_import(magma_handle_t device_channel, magma_device_t* device_out) override; 33 void magma_device_release(magma_device_t device) override; 34 magma_status_t magma_device_query_fudge(magma_device_t device, uint64_t id, magma_bool_t host_allocate, uint64_t* result_buffer_mapping_id_inout, uint64_t* result_buffer_size_inout, uint64_t* result_out) override; 35 magma_status_t magma_device_create_connection(magma_device_t device, magma_connection_t* connection_out) override; 36 void magma_connection_release(magma_connection_t connection) override; 37 magma_status_t magma_connection_create_buffer(magma_connection_t connection, uint64_t size, uint64_t* size_out, magma_buffer_t* buffer_out, magma_buffer_id_t* id_out) override; 38 void magma_connection_release_buffer(magma_connection_t connection, magma_buffer_t buffer) override; 39 magma_status_t magma_connection_create_semaphore(magma_connection_t magma_connection, magma_semaphore_t* semaphore_out, magma_semaphore_id_t* id_out) override; 40 void magma_connection_release_semaphore(magma_connection_t connection, magma_semaphore_t semaphore) override; 41 magma_status_t magma_buffer_get_info(magma_buffer_t buffer, magma_buffer_info_t* info_out) override; 42 magma_status_t magma_buffer_get_handle(magma_buffer_t buffer, magma_handle_t* handle_out) override; 43 magma_status_t magma_buffer_export(magma_buffer_t buffer, magma_handle_t* buffer_handle_out) override; 44 void magma_semaphore_signal(magma_semaphore_t semaphore) override; 45 void magma_semaphore_reset(magma_semaphore_t semaphore) override; 46 magma_status_t magma_poll(magma_poll_item_t* items, uint32_t count, uint64_t timeout_ns) override; 47 magma_status_t magma_connection_get_error(magma_connection_t connection) override; 48 magma_status_t magma_connection_create_context(magma_connection_t connection, uint32_t* context_id_out) override; 49 void magma_connection_release_context(magma_connection_t connection, uint32_t context_id) override; 50 magma_status_t magma_connection_map_buffer(magma_connection_t connection, uint64_t hw_va, magma_buffer_t buffer, uint64_t offset, uint64_t length, uint64_t map_flags) override; 51 void magma_connection_unmap_buffer(magma_connection_t connection, uint64_t hw_va, magma_buffer_t buffer) override; 52 53 uint32_t mContextId; 54 MonotonicMap<magma_device_t, DrmDevice> mDevices; 55 MonotonicMap<magma_buffer_t, DrmBuffer> mBuffers; 56 MonotonicMap<magma_connection_t, Connection> mConnections; 57 58 // Maps GEM handles to Buffers. 59 std::unordered_map<uint32_t, magma_buffer_t> mGemHandleToBuffer; 60 }; 61 62 } // namespace magma 63 } // namespace gfxstream 64