namespace ui {
+namespace {
+std::ostream& operator<<(std::ostream& stream,
+ OutputSurfaceState::State state) {
+ switch (state) {
+ case OutputSurfaceState::State::kNotInitialized:
+ stream << "not initialized";
+ break;
+ case OutputSurfaceState::State::kError:
+ stream << "error";
+ break;
+ case OutputSurfaceState::State::kActive:
+ stream << "active";
+ break;
+ case OutputSurfaceState::State::kIdle:
+ stream << "idle";
+ break;
+ case OutputSurfaceState::State::kRemoving:
+ stream << "removing";
+ break;
+ }
+ return stream;
+}
+} // namespace
+
bool OutputSurfaceState::Acquire(
bool allow_allocation,
base::OnceCallback<void(OutputSurface::Plane)> conflict_cb,
void OutputSurfaceState::Deinitialize(base::OnceClosure cb) {
TIZEN_MEDIA_LOG(INFO) << "Deinitialize surface: " << plane_;
+ switch (state_) {
+ case State::kError:
+ std::move(cb).Run();
+ return;
+ case State::kNotInitialized:
+ case State::kRemoving:
+ TIZEN_MEDIA_LOG(ERROR) << "Unexpected state: " << state_;
+ std::move(cb).Run();
+ return;
+ case State::kIdle:
+ case State::kActive:
+ break;
+ }
+
state_ = State::kRemoving;
removing_timer_.Stop();
Unregister();
void OutputSurfaceState::Reset() {
TIZEN_MEDIA_LOG(INFO) << "Remove surface: " << plane_;
- surface_->ReleaseResource();
- surface_ = nullptr;
+
+ switch (state_) {
+ case State::kError:
+ break;
+ case State::kNotInitialized:
+ case State::kIdle:
+ case State::kActive:
+ TIZEN_MEDIA_LOG(ERROR) << "Unexpected state: " << state_;
+ return;
+ case State::kRemoving:
+ surface_->ReleaseResource();
+ surface_ = nullptr;
+ break;
+ }
+
state_ = State::kNotInitialized;
}
base::OnceClosure cb,
scoped_refptr<base::SequencedTaskRunner> task_runner = nullptr);
void Deinitialize(base::OnceClosure cb);
+ // Completely removes surface, it won't be longer usable. Note that it should
+ // be done only after callback passed to |ScheduleRemoving| is triggered.
void Reset();
// Notify instance that resource underneath was taken and it should not
// allow further accessing it.
void MarkResourceTaken();
enum class State {
+ // Surface is not initialized and resource is not acquired.
kNotInitialized,
+ // After resource conflict or internal error of surface, cannot be longer
+ // reused.
kError,
kActive,
+ // Surface should be there, but it's inactive for some time. Note that
+ // |removing_timer_| should be active.
kIdle,
+ // Surface is under remove, it should not be used without reacquiring.
kRemoving,
};