Index: mojo/services/gfx/images/cpp/image_pipe_producer_endpoint.h |
diff --git a/mojo/services/gfx/images/cpp/image_pipe_producer_endpoint.h b/mojo/services/gfx/images/cpp/image_pipe_producer_endpoint.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..35f46844d24c855222681837ff31a1a8e3996333 |
--- /dev/null |
+++ b/mojo/services/gfx/images/cpp/image_pipe_producer_endpoint.h |
@@ -0,0 +1,71 @@ |
+// 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_INTERFACES_IMAGE_PIPE_PRODUCER_ENDPOINT_H_ |
+#define MOJO_SERVICES_GFX_IMAGES_INTERFACES_IMAGE_PIPE_PRODUCER_ENDPOINT_H_ |
+ |
+#include "image_pipe_endpoint.h" |
+#include "mojo/public/c/system/macros.h" |
+#include "mojo/services/gfx/images/interfaces/image_pipe.mojom.h" |
+ |
+namespace image_pipe { |
+ |
+// This class wraps the producer end of an ImagePipe and validates the sanity |
+// of both the producer actions and the consumer actions coming over the |
+// message pipe. It also tracks the state of Images in the pipe's image pool |
+// and provides conviennce mechanisms for accessing this state (like the ability |
+// to get the ID of an available image without having to manually track the |
+// lifecycle of these images. |
+class ImagePipeProducerEndpoint : public mojo::gfx::ImagePipe { |
+ public: |
+ ImagePipeProducerEndpoint(mojo::gfx::ImagePipePtr image_pipe, |
+ std::function<void()> endpoint_closed_callback); |
+ |
+ ~ImagePipeProducerEndpoint() override; |
+ |
+ // ask the endpoint for an available image to draw into |
jamesr
2016/02/18 20:40:59
capitalize
Forrest Reiling
2016/02/25 00:35:14
Done.
|
+ // returns false if no images are available, otherwise returns true and |
+ // sets |id| to the acquired ID. |
+ bool AcquireImage(uint32_t& id); |
jamesr
2016/02/18 20:40:59
pointer for out-param
Forrest Reiling
2016/02/25 00:35:15
Done.
|
+ |
+ // The blocking version of the above function. This function will block until |
+ // an Image is available or the deadline is met. If there are no images in the |
+ // pool or the underlying message pipe has errors then false will be returned |
+ bool AcquireImageBlocking(uint32_t& id, MojoDeadline deadline); |
+ |
+ // Inherited from mojo::gfx::ImagePipe, see image_pipe.mojom for comments |
+ void AddImage(mojo::gfx::ImagePtr image, uint32_t id) override; |
+ void RemoveImage(uint32_t id) override; |
+ void PresentImage(uint32_t id, const PresentImageCallback& callback) override; |
+ void FlushImages() override; |
+ void GetSupportedImageProperties( |
+ const GetSupportedImagePropertiesCallback& callback) override; |
+ |
+ // returns true iff the message pipe underlying the image pipe has enountered |
jamesr
2016/02/18 20:40:59
we don't normally say "iff" even when we mean it
Forrest Reiling
2016/02/25 00:35:15
Sure. For the record though I'm pretty sure if you
|
+ // errors or closed |
+ bool HasEncounteredError(); |
+ |
+ // 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 DisableFatalErrors(); |
+ |
+ private: |
+ void CloseEndpoint(); |
+ |
+ // This exists wrap ImagePipeEndpoint::ConsumerRelease because for some reason |
+ // GCC doesnt like us calling protected methods on our base class from inside |
+ // a lambda that captures 'this', which breaks the fnl build. Clang handles it |
+ // fine, but its unclear whos right here, so we trampoline it as a workaround |
+ void ConsumerReleaseInternal(uint32_t id, |
+ mojo::gfx::PresentationStatus status); |
+ |
+ ImagePipeEndpoint state_tacker_; |
jamesr
2016/02/18 20:40:59
tacker -> tracker? or is this something else? i'm
Forrest Reiling
2016/02/25 00:35:15
'tacker' is typo-copy-pasta cancer. Fixed
|
+ mojo::gfx::ImagePipePtr image_pipe_ptr_; |
+ std::function<void()> endpoint_closed_callback_; |
+}; |
+} |
jamesr
2016/02/18 20:40:59
newline, comment
Forrest Reiling
2016/02/25 00:35:14
Done.
|
+ |
+#endif // MOJO_SERVICES_GFX_IMAGES_INTERFACES_IMAGE_PIPE_PRODUCER_ENDPOINT_H_ |