Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: mojo/services/gfx/images/cpp/image_pipe_producer_endpoint.cc

Issue 1595773002: Added ImagePipe (Closed) Base URL: https://github.com/domokit/mojo.git@submit-2
Patch Set: Expose InterfacePtr::encountered_error() through ImagePipeProducerEndpoint so the GL on ImagePipe i… Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 : state_tacker_(true, [this]() { CloseEndpoint(); }),
18 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) {
26 return state_tacker_.AcquireNextImage(id);
27 }
28
29 bool ImagePipeProducerEndpoint::AcquireImageBlocking(uint32_t& id,
30 MojoDeadline deadline) {
31 MojoDeadline remaining_deadline_ = deadline;
32 bool have_image = false;
33 do {
34 have_image = state_tacker_.AcquireNextImage(id);
35 if (!have_image && remaining_deadline_ > 0) {
36 if (image_pipe_ptr_.encountered_error())
37 break;
38 MojoTimeTicks wait_start = MojoGetTimeTicksNow();
39 image_pipe_ptr_.WaitForIncomingResponseWithTimeout(remaining_deadline_);
40 MojoTimeTicks wait_end = MojoGetTimeTicksNow();
41 MojoTimeTicks wait_time = wait_end - wait_start;
42
43 MOJO_DCHECK(wait_time >= 0);
44
45 if (static_cast<MojoDeadline>(wait_time) > remaining_deadline_) {
46 remaining_deadline_ = 0; // just to be safe
47 } else {
48 remaining_deadline_ -= wait_time;
49 }
50
51 if (image_pipe_ptr_.encountered_error())
52 break;
53 }
54 } while (!have_image);
55
56 return have_image;
57 }
58
59 void ImagePipeProducerEndpoint::AddImage(mojo::gfx::ImagePtr image,
60 uint32_t id) {
61 state_tacker_.ProducerAdd(id);
62 image_pipe_ptr_->AddImage(image.Pass(), id);
63 }
64
65 void ImagePipeProducerEndpoint::RemoveImage(uint32_t id) {
66 state_tacker_.ProducerRemove(id);
67 image_pipe_ptr_->RemoveImage(id);
68 }
69
70 void ImagePipeProducerEndpoint::ConsumerReleaseInternal(
71 uint32_t id,
72 mojo::gfx::PresentationStatus status) {
73 state_tacker_.ConsumerRelease(id, status);
74 }
75
76 void ImagePipeProducerEndpoint::PresentImage(
77 uint32_t id,
78 const PresentImageCallback& callback) {
79 state_tacker_.ProducerPresent(id, callback);
80 image_pipe_ptr_->PresentImage(
81 id, [this](uint32_t id, mojo::gfx::PresentationStatus status) {
82 ConsumerReleaseInternal(id, status);
83 });
84 }
85
86 void ImagePipeProducerEndpoint::FlushImages() {
87 state_tacker_.ProducerFlush();
88 image_pipe_ptr_->FlushImages();
89 }
90
91 void ImagePipeProducerEndpoint::GetSupportedImageProperties(
92 const GetSupportedImagePropertiesCallback& callback) {
93 image_pipe_ptr_->GetSupportedImageProperties(callback);
94 }
95
96 void ImagePipeProducerEndpoint::DisableFatalErrors() {
97 state_tacker_.DisableFatalErrors();
98 }
99
100 bool ImagePipeProducerEndpoint::HasEncounteredError(){
101 return image_pipe_ptr_.encountered_error();
102 }
103
104 } // namespace image_pipe
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698