Chromium Code Reviews| Index: mojo/services/gfx/images/cpp/image_pipe_endpoint.h |
| diff --git a/mojo/services/gfx/images/cpp/image_pipe_endpoint.h b/mojo/services/gfx/images/cpp/image_pipe_endpoint.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..07641e1d94d3e5b647005aa611f66eb8b43de112 |
| --- /dev/null |
| +++ b/mojo/services/gfx/images/cpp/image_pipe_endpoint.h |
| @@ -0,0 +1,81 @@ |
| +// Copyright 2016 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. |
| + |
| +#ifndef MOJO_SERVICES_GFX_IMAGES_CPP_IMAGE_PIPE_ENDPOINT_H_ |
| +#define MOJO_SERVICES_GFX_IMAGES_CPP_IMAGE_PIPE_ENDPOINT_H_ |
| + |
| +#include <deque> |
| +#include <string> |
| +#include <unordered_map> |
| +#include <unordered_set> |
| +#include <vector> |
| + |
| +#include "mojo/public/c/system/macros.h" |
| +#include "mojo/services/gfx/images/interfaces/image_pipe.mojom.h" |
| + |
| +namespace image_pipe { |
| + |
| +class ImagePipeEndpoint { |
| + public: |
| + ImagePipeEndpoint(bool is_producer, |
| + std::function<void()> fatal_error_handler); |
| + virtual ~ImagePipeEndpoint(); |
| + |
| + void ProducerFatalError(const std::string& message, uint32_t id); |
| + void ConsumerFatalError(const std::string& message, uint32_t id); |
| + |
| + bool AcquireNextImage(uint32_t* id); |
|
jeffbrown
2016/03/03 23:27:49
nit: out_id
Forrest Reiling
2016/03/04 21:04:28
Done.
|
| + |
| + void ProducerAdd(uint32_t id); |
| + void ProducerRemove(uint32_t id); |
| + void ProducerPresent(uint32_t id, |
| + mojo::gfx::ImagePipe::PresentImageCallback callback); |
| + void ConsumerRelease(uint32_t id, mojo::gfx::PresentationStatus status); |
| + void ProducerFlush(); |
| + |
| + // For testing only, makes fatal errors not quite fatal, which allows tests |
| + // to cause a fatal error and check that it was caught correctly without |
| + // dying a horrible death in the process. If you are using this for something |
| + // other than testing you are probably doing something very wrong. |
| + void DisableFatalErrorsForTesting(); |
| + |
| + private: |
| + bool IsInPool(uint32_t id) const; |
| + bool IsConsumerOwned(uint32_t id) const; |
| + bool IsConsumerAcquirable(uint32_t id) const; |
| + bool IsProducerOwned(uint32_t id) const; |
| + bool IsProducerAcquirable(uint32_t id) const; |
| + void CallPresentCallback(uint32_t id, mojo::gfx::PresentationStatus status); |
| + void ReleaseInternal(uint32_t id, bool released_by_producer); |
| + |
| + static void ImagePipeLogError(const std::string& entity, |
| + const std::string& message, |
| + uint32_t id); |
| + |
| + // Used for internal state tracking and validation |
| + std::unordered_map<uint32_t, mojo::gfx::ImagePipe::PresentImageCallback> |
| + present_callback_map_; |
| + |
| + // ids that have been added to the pipe's image pool and have not been removed |
| + std::unordered_set<uint32_t> image_pool_ids_; |
| + |
| + // images that have been aquired by the consumer |
| + std::unordered_set<uint32_t> consumer_owned_ids_; |
| + // images that have been presented by the producer but have not been aquired |
| + // by the consumer |
| + std::deque<uint32_t> consumer_acquirable_ids_; |
| + |
| + // images that have been aquired by the producer |
| + std::unordered_set<uint32_t> producer_owned_ids_; |
| + // images that have been released by the producer but have not been aquired |
| + // by the consumer |
| + std::deque<uint32_t> producer_acquirable_ids_; |
| + |
| + bool is_producer_; |
| + bool is_checked_; |
| + std::function<void()> fatal_error_handler_; |
| +}; |
| +} |
| + |
| +#endif // MOJO_SERVICES_GFX_IMAGES_CPP_IMAGE_PIPE_ENDPOINT_H_ |