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_RENDERER_GPU_MAILBOX_OUTPUT_SURFACE_H_ 6 #define CONTENT_RENDERER_GPU_MAILBOX_OUTPUT_SURFACE_H_ 7 8 #include <queue> 9 10 #include "cc/resources/resource_format.h" 11 #include "cc/resources/transferable_resource.h" 12 #include "content/renderer/gpu/compositor_output_surface.h" 13 #include "ui/gfx/size.h" 14 15 namespace cc { 16 class CompositorFrameAck; 17 } 18 19 namespace content { 20 21 // Implementation of CompositorOutputSurface that renders to textures which 22 // are sent to the browser through the mailbox extension. 23 // This class can be created only on the main thread, but then becomes pinned 24 // to a fixed thread when bindToClient is called. 25 class MailboxOutputSurface : public CompositorOutputSurface { 26 public: 27 MailboxOutputSurface( 28 int32 routing_id, 29 uint32 output_surface_id, 30 const scoped_refptr<ContextProviderCommandBuffer>& context_provider, 31 scoped_ptr<cc::SoftwareOutputDevice> software_device, 32 cc::ResourceFormat format); 33 virtual ~MailboxOutputSurface(); 34 35 // cc::OutputSurface implementation. 36 virtual void EnsureBackbuffer() OVERRIDE; 37 virtual void DiscardBackbuffer() OVERRIDE; 38 virtual void Reshape(const gfx::Size& size, float scale_factor) OVERRIDE; 39 virtual void BindFramebuffer() OVERRIDE; 40 virtual void SwapBuffers(cc::CompositorFrame* frame) OVERRIDE; 41 42 private: 43 // CompositorOutputSurface overrides. 44 virtual void OnSwapAck(uint32 output_surface_id, 45 const cc::CompositorFrameAck& ack) OVERRIDE; 46 47 size_t GetNumAcksPending(); 48 49 struct TransferableFrame { 50 TransferableFrame() : texture_id(0), sync_point(0) {} 51 52 TransferableFrame(uint32 texture_id, 53 const gpu::Mailbox& mailbox, 54 const gfx::Size size) 55 : texture_id(texture_id), mailbox(mailbox), size(size), sync_point(0) {} 56 57 uint32 texture_id; 58 gpu::Mailbox mailbox; 59 gfx::Size size; 60 uint32 sync_point; 61 }; 62 63 TransferableFrame current_backing_; 64 std::deque<TransferableFrame> pending_textures_; 65 std::queue<TransferableFrame> returned_textures_; 66 67 uint32 fbo_; 68 bool is_backbuffer_discarded_; 69 cc::ResourceFormat format_; 70 }; 71 72 } // namespace content 73 74 #endif // CONTENT_RENDERER_GPU_MAILBOX_OUTPUT_SURFACE_H_ 75