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..669ad5f0d76bdd91750944c0c10f1bcf284b4ccf |
--- /dev/null |
+++ b/mojo/services/gfx/images/cpp/image_pipe_endpoint.h |
@@ -0,0 +1,76 @@ |
+// 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. |
+ |
+#ifndef MOJO_SERVICES_GFX_IMAGES_CPP_IMAGE_PIPE_ENDPOINT_H_ |
+#define MOJO_SERVICES_GFX_IMAGES_CPP_IMAGE_PIPE_ENDPOINT_H_ |
+ |
+#include <deque> |
+#include <map> |
+#include <vector> |
+ |
+#include "mojo/public/c/system/macros.h" |
+#include "mojo/services/gfx/images/interfaces/image_pipe.mojom.h" |
+ |
+namespace image_pipe { |
+ |
+// Base class for ImagePipeConsumerEndpoint and ImagePipeProducerEndpoint that |
+// provides common state state tracking facilities |
+class ImagePipeEndpoint { |
+ public: |
+ ImagePipeEndpoint(bool is_producer, bool is_checked); |
+ virtual ~ImagePipeEndpoint(); |
+ |
+ virtual void CloseEndpoint() = 0; |
+ |
+ protected: |
+ void ProducerFatalError(const char* message, uint32_t id); |
+ void ConsumerFatalError(const char* message, uint32_t id); |
+ |
+ bool AcquireNextImage(uint32_t& id); |
+ |
+ 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(); |
+ |
+ 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 char* entity, |
+ const char* message, |
+ uint32_t id); |
+ |
+ // Used for internal state tracking and validation |
+ std::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::vector<uint32_t> image_pool_ids_; |
+ |
+ // images that have been aquired by the consumer |
+ std::vector<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::vector<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_; |
+}; |
+} |
+ |
+#endif // MOJO_SERVICES_GFX_IMAGES_CPP_IMAGE_PIPE_ENDPOINT_H_ |