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