// // Created by loki on 4/23/20. // #ifndef SUNSHINE_DISPLAY_H #define SUNSHINE_DISPLAY_H #include #include #include #include #include #include "sunshine/platform/common.h" #include "sunshine/utility.h" namespace platf::dxgi { extern const char *format_str[]; template void Release(T *dxgi) { dxgi->Release(); } using factory1_t = util::safe_ptr>; using dxgi_t = util::safe_ptr>; using dxgi1_t = util::safe_ptr>; using device_t = util::safe_ptr>; using device_ctx_t = util::safe_ptr>; using adapter_t = util::safe_ptr>; using output_t = util::safe_ptr>; using output1_t = util::safe_ptr>; using dup_t = util::safe_ptr>; using texture2d_t = util::safe_ptr>; using texture1d_t = util::safe_ptr>; using resource_t = util::safe_ptr>; using multithread_t = util::safe_ptr>; using vs_t = util::safe_ptr>; using ps_t = util::safe_ptr>; using blend_t = util::safe_ptr>; using input_layout_t = util::safe_ptr>; using render_target_t = util::safe_ptr>; using shader_res_t = util::safe_ptr>; using buf_t = util::safe_ptr>; using raster_state_t = util::safe_ptr>; using sampler_state_t = util::safe_ptr>; using blob_t = util::safe_ptr>; using depth_stencil_state_t = util::safe_ptr>; using depth_stencil_view_t = util::safe_ptr>; namespace video { using device_t = util::safe_ptr>; using ctx_t = util::safe_ptr>; using processor_t = util::safe_ptr>; using processor_out_t = util::safe_ptr>; using processor_in_t = util::safe_ptr>; using processor_enum_t = util::safe_ptr>; } // namespace video class hwdevice_t; struct cursor_t { std::vector img_data; DXGI_OUTDUPL_POINTER_SHAPE_INFO shape_info; int x, y; bool visible; }; class gpu_cursor_t { public: gpu_cursor_t() : cursor_view { 0, 0, 0, 0, 0.0f, 1.0f } {}; void set_pos(LONG rel_x, LONG rel_y, bool visible) { cursor_view.TopLeftX = rel_x; cursor_view.TopLeftY = rel_y; this->visible = visible; } void set_texture(LONG width, LONG height, texture2d_t &&texture) { cursor_view.Width = width; cursor_view.Height = height; this->texture = std::move(texture); } texture2d_t texture; shader_res_t input_res; D3D11_VIEWPORT cursor_view; bool visible; }; class duplication_t { public: dup_t dup; bool has_frame {}; capture_e next_frame(DXGI_OUTDUPL_FRAME_INFO &frame_info, std::chrono::milliseconds timeout, resource_t::pointer *res_p); capture_e reset(dup_t::pointer dup_p = dup_t::pointer()); capture_e release_frame(); ~duplication_t(); }; class display_base_t : public display_t { public: int init(int framerate, const std::string &display_name); std::chrono::nanoseconds delay; factory1_t factory; adapter_t adapter; output_t output; device_t device; device_ctx_t device_ctx; duplication_t dup; DXGI_FORMAT format; D3D_FEATURE_LEVEL feature_level; typedef enum _D3DKMT_SCHEDULINGPRIORITYCLASS { D3DKMT_SCHEDULINGPRIORITYCLASS_IDLE, D3DKMT_SCHEDULINGPRIORITYCLASS_BELOW_NORMAL, D3DKMT_SCHEDULINGPRIORITYCLASS_NORMAL, D3DKMT_SCHEDULINGPRIORITYCLASS_ABOVE_NORMAL, D3DKMT_SCHEDULINGPRIORITYCLASS_HIGH, D3DKMT_SCHEDULINGPRIORITYCLASS_REALTIME } D3DKMT_SCHEDULINGPRIORITYCLASS; typedef NTSTATUS WINAPI (*PD3DKMTSetProcessSchedulingPriorityClass)(HANDLE, D3DKMT_SCHEDULINGPRIORITYCLASS); }; class display_ram_t : public display_base_t { public: capture_e capture(snapshot_cb_t &&snapshot_cb, std::shared_ptr img, bool *cursor) override; capture_e snapshot(img_t *img, std::chrono::milliseconds timeout, bool cursor_visible); std::shared_ptr alloc_img() override; int dummy_img(img_t *img) override; int init(int framerate, const std::string &display_name); cursor_t cursor; D3D11_MAPPED_SUBRESOURCE img_info; texture2d_t texture; }; class display_vram_t : public display_base_t, public std::enable_shared_from_this { public: capture_e capture(snapshot_cb_t &&snapshot_cb, std::shared_ptr img, bool *cursor) override; capture_e snapshot(img_t *img, std::chrono::milliseconds timeout, bool cursor_visible); std::shared_ptr alloc_img() override; int dummy_img(img_t *img_base) override; int init(int framerate, const std::string &display_name); std::shared_ptr make_hwdevice(pix_fmt_e pix_fmt) override; sampler_state_t sampler_linear; blend_t blend_enable; blend_t blend_disable; ps_t scene_ps; vs_t scene_vs; texture2d_t src; gpu_cursor_t cursor; }; } // namespace platf::dxgi #endif