| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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 "blimp/engine/renderer/blimp_remote_compositor_bridge.h" | |
| 6 | |
| 7 #include "cc/blimp/compositor_proto_state.h" | |
| 8 #include "cc/blimp/remote_compositor_bridge_client.h" | |
| 9 #include "cc/output/swap_promise.h" | |
| 10 #include "cc/proto/compositor_message.pb.h" | |
| 11 | |
| 12 namespace blimp { | |
| 13 namespace engine { | |
| 14 | |
| 15 BlimpRemoteCompositorBridge::BlimpRemoteCompositorBridge( | |
| 16 content::RemoteProtoChannel* remote_proto_channel, | |
| 17 scoped_refptr<base::SingleThreadTaskRunner> compositor_main_task_runner) | |
| 18 : RemoteCompositorBridge(std::move(compositor_main_task_runner)), | |
| 19 remote_proto_channel_(remote_proto_channel), | |
| 20 scheduler_(compositor_main_task_runner_.get(), this) { | |
| 21 remote_proto_channel_->SetProtoReceiver(this); | |
| 22 } | |
| 23 | |
| 24 BlimpRemoteCompositorBridge::~BlimpRemoteCompositorBridge() { | |
| 25 remote_proto_channel_->SetProtoReceiver(nullptr); | |
| 26 } | |
| 27 | |
| 28 void BlimpRemoteCompositorBridge::BindToClient( | |
| 29 cc::RemoteCompositorBridgeClient* client) { | |
| 30 DCHECK(!client_); | |
| 31 client_ = client; | |
| 32 } | |
| 33 | |
| 34 void BlimpRemoteCompositorBridge::ScheduleMainFrame() { | |
| 35 scheduler_.ScheduleFrameUpdate(); | |
| 36 } | |
| 37 | |
| 38 void BlimpRemoteCompositorBridge::ProcessCompositorStateUpdate( | |
| 39 std::unique_ptr<cc::CompositorProtoState> compositor_proto_state) { | |
| 40 compositor_proto_state->compositor_message->set_client_state_update_ack( | |
| 41 client_state_update_ack_pending_); | |
| 42 client_state_update_ack_pending_ = false; | |
| 43 | |
| 44 remote_proto_channel_->SendCompositorProto( | |
| 45 *compositor_proto_state->compositor_message); | |
| 46 scheduler_.DidSendFrameUpdateToClient(); | |
| 47 | |
| 48 // Activate the swap promises after the frame is queued. | |
| 49 for (const auto& swap_promise : compositor_proto_state->swap_promises) | |
| 50 swap_promise->DidActivate(); | |
| 51 } | |
| 52 | |
| 53 void BlimpRemoteCompositorBridge::OnProtoReceived( | |
| 54 std::unique_ptr<cc::proto::CompositorMessage> proto) { | |
| 55 if (proto->frame_ack()) | |
| 56 scheduler_.DidReceiveFrameUpdateAck(); | |
| 57 | |
| 58 if (proto->has_client_state_update()) { | |
| 59 DCHECK(!client_state_update_ack_pending_); | |
| 60 | |
| 61 client_->ApplyStateUpdateFromClient(proto->client_state_update()); | |
| 62 | |
| 63 // If applying the delta resulted in a frame request, run the main frame | |
| 64 // first so the ack sent to the client includes the frame with the deltas | |
| 65 // applied. | |
| 66 if (scheduler_.needs_frame_update()) { | |
| 67 client_state_update_ack_pending_ = true; | |
| 68 } else { | |
| 69 cc::proto::CompositorMessage message; | |
| 70 message.set_client_state_update_ack(true); | |
| 71 remote_proto_channel_->SendCompositorProto(message); | |
| 72 } | |
| 73 } | |
| 74 } | |
| 75 | |
| 76 void BlimpRemoteCompositorBridge::StartFrameUpdate() { | |
| 77 client_->BeginMainFrame(); | |
| 78 | |
| 79 // If the frame resulted in an update to the client, the ack should have gone | |
| 80 // with it. If it is still pending, this means the main frame was aborted so | |
| 81 // send the ack now. | |
| 82 if (client_state_update_ack_pending_) { | |
| 83 client_state_update_ack_pending_ = false; | |
| 84 cc::proto::CompositorMessage message; | |
| 85 message.set_client_state_update_ack(true); | |
| 86 remote_proto_channel_->SendCompositorProto(message); | |
| 87 } | |
| 88 } | |
| 89 | |
| 90 } // namespace engine | |
| 91 } // namespace blimp | |
| OLD | NEW |