blob: a4e7fc9b746125c38fd4269e2b64d0366382f05a [file] [log] [blame]
Sean Paulb386f1b2015-05-13 06:33:23 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "hwc-drm-compositor-worker"
18
Sean Paul98e73c82015-06-24 14:38:49 -070019#include "drmdisplaycompositor.h"
Sean Paulb386f1b2015-05-13 06:33:23 -070020#include "drmcompositorworker.h"
21#include "worker.h"
22
23#include <stdlib.h>
24
25#include <cutils/log.h>
26#include <hardware/hardware.h>
27
28namespace android {
29
Zach Reiznerbff33ac2015-11-16 11:08:46 -080030static const int64_t kSquashWait = 500000000LL;
31
Sean Paul98e73c82015-06-24 14:38:49 -070032DrmCompositorWorker::DrmCompositorWorker(DrmDisplayCompositor *compositor)
Sean Paulb386f1b2015-05-13 06:33:23 -070033 : Worker("drm-compositor", HAL_PRIORITY_URGENT_DISPLAY),
34 compositor_(compositor) {
35}
36
37DrmCompositorWorker::~DrmCompositorWorker() {
38}
39
40int DrmCompositorWorker::Init() {
41 return InitWorker();
42}
43
44void DrmCompositorWorker::Routine() {
45 int ret;
46 if (!compositor_->HaveQueuedComposites()) {
Adrian Salidofa37f672017-02-16 10:29:46 -080047 Lock();
Sean Paulb386f1b2015-05-13 06:33:23 -070048
Zach Reiznerbff33ac2015-11-16 11:08:46 -080049 // Only use a timeout if we didn't do a SquashAll last time. This will
50 // prevent wait_ret == -ETIMEDOUT which would trigger a SquashAll and be a
51 // pointless drain on resources.
52 int wait_ret = did_squash_all_ ? WaitForSignalOrExitLocked()
53 : WaitForSignalOrExitLocked(kSquashWait);
Adrian Salidofa37f672017-02-16 10:29:46 -080054 Unlock();
Sean Paulb386f1b2015-05-13 06:33:23 -070055
Zach Reiznerbff33ac2015-11-16 11:08:46 -080056 switch (wait_ret) {
57 case 0:
58 break;
59 case -EINTR:
60 return;
61 case -ETIMEDOUT:
62 ret = compositor_->SquashAll();
63 if (ret)
64 ALOGE("Failed to squash all %d", ret);
65 did_squash_all_ = true;
66 return;
67 default:
68 ALOGE("Failed to wait for signal, %d", wait_ret);
69 return;
Sean Paulb386f1b2015-05-13 06:33:23 -070070 }
71 }
72
73 ret = compositor_->Composite();
74 if (ret)
75 ALOGE("Failed to composite! %d", ret);
Zach Reiznerbff33ac2015-11-16 11:08:46 -080076 did_squash_all_ = false;
Sean Paulb386f1b2015-05-13 06:33:23 -070077}
78}