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