OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 #ifndef MOJO_SERVICES_GFX_IMAGES_INTERFACES_IMAGE_PIPE_PRODUCER_ENDPOINT_H_ |
| 6 #define MOJO_SERVICES_GFX_IMAGES_INTERFACES_IMAGE_PIPE_PRODUCER_ENDPOINT_H_ |
| 7 |
| 8 #include "image_pipe_endpoint.h" |
| 9 #include "mojo/public/c/system/macros.h" |
| 10 #include "mojo/services/gfx/images/interfaces/image_pipe.mojom.h" |
| 11 |
| 12 namespace image_pipe { |
| 13 |
| 14 // This class wraps the producer end of an ImagePipe and validates the sanity |
| 15 // of both the producer actions and the consumer actions coming over the |
| 16 // message pipe. It also tracks the state of Images in the pipe's image pool |
| 17 // and provides conviennce mechanisms for accessing this state (like the ability |
| 18 // to get the ID of an available image without having to manually track the |
| 19 // lifecycle of these images. |
| 20 class ImagePipeProducerEndpoint : public mojo::gfx::ImagePipe { |
| 21 public: |
| 22 ImagePipeProducerEndpoint(mojo::gfx::ImagePipePtr image_pipe, |
| 23 std::function<void()> endpoint_closed_callback); |
| 24 |
| 25 ~ImagePipeProducerEndpoint() override; |
| 26 |
| 27 // Ask the endpoint for an available image to draw into |
| 28 // returns false if no images are available, otherwise returns true and |
| 29 // sets |id| to the acquired ID. |
| 30 bool AcquireImage(uint32_t* out_id); |
| 31 |
| 32 // The blocking version of the above function. This function will block until |
| 33 // an Image is available or the deadline is met. If there are no images in the |
| 34 // pool or the underlying message pipe has errors then false will be returned |
| 35 bool AcquireImageBlocking(uint32_t* out_id, MojoDeadline deadline); |
| 36 |
| 37 // Inherited from mojo::gfx::ImagePipe, see image_pipe.mojom for comments |
| 38 void AddImage(mojo::gfx::ImagePtr image, uint32_t id) override; |
| 39 void RemoveImage(uint32_t id) override; |
| 40 void PresentImage(uint32_t id, const PresentImageCallback& callback) override; |
| 41 void FlushImages() override; |
| 42 |
| 43 // Returns true if and only if the message pipe underlying the image pipe has |
| 44 // enountered errors or closed |
| 45 bool HasEncounteredError(); |
| 46 |
| 47 // For testing only, makes fatal errors not quite fatal, which allows tests |
| 48 // to cause a fatal error and check that it was caught correctly without |
| 49 // dying a horrible death in the process. If you are using this for something |
| 50 // other than testing you are probably doing something very wrong. |
| 51 void DisableFatalErrorsForTesting(); |
| 52 |
| 53 private: |
| 54 void CloseEndpoint(); |
| 55 |
| 56 // This exists wrap ImagePipeEndpoint::ConsumerRelease because for some reason |
| 57 // GCC doesnt like us calling protected methods on our base class from inside |
| 58 // a lambda that captures 'this', which breaks the fnl build. Clang handles it |
| 59 // fine, but its unclear whos right here, so we trampoline it as a workaround |
| 60 void ConsumerReleaseInternal(uint32_t id, |
| 61 mojo::gfx::PresentationStatus status); |
| 62 |
| 63 ImagePipeEndpoint state_tracker_; |
| 64 mojo::gfx::ImagePipePtr image_pipe_ptr_; |
| 65 std::function<void()> endpoint_closed_callback_; |
| 66 }; |
| 67 |
| 68 } // namespace image_pipe |
| 69 |
| 70 #endif // MOJO_SERVICES_GFX_IMAGES_INTERFACES_IMAGE_PIPE_PRODUCER_ENDPOINT_H_ |
OLD | NEW |