Chromium Code Reviews| Index: mojo/services/gfx/images/cpp/image_pipe_consumer_endpoint.cc |
| diff --git a/mojo/services/gfx/images/cpp/image_pipe_consumer_endpoint.cc b/mojo/services/gfx/images/cpp/image_pipe_consumer_endpoint.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..14374a9d3f74216f35ffffde8fb9669f22129677 |
| --- /dev/null |
| +++ b/mojo/services/gfx/images/cpp/image_pipe_consumer_endpoint.cc |
| @@ -0,0 +1,94 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "image_pipe_consumer_endpoint.h" |
| + |
| +namespace image_pipe { |
| + |
| +void ImagePipeConsumerEndpoint::CloseEndpoint() { |
| + image_pipe_binding_.Close(); |
| + delegate_->HandleEndpointClosed(); |
| +} |
| + |
| +ImagePipeConsumerEndpoint::ImagePipeConsumerEndpoint( |
| + mojo::InterfaceRequest<mojo::gfx::ImagePipe> request, |
| + mojo::gfx::SupportedImagePropertiesPtr supported_properties, |
| + ImagePipeConsumerDelegate* delegate) |
| + : state_tacker_(false, [this]() { CloseEndpoint(); }), |
| + delegate_(delegate), |
| + supported_properties_dirty_(true), |
| + supported_properties_callback_pending_(false), |
| + image_pipe_binding_(this, request.Pass()) { |
| + image_pipe_binding_.set_connection_error_handler([this]() { |
| + MOJO_LOG(ERROR) << "Image Pipe Connection Error for Consumer!"; |
| + CloseEndpoint(); |
| + }); |
| + |
| + supported_properties_ = supported_properties.Pass(); |
| +} |
| + |
| +ImagePipeConsumerEndpoint::~ImagePipeConsumerEndpoint() {} |
| + |
| +void ImagePipeConsumerEndpoint::ReleaseImage( |
| + uint32_t id, |
| + mojo::gfx::PresentationStatus status) { |
| + state_tacker_.ConsumerRelease(id, status); |
| +} |
| + |
| +void ImagePipeConsumerEndpoint::SetSupportedImageProperties( |
| + mojo::gfx::SupportedImagePropertiesPtr supported_properties) { |
| + supported_properties_ = supported_properties.Pass(); |
| + supported_properties_dirty_ = true; |
| + |
| + // this should be conditional on whether |
| + if (supported_properties_callback_pending_) { |
| + supported_properties_callback_.Run(supported_properties_.Clone()); |
| + supported_properties_callback_pending_ = false; |
| + supported_properties_dirty_ = false; |
| + } |
| +} |
| + |
| +/* mojo::gfx::ImagePipe implementation */ |
|
jamesr
2016/02/18 20:40:58
prefer // style comments
Forrest Reiling
2016/02/25 00:35:14
Done.
|
| +void ImagePipeConsumerEndpoint::AddImage(mojo::gfx::ImagePtr image, |
| + uint32_t id) { |
| + state_tacker_.ProducerAdd(id); |
| + delegate_->AddImage(image.Pass(), id); |
| +} |
| + |
| +void ImagePipeConsumerEndpoint::RemoveImage(uint32_t id) { |
| + state_tacker_.ProducerRemove(id); |
| + delegate_->RemoveImage(id); |
| +} |
| + |
| +void ImagePipeConsumerEndpoint::PresentImage( |
| + uint32_t id, |
| + const PresentImageCallback& callback) { |
| + state_tacker_.ProducerPresent(id, callback); |
| + delegate_->PresentImage(id); |
| +} |
| + |
| +void ImagePipeConsumerEndpoint::FlushImages() { |
| + state_tacker_.ProducerFlush(); |
| +} |
| + |
| +void ImagePipeConsumerEndpoint::GetSupportedImageProperties( |
| + const GetSupportedImagePropertiesCallback& callback) { |
| + if (supported_properties_dirty_) { |
| + callback.Run(supported_properties_.Clone()); |
| + supported_properties_dirty_ = false; |
| + } else { |
| + supported_properties_callback_ = callback; |
| + supported_properties_callback_pending_ = true; |
| + } |
| +} |
| + |
| +bool ImagePipeConsumerEndpoint::AcquireNextImage(uint32_t& id) { |
| + return state_tacker_.AcquireNextImage(id); |
| +} |
| + |
| +void ImagePipeConsumerEndpoint::DisableFatalErrors() { |
| + state_tacker_.DisableFatalErrors(); |
| +} |
| + |
| +} // namespace image_pipe |