Example #1
0
        protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr buffer, int width, int height)
        {
            if (CreateTextureEvent != null)
            {
                lock (texturesLock)
                {
                    SharedTexture textureToRender;
                    if (textures.Count <= currentTextureIndex)
                    {
                        IntPtr sharedTextureHandle;
                        CreateTextureEvent((UInt32)width, (UInt32)height, out sharedTextureHandle);

                        if (sharedTextureHandle == IntPtr.Zero)
                        {
                            //texture has not been created yet, try again on the next paint
                            return;
                        }

                        // TODO : eventually switch to shared textures
                        //Texture texture = GraphicsSystem.Instance.CreateTextureFromSharedHandle((UInt32)width, (UInt32)height, sharedTextureHandle);

                        Texture texture = new Texture(sharedTextureHandle);

                        textureToRender = new SharedTexture
                        {
                            Texture = texture,
                            Handle  = sharedTextureHandle
                        };

                        textures.Add(textureToRender);
                    }
                    else
                    {
                        textureToRender = textures[currentTextureIndex];
                    }

                    textureToRender.Texture.SetImage(buffer, GSImageFormat.GS_IMAGEFORMAT_BGRA, (UInt32)(width * 4));

                    // loop the current texture index
                    currentTextureIndex = ++currentTextureIndex % textureCount;
                    PaintEvent(textureToRender.Handle);
                }
            }
        }
        protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr buffer, int width, int height)
        {
            if (CreateTextureEvent != null)
            {
                lock (texturesLock)
                {
                    SharedTexture textureToRender;
                    if (textures.Count <= currentTextureIndex)
                    {
                        IntPtr sharedTextureHandle;
                        CreateTextureEvent((UInt32)width, (UInt32)height, out sharedTextureHandle);

                        if (sharedTextureHandle == IntPtr.Zero)
                        {
                            API.Instance.Log("BrowserRenderHandler::OnPaint failed to create texture");
                            return;
                        }

                        // TODO : eventually switch to shared textures
                        //Texture texture = GraphicsSystem.Instance.CreateTextureFromSharedHandle((UInt32)width, (UInt32)height, sharedTextureHandle);

                        Texture texture = new Texture(sharedTextureHandle);

                        textureToRender = new SharedTexture
                        {
                            Texture = texture,
                            Handle = sharedTextureHandle
                        };

                        textures.Add(textureToRender);
                    }
                    else
                    {
                        textureToRender = textures[currentTextureIndex];
                    }

                    textureToRender.Texture.SetImage(buffer, GSImageFormat.GS_IMAGEFORMAT_BGRA, (UInt32)(width * 4));

                    // loop the current texture index
                    currentTextureIndex = ++currentTextureIndex % textureCount;
                    PaintEvent(textureToRender.Handle);
                }
            }
        }