OLD | NEW |
| (Empty) |
1 // Copyright 2014 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 #include "components/mus/public/cpp/output_surface.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "cc/output/compositor_frame.h" | |
9 #include "cc/output/compositor_frame_ack.h" | |
10 #include "cc/output/output_surface_client.h" | |
11 #include "components/mus/public/cpp/window_surface.h" | |
12 | |
13 namespace mus { | |
14 | |
15 OutputSurface::OutputSurface( | |
16 const scoped_refptr<cc::ContextProvider>& context_provider, | |
17 std::unique_ptr<mus::WindowSurface> surface) | |
18 : cc::OutputSurface(context_provider, nullptr, nullptr), | |
19 surface_(std::move(surface)) { | |
20 capabilities_.delegated_rendering = true; | |
21 } | |
22 | |
23 OutputSurface::~OutputSurface() {} | |
24 | |
25 bool OutputSurface::BindToClient(cc::OutputSurfaceClient* client) { | |
26 surface_->BindToThread(); | |
27 surface_->set_client(this); | |
28 return cc::OutputSurface::BindToClient(client); | |
29 } | |
30 | |
31 void OutputSurface::DetachFromClient() { | |
32 surface_.reset(); | |
33 cc::OutputSurface::DetachFromClient(); | |
34 } | |
35 | |
36 void OutputSurface::BindFramebuffer() { | |
37 // This is a delegating output surface, no framebuffer/direct drawing support. | |
38 NOTREACHED(); | |
39 } | |
40 | |
41 uint32_t OutputSurface::GetFramebufferCopyTextureFormat() { | |
42 // This is a delegating output surface, no framebuffer/direct drawing support. | |
43 NOTREACHED(); | |
44 return 0; | |
45 } | |
46 | |
47 void OutputSurface::SwapBuffers(cc::CompositorFrame frame) { | |
48 // TODO(fsamuel, rjkroege): We should probably throttle compositor frames. | |
49 client_->DidSwapBuffers(); | |
50 // OutputSurface owns WindowSurface, and so if OutputSurface is | |
51 // destroyed then SubmitCompositorFrame's callback will never get called. | |
52 // Thus, base::Unretained is safe here. | |
53 surface_->SubmitCompositorFrame( | |
54 std::move(frame), | |
55 base::Bind(&OutputSurface::SwapBuffersComplete, base::Unretained(this))); | |
56 } | |
57 | |
58 void OutputSurface::OnResourcesReturned( | |
59 mus::WindowSurface* surface, | |
60 mojo::Array<cc::ReturnedResource> resources) { | |
61 cc::CompositorFrameAck cfa; | |
62 cfa.resources = resources.To<cc::ReturnedResourceArray>(); | |
63 ReclaimResources(&cfa); | |
64 } | |
65 | |
66 void OutputSurface::SwapBuffersComplete() { | |
67 client_->DidSwapBuffersComplete(); | |
68 } | |
69 | |
70 } // namespace mus | |
OLD | NEW |