| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_COMMON_GPU_TEXTURE_IMAGE_TRANSPORT_SURFACE_H_ | 5 #ifndef CONTENT_COMMON_GPU_TEXTURE_IMAGE_TRANSPORT_SURFACE_H_ |
| 6 #define CONTENT_COMMON_GPU_TEXTURE_IMAGE_TRANSPORT_SURFACE_H_ | 6 #define CONTENT_COMMON_GPU_TEXTURE_IMAGE_TRANSPORT_SURFACE_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/weak_ptr.h" | |
| 10 #include "content/common/gpu/gpu_command_buffer_stub.h" | 9 #include "content/common/gpu/gpu_command_buffer_stub.h" |
| 11 #include "content/common/gpu/image_transport_surface.h" | 10 #include "content/common/gpu/image_transport_surface.h" |
| 11 #include "gpu/command_buffer/service/mailbox_manager.h" |
| 12 #include "gpu/command_buffer/service/texture_manager.h" | 12 #include "gpu/command_buffer/service/texture_manager.h" |
| 13 #include "ui/gl/gl_surface.h" | 13 #include "ui/gl/gl_surface.h" |
| 14 | 14 |
| 15 namespace content { | 15 namespace content { |
| 16 class GpuChannelManager; | 16 class GpuChannelManager; |
| 17 | 17 |
| 18 class TextureImageTransportSurface : | 18 class TextureImageTransportSurface : |
| 19 public ImageTransportSurface, | 19 public ImageTransportSurface, |
| 20 public GpuCommandBufferStub::DestructionObserver, | 20 public GpuCommandBufferStub::DestructionObserver, |
| 21 public gfx::GLSurface, | 21 public gfx::GLSurface { |
| 22 public base::SupportsWeakPtr<TextureImageTransportSurface> { | |
| 23 public: | 22 public: |
| 24 TextureImageTransportSurface(GpuChannelManager* manager, | 23 TextureImageTransportSurface(GpuChannelManager* manager, |
| 25 GpuCommandBufferStub* stub, | 24 GpuCommandBufferStub* stub, |
| 26 const gfx::GLSurfaceHandle& handle); | 25 const gfx::GLSurfaceHandle& handle); |
| 27 | 26 |
| 28 // gfx::GLSurface implementation. | 27 // gfx::GLSurface implementation. |
| 29 virtual bool Initialize() OVERRIDE; | 28 virtual bool Initialize() OVERRIDE; |
| 30 virtual void Destroy() OVERRIDE; | 29 virtual void Destroy() OVERRIDE; |
| 31 virtual bool DeferDraws() OVERRIDE; | 30 virtual bool DeferDraws() OVERRIDE; |
| 32 virtual bool Resize(const gfx::Size& size) OVERRIDE; | 31 virtual bool Resize(const gfx::Size& size) OVERRIDE; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 43 virtual void SetFrontbufferAllocation(bool allocated) OVERRIDE; | 42 virtual void SetFrontbufferAllocation(bool allocated) OVERRIDE; |
| 44 virtual void* GetShareHandle() OVERRIDE; | 43 virtual void* GetShareHandle() OVERRIDE; |
| 45 virtual void* GetDisplay() OVERRIDE; | 44 virtual void* GetDisplay() OVERRIDE; |
| 46 virtual void* GetConfig() OVERRIDE; | 45 virtual void* GetConfig() OVERRIDE; |
| 47 | 46 |
| 48 protected: | 47 protected: |
| 49 // ImageTransportSurface implementation. | 48 // ImageTransportSurface implementation. |
| 50 virtual void OnBufferPresented( | 49 virtual void OnBufferPresented( |
| 51 uint32 sync_point) OVERRIDE; | 50 uint32 sync_point) OVERRIDE; |
| 52 virtual void OnResizeViewACK() OVERRIDE; | 51 virtual void OnResizeViewACK() OVERRIDE; |
| 53 virtual void OnSetFrontSurfaceIsProtected( | |
| 54 bool is_protected, | |
| 55 uint32 protection_state_id) OVERRIDE; | |
| 56 virtual void OnResize(gfx::Size size) OVERRIDE; | 52 virtual void OnResize(gfx::Size size) OVERRIDE; |
| 57 | 53 |
| 58 // GpuCommandBufferStub::DestructionObserver implementation. | 54 // GpuCommandBufferStub::DestructionObserver implementation. |
| 59 virtual void OnWillDestroyStub(GpuCommandBufferStub* stub) OVERRIDE; | 55 virtual void OnWillDestroyStub(GpuCommandBufferStub* stub) OVERRIDE; |
| 60 | 56 |
| 61 private: | 57 private: |
| 62 // A texture backing the front/back buffer in the parent stub. | 58 // A texture backing the front/back buffer. |
| 63 struct Texture { | 59 struct Texture { |
| 64 Texture(); | 60 Texture(); |
| 65 ~Texture(); | 61 ~Texture(); |
| 66 | 62 |
| 67 // The client-side id in the parent stub. | |
| 68 uint32 client_id; | |
| 69 | |
| 70 // The currently allocated size. | 63 // The currently allocated size. |
| 71 gfx::Size size; | 64 gfx::Size size; |
| 72 | 65 |
| 73 // Whether or not that texture has been sent to the client yet. | 66 // The actual GL texture id. |
| 74 bool sent_to_client; | 67 uint32 service_id; |
| 75 | |
| 76 // The texture info in the parent stub. | |
| 77 gpu::gles2::TextureManager::TextureInfo::Ref info; | |
| 78 }; | 68 }; |
| 79 | 69 |
| 80 virtual ~TextureImageTransportSurface(); | 70 virtual ~TextureImageTransportSurface(); |
| 81 void CreateBackTexture(const gfx::Size& size); | 71 void CreateBackTexture(); |
| 82 void AttachBackTextureToFBO(); | 72 void AttachBackTextureToFBO(); |
| 83 void ReleaseTexture(int id); | 73 void ReleaseBackBuffer(); |
| 84 void ReleaseParentStub(); | |
| 85 void AdjustFrontBufferAllocation(); | 74 void AdjustFrontBufferAllocation(); |
| 86 void BufferPresentedImpl(); | 75 void BufferPresentedImpl(); |
| 87 int front() const { return front_; } | 76 void ProduceTexture(Texture& texture); |
| 88 int back() const { return 1 - front_; } | 77 void ConsumeTexture(Texture& texture); |
| 89 | 78 |
| 90 // The framebuffer that represents this surface (service id). Allocated lazily | 79 // The framebuffer that represents this surface (service id). Allocated lazily |
| 91 // in OnMakeCurrent. | 80 // in OnMakeCurrent. |
| 92 uint32 fbo_id_; | 81 uint32 fbo_id_; |
| 93 | 82 |
| 94 // The front and back buffers. | 83 // The current backbuffer |
| 95 Texture textures_[2]; | 84 Texture backbuffer_; |
| 85 |
| 86 gfx::Size current_size_; |
| 96 | 87 |
| 97 gfx::Rect previous_damage_rect_; | 88 gfx::Rect previous_damage_rect_; |
| 98 | 89 |
| 99 // Indicates which of the 2 above is the front buffer. | |
| 100 int front_; | |
| 101 | |
| 102 // Whether or not the command buffer stub has been destroyed. | 90 // Whether or not the command buffer stub has been destroyed. |
| 103 bool stub_destroyed_; | 91 bool stub_destroyed_; |
| 104 | 92 |
| 105 bool backbuffer_suggested_allocation_; | 93 bool backbuffer_suggested_allocation_; |
| 106 bool frontbuffer_suggested_allocation_; | 94 bool frontbuffer_suggested_allocation_; |
| 107 | 95 |
| 108 bool frontbuffer_is_protected_; | |
| 109 uint32 protection_state_id_; | |
| 110 | |
| 111 scoped_ptr<ImageTransportHelper> helper_; | 96 scoped_ptr<ImageTransportHelper> helper_; |
| 112 gfx::GLSurfaceHandle handle_; | 97 gfx::GLSurfaceHandle handle_; |
| 113 GpuCommandBufferStub* parent_stub_; | |
| 114 | 98 |
| 115 // The offscreen surface used to make the context current. However note that | 99 // The offscreen surface used to make the context current. However note that |
| 116 // the actual rendering is always redirected to an FBO. | 100 // the actual rendering is always redirected to an FBO. |
| 117 scoped_refptr<GLSurface> surface_; | 101 scoped_refptr<GLSurface> surface_; |
| 118 | 102 |
| 119 // Whether a SwapBuffers is pending. | 103 // Whether a SwapBuffers is pending. |
| 120 bool is_swap_buffers_pending_; | 104 bool is_swap_buffers_pending_; |
| 121 | 105 |
| 122 // Whether we unscheduled command buffer because of pending SwapBuffers. | 106 // Whether we unscheduled command buffer because of pending SwapBuffers. |
| 123 bool did_unschedule_; | 107 bool did_unschedule_; |
| 124 | 108 |
| 109 // The mailbox name used for texture exchange. |
| 110 gpu::gles2::MailboxName mailbox_name_; |
| 111 |
| 112 // Holds a reference to the mailbox manager for cleanup. |
| 113 scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_; |
| 114 |
| 125 DISALLOW_COPY_AND_ASSIGN(TextureImageTransportSurface); | 115 DISALLOW_COPY_AND_ASSIGN(TextureImageTransportSurface); |
| 126 }; | 116 }; |
| 127 | 117 |
| 128 } // namespace content | 118 } // namespace content |
| 129 | 119 |
| 130 #endif // CONTENT_COMMON_GPU_TEXTURE_IMAGE_TRANSPORT_SURFACE_H_ | 120 #endif // CONTENT_COMMON_GPU_TEXTURE_IMAGE_TRANSPORT_SURFACE_H_ |
| OLD | NEW |