Ejemplo n.º 1
0
        private async void HandleWindowSize()
        {
            var currentSize = ImGui.GetWindowContentRegionMax() - ImGui.GetWindowContentRegionMin();

            if (currentSize == size || resizing)
            {
                return;
            }

            // If there isn't a size yet, we haven't rendered at all - boot up an inlay in the render process
            // TODO: Edge case - if a user _somehow_ makes the size zero, this will freak out and generate a new render inlay
            // TODO: Maybe consolidate the request types? dunno.
            var request = size == Vector2.Zero
                                ? new NewInlayRequest()
            {
                Guid = RenderGuid,
                FrameTransportMode = config.FrameTransportMode,
                Url    = inlayConfig.Url,
                Width  = (int)currentSize.X,
                Height = (int)currentSize.Y,
            }
                                : new ResizeInlayRequest()
            {
                Guid   = RenderGuid,
                Width  = (int)currentSize.X,
                Height = (int)currentSize.Y,
            } as DownstreamIpcRequest;

            resizing = true;

            var response = await renderProcess.Send <FrameTransportResponse>(request);

            if (!response.Success)
            {
                PluginLog.LogError("Texture build failure, retrying...");
                resizing = false;
                return;
            }

            size     = currentSize;
            resizing = false;

            var oldTextureHandler = textureHandler;

            try
            {
                textureHandler = response.Data switch
                {
                    TextureHandleResponse textureHandleResponse => new SharedTextureHandler(textureHandleResponse),
                    BitmapBufferResponse bitmapBufferResponse => new BitmapBufferTextureHandler(bitmapBufferResponse),
                    _ => throw new Exception($"Unhandled frame transport {response.GetType().Name}"),
                };
            }
            catch (Exception e) { textureRenderException = e; }
            if (oldTextureHandler != null)
            {
                oldTextureHandler.Dispose();
            }
        }
Ejemplo n.º 2
0
        public void InvalidateTransport()
        {
            // Get old refs so we can clean up later
            var oldTextureHandler = textureHandler;
            var oldRenderGuid     = RenderGuid;

            // Invalidate the handler, and reset the size to trigger a rebuild
            // Also need to generate a new renderer guid so we don't have a collision during the hand over
            // TODO: Might be able to tweak the logic in resize alongside this to shore up (re)builds
            textureHandler = null;
            size           = Vector2.Zero;
            RenderGuid     = Guid.NewGuid();

            // Clean up
            oldTextureHandler.Dispose();
            renderProcess.Send(new RemoveInlayRequest()
            {
                Guid = oldRenderGuid
            });
        }
Ejemplo n.º 3
0
 public PaintBrush(ITextureHandler textureHandler, IGraphicsEngine graphicsEngine)
 {
     this.textureHandler = textureHandler;
     this.graphicsEngine = graphicsEngine;
 }