Forrest Reiling | c905841 | 2016-03-08 11:36:28 -0800 | [diff] [blame] | 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 "image_pipe_consumer_endpoint.h" |
| 6 | |
| 7 | namespace image_pipe { |
| 8 | |
| 9 | void ImagePipeConsumerEndpoint::CloseEndpoint() { |
| 10 | image_pipe_binding_.Close(); |
| 11 | delegate_->HandleEndpointClosed(); |
| 12 | } |
| 13 | |
| 14 | ImagePipeConsumerEndpoint::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 | |
| 26 | ImagePipeConsumerEndpoint::~ImagePipeConsumerEndpoint() {} |
| 27 | |
| 28 | void ImagePipeConsumerEndpoint::ReleaseImage( |
| 29 | uint32_t id, |
| 30 | mojo::gfx::PresentationStatus status) { |
| 31 | state_tracker_.ConsumerRelease(id, status); |
| 32 | } |
| 33 | |
| 34 | // mojo::gfx::ImagePipe implementation |
| 35 | void ImagePipeConsumerEndpoint::AddImage(mojo::gfx::ImagePtr image, |
| 36 | uint32_t id) { |
| 37 | state_tracker_.ProducerAdd(id); |
| 38 | delegate_->AddImage(image.Pass(), id); |
| 39 | } |
| 40 | |
| 41 | void ImagePipeConsumerEndpoint::RemoveImage(uint32_t id) { |
| 42 | state_tracker_.ProducerRemove(id); |
| 43 | delegate_->RemoveImage(id); |
| 44 | } |
| 45 | |
| 46 | void ImagePipeConsumerEndpoint::PresentImage( |
| 47 | uint32_t id, |
| 48 | const PresentImageCallback& callback) { |
| 49 | state_tracker_.ProducerPresent(id, callback); |
| 50 | delegate_->PresentImage(id); |
| 51 | } |
| 52 | |
| 53 | void ImagePipeConsumerEndpoint::FlushImages() { |
| 54 | state_tracker_.ProducerFlush(); |
| 55 | } |
| 56 | |
| 57 | bool ImagePipeConsumerEndpoint::AcquireNextImage(uint32_t* out_id) { |
| 58 | return state_tracker_.AcquireNextImage(out_id); |
| 59 | } |
| 60 | |
| 61 | void ImagePipeConsumerEndpoint::DisableFatalErrorsForTesting() { |
| 62 | state_tracker_.DisableFatalErrorsForTesting(); |
| 63 | } |
| 64 | |
| 65 | } // namespace image_pipe |