blob: 0516ea4afa5181a5f77fadba64318227730086e8 [file] [log] [blame]
Forrest Reilingc9058412016-03-08 11:36:28 -08001// 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 "image_pipe_consumer_endpoint.h"
6
7namespace image_pipe {
8
9void ImagePipeConsumerEndpoint::CloseEndpoint() {
10 image_pipe_binding_.Close();
11 delegate_->HandleEndpointClosed();
12}
13
14ImagePipeConsumerEndpoint::ImagePipeConsumerEndpoint(
15 mojo::InterfaceRequest<mojo::gfx::ImagePipe> request,
16 ImagePipeConsumerDelegate* delegate)
17 : state_tracker_(false, [this]() { CloseEndpoint(); }),
18 delegate_(delegate),
19 image_pipe_binding_(this, request.Pass()) {
20 image_pipe_binding_.set_connection_error_handler([this]() {
21 MOJO_LOG(ERROR) << "Image Pipe Connection Error for Consumer!";
22 CloseEndpoint();
23 });
24}
25
26ImagePipeConsumerEndpoint::~ImagePipeConsumerEndpoint() {}
27
28void ImagePipeConsumerEndpoint::ReleaseImage(
29 uint32_t id,
30 mojo::gfx::PresentationStatus status) {
31 state_tracker_.ConsumerRelease(id, status);
32}
33
34// mojo::gfx::ImagePipe implementation
35void ImagePipeConsumerEndpoint::AddImage(mojo::gfx::ImagePtr image,
36 uint32_t id) {
37 state_tracker_.ProducerAdd(id);
38 delegate_->AddImage(image.Pass(), id);
39}
40
41void ImagePipeConsumerEndpoint::RemoveImage(uint32_t id) {
42 state_tracker_.ProducerRemove(id);
43 delegate_->RemoveImage(id);
44}
45
46void ImagePipeConsumerEndpoint::PresentImage(
47 uint32_t id,
48 const PresentImageCallback& callback) {
49 state_tracker_.ProducerPresent(id, callback);
50 delegate_->PresentImage(id);
51}
52
53void ImagePipeConsumerEndpoint::FlushImages() {
54 state_tracker_.ProducerFlush();
55}
56
57bool ImagePipeConsumerEndpoint::AcquireNextImage(uint32_t* out_id) {
58 return state_tracker_.AcquireNextImage(out_id);
59}
60
61void ImagePipeConsumerEndpoint::DisableFatalErrorsForTesting() {
62 state_tracker_.DisableFatalErrorsForTesting();
63}
64
65} // namespace image_pipe