Chromium Code Reviews| 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 <map> | |
| 9 | |
| 8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 9 #include "base/memory/weak_ptr.h" | |
| 10 #include "content/common/gpu/gpu_command_buffer_stub.h" | 11 #include "content/common/gpu/gpu_command_buffer_stub.h" |
| 11 #include "content/common/gpu/image_transport_surface.h" | 12 #include "content/common/gpu/image_transport_surface.h" |
| 13 #include "gpu/command_buffer/service/mailbox_manager.h" | |
| 12 #include "gpu/command_buffer/service/texture_manager.h" | 14 #include "gpu/command_buffer/service/texture_manager.h" |
| 13 #include "ui/gl/gl_surface.h" | 15 #include "ui/gl/gl_surface.h" |
| 14 | 16 |
| 15 namespace content { | 17 namespace content { |
| 16 class GpuChannelManager; | 18 class GpuChannelManager; |
| 17 | 19 |
| 18 class TextureImageTransportSurface : | 20 class TextureImageTransportSurface : |
| 19 public ImageTransportSurface, | 21 public ImageTransportSurface, |
| 20 public GpuCommandBufferStub::DestructionObserver, | 22 public GpuCommandBufferStub::DestructionObserver, |
| 21 public gfx::GLSurface, | 23 public gfx::GLSurface { |
| 22 public base::SupportsWeakPtr<TextureImageTransportSurface> { | |
|
jonathan.backer
2012/11/12 16:52:15
Why can we lose this?
no sievers
2012/11/19 20:30:44
It was only needed to post the BufferPresentedImpl
| |
| 23 public: | 24 public: |
| 24 TextureImageTransportSurface(GpuChannelManager* manager, | 25 TextureImageTransportSurface(GpuChannelManager* manager, |
| 25 GpuCommandBufferStub* stub, | 26 GpuCommandBufferStub* stub, |
| 26 const gfx::GLSurfaceHandle& handle); | 27 const gfx::GLSurfaceHandle& handle); |
| 27 | 28 |
| 28 // gfx::GLSurface implementation. | 29 // gfx::GLSurface implementation. |
| 29 virtual bool Initialize() OVERRIDE; | 30 virtual bool Initialize() OVERRIDE; |
| 30 virtual void Destroy() OVERRIDE; | 31 virtual void Destroy() OVERRIDE; |
| 31 virtual bool DeferDraws() OVERRIDE; | 32 virtual bool DeferDraws() OVERRIDE; |
| 32 virtual bool Resize(const gfx::Size& size) OVERRIDE; | 33 virtual bool Resize(const gfx::Size& size) OVERRIDE; |
| 33 virtual bool IsOffscreen() OVERRIDE; | 34 virtual bool IsOffscreen() OVERRIDE; |
| 34 virtual bool SwapBuffers() OVERRIDE; | 35 virtual bool SwapBuffers() OVERRIDE; |
| 35 virtual gfx::Size GetSize() OVERRIDE; | 36 virtual gfx::Size GetSize() OVERRIDE; |
| 36 virtual void* GetHandle() OVERRIDE; | 37 virtual void* GetHandle() OVERRIDE; |
| 37 virtual unsigned GetFormat() OVERRIDE; | 38 virtual unsigned GetFormat() OVERRIDE; |
| 38 virtual std::string GetExtensions() OVERRIDE; | 39 virtual std::string GetExtensions() OVERRIDE; |
| 39 virtual unsigned int GetBackingFrameBufferObject() OVERRIDE; | 40 virtual unsigned int GetBackingFrameBufferObject() OVERRIDE; |
| 40 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; | 41 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; |
| 41 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; | 42 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; |
| 42 virtual void SetBackbufferAllocation(bool allocated) OVERRIDE; | 43 virtual void SetBackbufferAllocation(bool allocated) OVERRIDE; |
| 43 virtual void SetFrontbufferAllocation(bool allocated) OVERRIDE; | 44 virtual void SetFrontbufferAllocation(bool allocated) OVERRIDE; |
| 44 virtual void* GetShareHandle() OVERRIDE; | 45 virtual void* GetShareHandle() OVERRIDE; |
| 45 virtual void* GetDisplay() OVERRIDE; | 46 virtual void* GetDisplay() OVERRIDE; |
| 46 virtual void* GetConfig() OVERRIDE; | 47 virtual void* GetConfig() OVERRIDE; |
| 47 | 48 |
| 48 protected: | 49 protected: |
| 49 // ImageTransportSurface implementation. | 50 // ImageTransportSurface implementation. |
| 50 virtual void OnBufferPresented( | 51 virtual void OnBufferPresented( |
| 51 bool presented, | 52 uint64 surface_handle, |
| 52 uint32 sync_point) OVERRIDE; | 53 uint32 sync_point) OVERRIDE; |
| 53 virtual void OnResizeViewACK() OVERRIDE; | 54 virtual void OnResizeViewACK() OVERRIDE; |
| 54 virtual void OnSetFrontSurfaceIsProtected( | |
| 55 bool is_protected, | |
| 56 uint32 protection_state_id) OVERRIDE; | |
| 57 virtual void OnResize(gfx::Size size) OVERRIDE; | 55 virtual void OnResize(gfx::Size size) OVERRIDE; |
| 58 | 56 |
| 59 // GpuCommandBufferStub::DestructionObserver implementation. | 57 // GpuCommandBufferStub::DestructionObserver implementation. |
| 60 virtual void OnWillDestroyStub(GpuCommandBufferStub* stub) OVERRIDE; | 58 virtual void OnWillDestroyStub(GpuCommandBufferStub* stub) OVERRIDE; |
| 61 | 59 |
| 62 private: | 60 private: |
| 63 // A texture backing the front/back buffer in the parent stub. | 61 // A texture backing the front/back buffer. |
| 64 struct Texture { | 62 struct Texture { |
|
jonathan.backer
2012/11/12 16:52:15
nit: We only ever have one instance of this class.
| |
| 65 Texture(); | 63 Texture(); |
| 66 ~Texture(); | 64 ~Texture(); |
| 67 | 65 |
| 68 // The client-side id in the parent stub. | |
| 69 uint32 client_id; | |
| 70 | |
| 71 // The currently allocated size. | 66 // The currently allocated size. |
| 72 gfx::Size size; | 67 gfx::Size size; |
| 73 | 68 |
| 74 // Whether or not that texture has been sent to the client yet. | 69 // The actual GL texture id. |
| 75 bool sent_to_client; | 70 uint32 service_id; |
| 76 | 71 |
| 77 // The texture info in the parent stub. | 72 // The surface identifier for this texture. |
| 78 gpu::gles2::TextureManager::TextureInfo::Ref info; | 73 uint64 identifier; |
| 79 }; | 74 }; |
| 80 | 75 |
| 81 virtual ~TextureImageTransportSurface(); | 76 virtual ~TextureImageTransportSurface(); |
| 82 void CreateBackTexture(const gfx::Size& size); | 77 void CreateBackTexture(); |
| 83 void AttachBackTextureToFBO(); | 78 void AttachBackTextureToFBO(); |
| 84 void ReleaseTexture(int id); | 79 void ReleaseBackBuffer(); |
| 85 void ReleaseParentStub(); | |
| 86 void AdjustFrontBufferAllocation(); | 80 void AdjustFrontBufferAllocation(); |
| 87 void BufferPresentedImpl(bool presented); | 81 void BufferPresentedImpl(uint64 surface_handle); |
| 88 int front() const { return front_; } | 82 void ProduceTexture(Texture& texture); |
|
jonathan.backer
2012/11/12 16:52:15
nit: Only operates on the same Texture.
| |
| 89 int back() const { return 1 - front_; } | 83 void ConsumeTexture(Texture& texture); |
| 90 | 84 |
| 91 // The framebuffer that represents this surface (service id). Allocated lazily | 85 // The framebuffer that represents this surface (service id). Allocated lazily |
| 92 // in OnMakeCurrent. | 86 // in OnMakeCurrent. |
| 93 uint32 fbo_id_; | 87 uint32 fbo_id_; |
| 94 | 88 |
| 95 // The front and back buffers. | 89 // The current backbuffer |
| 96 Texture textures_[2]; | 90 Texture backbuffer_; |
| 97 | 91 |
| 98 gfx::Rect previous_damage_rect_; | 92 gfx::Size current_size_; |
| 99 | |
| 100 // Indicates which of the 2 above is the front buffer. | |
| 101 int front_; | |
| 102 | 93 |
| 103 // Whether or not the command buffer stub has been destroyed. | 94 // Whether or not the command buffer stub has been destroyed. |
| 104 bool stub_destroyed_; | 95 bool stub_destroyed_; |
| 105 | 96 |
| 106 bool backbuffer_suggested_allocation_; | 97 bool backbuffer_suggested_allocation_; |
| 107 bool frontbuffer_suggested_allocation_; | 98 bool frontbuffer_suggested_allocation_; |
| 108 | 99 |
| 109 bool frontbuffer_is_protected_; | |
| 110 uint32 protection_state_id_; | |
| 111 | |
| 112 scoped_ptr<ImageTransportHelper> helper_; | 100 scoped_ptr<ImageTransportHelper> helper_; |
| 113 gfx::GLSurfaceHandle handle_; | 101 gfx::GLSurfaceHandle handle_; |
| 114 GpuCommandBufferStub* parent_stub_; | |
| 115 | 102 |
| 116 // The offscreen surface used to make the context current. However note that | 103 // The offscreen surface used to make the context current. However note that |
| 117 // the actual rendering is always redirected to an FBO. | 104 // the actual rendering is always redirected to an FBO. |
| 118 scoped_refptr<GLSurface> surface_; | 105 scoped_refptr<GLSurface> surface_; |
| 119 | 106 |
| 120 // Whether a SwapBuffers is pending. | 107 // Whether a SwapBuffers is pending. |
| 121 bool is_swap_buffers_pending_; | 108 bool is_swap_buffers_pending_; |
| 122 | 109 |
| 123 // Whether we unscheduled command buffer because of pending SwapBuffers. | 110 // Whether we unscheduled command buffer because of pending SwapBuffers. |
| 124 bool did_unschedule_; | 111 bool did_unschedule_; |
| 125 | 112 |
| 126 // Whether or not the buffer flip went through browser side on the last | 113 // The mailbox names used for texture exchange. Uses the texture |
| 127 // swap or post sub buffer. | 114 // identifier as the key. |
| 128 bool did_flip_; | 115 std::map<uint64, gpu::gles2::MailboxName> mailbox_names_; |
| 116 | |
| 117 // Holds a reference to the mailbox manager for cleanup. | |
| 118 scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_; | |
| 129 | 119 |
| 130 DISALLOW_COPY_AND_ASSIGN(TextureImageTransportSurface); | 120 DISALLOW_COPY_AND_ASSIGN(TextureImageTransportSurface); |
| 131 }; | 121 }; |
| 132 | 122 |
| 133 } // namespace content | 123 } // namespace content |
| 134 | 124 |
| 135 #endif // CONTENT_COMMON_GPU_TEXTURE_IMAGE_TRANSPORT_SURFACE_H_ | 125 #endif // CONTENT_COMMON_GPU_TEXTURE_IMAGE_TRANSPORT_SURFACE_H_ |
| OLD | NEW |