|
30 | 30 |
|
31 | 31 | #import "display_server_embedded.h" |
32 | 32 |
|
33 | | -#import "embedded_debugger.h" |
34 | | -#import "macos_quartz_core_spi.h" |
35 | | - |
36 | | -#import "core/config/project_settings.h" |
37 | | -#import "core/debugger/engine_debugger.h" |
38 | | - |
39 | 33 | #if defined(GLES3_ENABLED) |
40 | | -#include "drivers/gles3/rasterizer_gles3.h" |
| 34 | +#import "embedded_gl_manager.h" |
| 35 | +#import "platform_gl.h" |
| 36 | + |
| 37 | +#import "drivers/gles3/rasterizer_gles3.h" |
41 | 38 | #endif |
42 | 39 |
|
43 | 40 | #if defined(RD_ENABLED) |
44 | 41 | #import "servers/rendering/renderer_rd/renderer_compositor_rd.h" |
| 42 | +#import "servers/rendering/rendering_device.h" |
| 43 | + |
| 44 | +#if defined(VULKAN_ENABLED) |
| 45 | +#import "rendering_context_driver_vulkan_macos.h" |
| 46 | +#endif // VULKAN_ENABLED |
| 47 | +#if defined(METAL_ENABLED) |
| 48 | +#import "drivers/metal/rendering_context_driver_metal.h" |
45 | 49 | #endif |
| 50 | +#endif // RD_ENABLED |
| 51 | + |
| 52 | +#import "embedded_debugger.h" |
| 53 | +#import "macos_quartz_core_spi.h" |
| 54 | + |
| 55 | +#import "core/config/project_settings.h" |
| 56 | +#import "core/debugger/engine_debugger.h" |
| 57 | +#import "core/io/marshalls.h" |
46 | 58 |
|
47 | 59 | DisplayServerEmbedded::DisplayServerEmbedded(const String &p_rendering_driver, WindowMode p_mode, DisplayServer::VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i *p_position, const Vector2i &p_resolution, int p_screen, Context p_context, Error &r_error) { |
48 | 60 | EmbeddedDebugger::initialize(this); |
|
176 | 188 | } |
177 | 189 | #endif |
178 | 190 |
|
179 | | - constexpr CGFloat CONTENT_SCALE = 2.0; |
180 | | - layer.contentsScale = CONTENT_SCALE; |
| 191 | + CGFloat scale = screen_get_max_scale(); |
| 192 | + layer.contentsScale = scale; |
181 | 193 | layer.magnificationFilter = kCAFilterNearest; |
182 | 194 | layer.minificationFilter = kCAFilterNearest; |
183 | | - layer.opaque = NO; // Never opaque when embedded. |
| 195 | + layer.opaque = YES; // Always opaque when embedded. |
184 | 196 | layer.actions = @{ @"contents" : [NSNull null] }; // Disable implicit animations for contents. |
185 | 197 | // AppKit frames, bounds and positions are always in points. |
186 | 198 | CGRect bounds = CGRectMake(0, 0, p_resolution.width, p_resolution.height); |
187 | | - bounds = CGRectApplyAffineTransform(bounds, CGAffineTransformMakeScale(1.0 / CONTENT_SCALE, 1.0 / CONTENT_SCALE)); |
| 199 | + bounds = CGRectApplyAffineTransform(bounds, CGAffineTransformInvert(CGAffineTransformMakeScale(scale, scale))); |
188 | 200 | layer.bounds = bounds; |
189 | 201 |
|
190 | 202 | CGSConnectionID connection_id = CGSMainConnectionID(); |
|
582 | 594 | [CATransaction begin]; |
583 | 595 | [CATransaction setDisableActions:YES]; |
584 | 596 |
|
585 | | - // TODO(sgc): Pass scale as argument from parent process. |
586 | | - constexpr CGFloat CONTENT_SCALE = 2.0; |
| 597 | + CGFloat scale = screen_get_max_scale(); |
587 | 598 | CGRect bounds = CGRectMake(0, 0, p_size.width, p_size.height); |
588 | | - bounds = CGRectApplyAffineTransform(bounds, CGAffineTransformMakeScale(1.0 / CONTENT_SCALE, 1.0 / CONTENT_SCALE)); |
| 599 | + bounds = CGRectApplyAffineTransform(bounds, CGAffineTransformInvert(CGAffineTransformMakeScale(scale, scale))); |
589 | 600 | layer.bounds = bounds; |
| 601 | + layer.contentsScale = scale; |
590 | 602 |
|
591 | 603 | #if defined(RD_ENABLED) |
592 | 604 | if (rendering_context) { |
|
685 | 697 | ime_last_position = p_pos; |
686 | 698 | } |
687 | 699 |
|
688 | | -void DisplayServerEmbedded::update_state(const Dictionary &p_state) { |
689 | | - state.screen_max_scale = p_state["screen_get_max_scale"]; |
690 | | -} |
691 | | - |
692 | | -void DisplayServerEmbedded::set_content_scale(float p_scale) { |
693 | | - content_scale = p_scale; |
| 700 | +void DisplayServerEmbedded::set_state(const DisplayServerEmbeddedState &p_state) { |
| 701 | + state = p_state; |
694 | 702 | } |
695 | 703 |
|
696 | 704 | void DisplayServerEmbedded::window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mode, WindowID p_window) { |
|
742 | 750 | } |
743 | 751 | #endif |
744 | 752 | } |
| 753 | + |
| 754 | +void DisplayServerEmbeddedState::serialize(PackedByteArray &r_data) { |
| 755 | + r_data.resize(8); |
| 756 | + |
| 757 | + uint8_t *data = r_data.ptrw(); |
| 758 | + data += encode_float(screen_max_scale, data); |
| 759 | + data += encode_float(screen_dpi, data); |
| 760 | + |
| 761 | + // Assert we had enough space. |
| 762 | + DEV_ASSERT(data - r_data.ptrw() >= r_data.size()); |
| 763 | +} |
| 764 | + |
| 765 | +Error DisplayServerEmbeddedState::deserialize(const PackedByteArray &p_data) { |
| 766 | + const uint8_t *data = p_data.ptr(); |
| 767 | + |
| 768 | + screen_max_scale = decode_float(data); |
| 769 | + data += sizeof(float); |
| 770 | + screen_dpi = decode_float(data); |
| 771 | + |
| 772 | + return OK; |
| 773 | +} |
0 commit comments