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