| 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 <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "content/common/gpu/gpu_command_buffer_stub.h" | 12 #include "content/common/gpu/gpu_command_buffer_stub.h" |
| 13 #include "content/common/gpu/image_transport_surface.h" | 13 #include "content/common/gpu/image_transport_surface.h" |
| 14 #include "gpu/command_buffer/service/mailbox_manager.h" | 14 #include "gpu/command_buffer/service/mailbox_manager.h" |
| 15 #include "gpu/command_buffer/service/texture_definition.h" | |
| 16 #include "gpu/command_buffer/service/texture_manager.h" | 15 #include "gpu/command_buffer/service/texture_manager.h" |
| 17 #include "ui/gl/gl_context.h" | 16 #include "ui/gl/gl_context.h" |
| 18 #include "ui/gl/gl_surface.h" | 17 #include "ui/gl/gl_surface.h" |
| 19 | 18 |
| 20 namespace content { | 19 namespace content { |
| 21 class GpuChannelManager; | 20 class GpuChannelManager; |
| 22 | 21 |
| 23 class TextureImageTransportSurface | 22 class TextureImageTransportSurface |
| 24 : public ImageTransportSurface, | 23 : public ImageTransportSurface, |
| 25 public GpuCommandBufferStub::DestructionObserver, | 24 public GpuCommandBufferStub::DestructionObserver, |
| 26 public gfx::GLSurface { | 25 public gfx::GLSurface { |
| 27 public: | 26 public: |
| 28 TextureImageTransportSurface(GpuChannelManager* manager, | 27 TextureImageTransportSurface(GpuChannelManager* manager, |
| 29 GpuCommandBufferStub* stub, | 28 GpuCommandBufferStub* stub, |
| 30 const gfx::GLSurfaceHandle& handle); | 29 const gfx::GLSurfaceHandle& handle); |
| 31 | 30 |
| 32 // gfx::GLSurface implementation. | 31 // gfx::GLSurface implementation. |
| 33 virtual bool Initialize() OVERRIDE; | 32 virtual bool Initialize() OVERRIDE; |
| 34 virtual void Destroy() OVERRIDE; | 33 virtual void Destroy() OVERRIDE; |
| 35 virtual bool DeferDraws() OVERRIDE; | 34 virtual bool DeferDraws() OVERRIDE; |
| 36 virtual bool Resize(const gfx::Size& size) OVERRIDE; | |
| 37 virtual bool IsOffscreen() OVERRIDE; | 35 virtual bool IsOffscreen() OVERRIDE; |
| 38 virtual bool SwapBuffers() OVERRIDE; | 36 virtual bool SwapBuffers() OVERRIDE; |
| 39 virtual gfx::Size GetSize() OVERRIDE; | 37 virtual gfx::Size GetSize() OVERRIDE; |
| 40 virtual void* GetHandle() OVERRIDE; | 38 virtual void* GetHandle() OVERRIDE; |
| 41 virtual unsigned GetFormat() OVERRIDE; | 39 virtual unsigned GetFormat() OVERRIDE; |
| 42 virtual std::string GetExtensions() OVERRIDE; | 40 virtual std::string GetExtensions() OVERRIDE; |
| 43 virtual unsigned int GetBackingFrameBufferObject() OVERRIDE; | 41 virtual unsigned int GetBackingFrameBufferObject() OVERRIDE; |
| 44 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; |
| 45 virtual bool OnMakeCurrent(gfx::GLContext* context) OVERRIDE; | |
| 46 virtual bool SetBackbufferAllocation(bool allocated) OVERRIDE; | 43 virtual bool SetBackbufferAllocation(bool allocated) OVERRIDE; |
| 47 virtual void SetFrontbufferAllocation(bool allocated) OVERRIDE; | 44 virtual void SetFrontbufferAllocation(bool allocated) OVERRIDE; |
| 48 virtual void* GetShareHandle() OVERRIDE; | 45 virtual void* GetShareHandle() OVERRIDE; |
| 49 virtual void* GetDisplay() OVERRIDE; | 46 virtual void* GetDisplay() OVERRIDE; |
| 50 virtual void* GetConfig() OVERRIDE; | 47 virtual void* GetConfig() OVERRIDE; |
| 51 | 48 |
| 52 protected: | 49 protected: |
| 53 // ImageTransportSurface implementation. | 50 // ImageTransportSurface implementation. |
| 54 virtual void OnBufferPresented( | 51 virtual void OnBufferPresented( |
| 55 const AcceleratedSurfaceMsg_BufferPresented_Params& params) OVERRIDE; | 52 const AcceleratedSurfaceMsg_BufferPresented_Params& params) OVERRIDE; |
| 56 virtual void OnResizeViewACK() OVERRIDE; | 53 virtual void OnResizeViewACK() OVERRIDE; |
| 57 virtual void OnResize(gfx::Size size) OVERRIDE; | 54 virtual void OnResize(gfx::Size size) OVERRIDE; |
| 58 virtual void SetLatencyInfo( | 55 virtual void SetLatencyInfo( |
| 59 const cc::LatencyInfo& latency_info) OVERRIDE; | 56 const cc::LatencyInfo& latency_info) OVERRIDE; |
| 60 | 57 |
| 61 // GpuCommandBufferStub::DestructionObserver implementation. | 58 // GpuCommandBufferStub::DestructionObserver implementation. |
| 62 virtual void OnWillDestroyStub() OVERRIDE; | 59 virtual void OnWillDestroyStub() OVERRIDE; |
| 63 | 60 |
| 64 private: | 61 private: |
| 65 | 62 |
| 66 gfx::Size backbuffer_size() const { | 63 gfx::Size backbuffer_size() const { |
| 67 return gfx::Size(backbuffer_->level_infos()[0][0].width, | 64 DCHECK(backbuffer_); |
| 68 backbuffer_->level_infos()[0][0].height); | 65 GLsizei width = 0; |
| 66 GLsizei height = 0; |
| 67 backbuffer_->texture()->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height); |
| 68 return gfx::Size(width, height); |
| 69 } | 69 } |
| 70 | 70 |
| 71 virtual ~TextureImageTransportSurface(); | 71 virtual ~TextureImageTransportSurface(); |
| 72 void CreateBackTexture(); | 72 void CreateBackTexture(); |
| 73 void AttachBackTextureToFBO(); | 73 void AttachBackTextureToFBO(); |
| 74 void ReleaseBackTexture(); | 74 void ReleaseBackTexture(); |
| 75 void ReleaseFrontTexture(); |
| 75 void BufferPresentedImpl(const std::string& mailbox_name); | 76 void BufferPresentedImpl(const std::string& mailbox_name); |
| 76 void ProduceTexture(); | |
| 77 void ConsumeTexture(); | |
| 78 | |
| 79 static gpu::gles2::TextureDefinition* CreateTextureDefinition(gfx::Size size, | |
| 80 int service_id); | |
| 81 | 77 |
| 82 // The framebuffer that represents this surface (service id). Allocated lazily | 78 // The framebuffer that represents this surface (service id). Allocated lazily |
| 83 // in OnMakeCurrent. | 79 // in OnMakeCurrent. |
| 84 uint32 fbo_id_; | 80 uint32 fbo_id_; |
| 85 | 81 |
| 86 // The current backbuffer. | 82 // The current backbuffer. |
| 87 scoped_ptr<gpu::gles2::TextureDefinition> backbuffer_; | 83 scoped_refptr<gpu::gles2::TextureRef> backbuffer_; |
| 84 scoped_refptr<gpu::gles2::TextureRef> frontbuffer_; |
| 88 | 85 |
| 89 // The mailbox name for the current backbuffer texture. Needs to be unique per | 86 // The mailbox name for the current backbuffer texture. Needs to be unique per |
| 90 // GL texture and is invalid while service_id is zero. | 87 // GL texture and is invalid while service_id is zero. |
| 91 gpu::gles2::MailboxName mailbox_name_; | 88 gpu::gles2::MailboxName back_mailbox_name_; |
| 89 gpu::gles2::MailboxName front_mailbox_name_; |
| 92 | 90 |
| 93 // The current size of the GLSurface. Used to disambiguate from the current | 91 // The current size of the GLSurface. Used to disambiguate from the current |
| 94 // texture size which might be outdated (since we use two buffers). | 92 // texture size which might be outdated (since we use two buffers). |
| 95 gfx::Size current_size_; | 93 gfx::Size current_size_; |
| 96 | 94 |
| 97 // Whether or not the command buffer stub has been destroyed. | 95 // Whether or not the command buffer stub has been destroyed. |
| 98 bool stub_destroyed_; | 96 bool stub_destroyed_; |
| 99 | 97 |
| 100 bool backbuffer_suggested_allocation_; | 98 bool backbuffer_suggested_allocation_; |
| 101 bool frontbuffer_suggested_allocation_; | 99 bool frontbuffer_suggested_allocation_; |
| 102 | 100 |
| 103 scoped_ptr<ImageTransportHelper> helper_; | 101 scoped_ptr<ImageTransportHelper> helper_; |
| 104 gfx::GLSurfaceHandle handle_; | 102 gfx::GLSurfaceHandle handle_; |
| 105 | 103 |
| 106 // 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 |
| 107 // the actual rendering is always redirected to an FBO. | 105 // the actual rendering is always redirected to an FBO. |
| 108 scoped_refptr<gfx::GLSurface> surface_; | 106 scoped_refptr<gfx::GLSurface> surface_; |
| 109 | 107 |
| 110 // Holds a reference to the underlying context for cleanup. | |
| 111 scoped_refptr<gfx::GLContext> context_; | |
| 112 | |
| 113 // Whether a SwapBuffers is pending. | 108 // Whether a SwapBuffers is pending. |
| 114 bool is_swap_buffers_pending_; | 109 bool is_swap_buffers_pending_; |
| 115 | 110 |
| 116 // Whether we unscheduled command buffer because of pending SwapBuffers. | 111 // Whether we unscheduled command buffer because of pending SwapBuffers. |
| 117 bool did_unschedule_; | 112 bool did_unschedule_; |
| 118 | 113 |
| 119 // Holds a reference to the mailbox manager for cleanup. | 114 // Holds a reference to the mailbox manager for cleanup. |
| 120 scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_; | 115 scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_; |
| 121 | 116 |
| 122 cc::LatencyInfo latency_info_; | 117 cc::LatencyInfo latency_info_; |
| 123 DISALLOW_COPY_AND_ASSIGN(TextureImageTransportSurface); | 118 DISALLOW_COPY_AND_ASSIGN(TextureImageTransportSurface); |
| 124 }; | 119 }; |
| 125 | 120 |
| 126 } // namespace content | 121 } // namespace content |
| 127 | 122 |
| 128 #endif // CONTENT_COMMON_GPU_TEXTURE_IMAGE_TRANSPORT_SURFACE_H_ | 123 #endif // CONTENT_COMMON_GPU_TEXTURE_IMAGE_TRANSPORT_SURFACE_H_ |
| OLD | NEW |