OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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_producer_endpoint.h" |
| 6 |
| 7 namespace image_pipe { |
| 8 |
| 9 void ImagePipeProducerEndpoint::CloseEndpoint() { |
| 10 image_pipe_ptr_.reset(); |
| 11 endpoint_closed_callback_(); |
| 12 } |
| 13 |
| 14 ImagePipeProducerEndpoint::ImagePipeProducerEndpoint( |
| 15 mojo::gfx::ImagePipePtr image_pipe, |
| 16 std::function<void()> endpoint_closed_callback, |
| 17 bool is_checked) |
| 18 : ImagePipeEndpoint(true, is_checked), image_pipe_ptr_(image_pipe.Pass()) { |
| 19 endpoint_closed_callback_ = endpoint_closed_callback; |
| 20 image_pipe_ptr_.set_connection_error_handler([this] { CloseEndpoint(); }); |
| 21 } |
| 22 |
| 23 ImagePipeProducerEndpoint::~ImagePipeProducerEndpoint() {} |
| 24 |
| 25 bool ImagePipeProducerEndpoint::AcquireImage(uint32_t& id, bool blocking) { |
| 26 bool have_image = false; |
| 27 do { |
| 28 have_image = ImagePipeEndpoint::AcquireNextImage(id); |
| 29 if (blocking && !have_image) { |
| 30 if (image_pipe_ptr_.encountered_error()) |
| 31 break; |
| 32 image_pipe_ptr_.WaitForIncomingResponse(); |
| 33 if (image_pipe_ptr_.encountered_error()) |
| 34 break; |
| 35 } |
| 36 } while (blocking && !have_image); |
| 37 |
| 38 return have_image; |
| 39 } |
| 40 |
| 41 void ImagePipeProducerEndpoint::AddImage(mojo::gfx::ImagePtr image, |
| 42 uint32_t id) { |
| 43 ImagePipeEndpoint::ProducerAdd(id); |
| 44 image_pipe_ptr_->AddImage(image.Pass(), id); |
| 45 } |
| 46 |
| 47 void ImagePipeProducerEndpoint::RemoveImage(uint32_t id) { |
| 48 ImagePipeEndpoint::ProducerRemove(id); |
| 49 image_pipe_ptr_->RemoveImage(id); |
| 50 } |
| 51 |
| 52 void ImagePipeProducerEndpoint::ConsumerReleaseInternal( |
| 53 uint32_t id, |
| 54 mojo::gfx::PresentationStatus status) { |
| 55 ImagePipeEndpoint::ConsumerRelease(id, status); |
| 56 } |
| 57 |
| 58 void ImagePipeProducerEndpoint::PresentImage( |
| 59 uint32_t id, |
| 60 const PresentImageCallback& callback) { |
| 61 ImagePipeEndpoint::ProducerPresent(id, callback); |
| 62 image_pipe_ptr_->PresentImage( |
| 63 id, [this](uint32_t id, mojo::gfx::PresentationStatus status) { |
| 64 ConsumerReleaseInternal(id, status); |
| 65 }); |
| 66 } |
| 67 |
| 68 void ImagePipeProducerEndpoint::FlushImages() { |
| 69 ImagePipeEndpoint::ProducerFlush(); |
| 70 image_pipe_ptr_->FlushImages(); |
| 71 } |
| 72 |
| 73 void ImagePipeProducerEndpoint::GetSupportedImageProperties( |
| 74 const GetSupportedImagePropertiesCallback& callback) { |
| 75 image_pipe_ptr_->GetSupportedImageProperties(callback); |
| 76 } |
| 77 } |
OLD | NEW |