| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef SERVICES_UI_GLES2_GL_SURFACE_ADAPTER_H_ | |
| 6 #define SERVICES_UI_GLES2_GL_SURFACE_ADAPTER_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/callback.h" | |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #include "ui/gfx/swap_result.h" | |
| 15 #include "ui/gl/gl_surface.h" | |
| 16 | |
| 17 namespace ui { | |
| 18 | |
| 19 // Wraps a GLSurface such that there is a real GLSurface instance acting as | |
| 20 // delegate. Implements the GLSurface interface. The |gl::GLSurfaceAdapter| | |
| 21 // superclass provides a default implementation that forwards all GLSurface | |
| 22 // methods to the provided delegate. |GLSurfaceAdapterMus| overrides only the | |
| 23 // necessary methods to augment the completion callback argument to | |
| 24 // |SwapBuffersAsync|, |PostSubBufferAsync| and |CommitOverlayPlanesAsync| with | |
| 25 // a callback provided with the |SetGpuCompletedSwapBuffersCallback| method. | |
| 26 class GLSurfaceAdapterMus : public gl::GLSurfaceAdapter { | |
| 27 public: | |
| 28 // Creates a new |GLSurfaceAdapterMus| that delegates to |surface|. | |
| 29 explicit GLSurfaceAdapterMus(scoped_refptr<gl::GLSurface> surface); | |
| 30 | |
| 31 // gl::GLSurfaceAdapter. | |
| 32 void SwapBuffersAsync( | |
| 33 const gl::GLSurface::SwapCompletionCallback& callback) override; | |
| 34 void PostSubBufferAsync( | |
| 35 int x, | |
| 36 int y, | |
| 37 int width, | |
| 38 int height, | |
| 39 const gl::GLSurface::SwapCompletionCallback& callback) override; | |
| 40 void CommitOverlayPlanesAsync( | |
| 41 const gl::GLSurface::SwapCompletionCallback& callback) override; | |
| 42 | |
| 43 // Set an additional callback to run on SwapBuffers completion. | |
| 44 void SetGpuCompletedSwapBuffersCallback( | |
| 45 gl::GLSurface::SwapCompletionCallback callback); | |
| 46 | |
| 47 private: | |
| 48 ~GLSurfaceAdapterMus() override; | |
| 49 | |
| 50 // We wrap the callback given to the |gl::GLSurfaceAdapter| overrides above | |
| 51 // with an invocation of this function. It invokes |adapter_callback_| and the | |
| 52 // original |original_callback| provided by the original invoker of | |
| 53 // |SwapBuffersAsync| etc. | |
| 54 void WrappedCallbackForSwapBuffersAsync( | |
| 55 const gl::GLSurface::SwapCompletionCallback& original_callback, | |
| 56 gfx::SwapResult result); | |
| 57 | |
| 58 gl::GLSurface::SwapCompletionCallback adapter_callback_; | |
| 59 | |
| 60 // gl::GLSurfaceAdapter doesn't own the delegate surface so keep a reference | |
| 61 // here. | |
| 62 scoped_refptr<gl::GLSurface> surface_; | |
| 63 | |
| 64 base::WeakPtrFactory<GLSurfaceAdapterMus> weak_ptr_factory_; | |
| 65 | |
| 66 DISALLOW_COPY_AND_ASSIGN(GLSurfaceAdapterMus); | |
| 67 }; | |
| 68 | |
| 69 } // namespace ui | |
| 70 | |
| 71 #endif // SERVICES_UI_GLES2_GL_SURFACE_ADAPTER_H_ | |
| OLD | NEW |