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