blob: cb20fcc798054f919daaac3c7ca5a99e7808dd76 [file] [log] [blame]
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -07001/*
2 * Copyright 2016 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#ifndef ANDROID_SURFACEREPLAYER_BUFFERQUEUESCHEDULER_H
18#define ANDROID_SURFACEREPLAYER_BUFFERQUEUESCHEDULER_H
19
20#include "Color.h"
21#include "Event.h"
22
23#include <gui/SurfaceControl.h>
24
25#include <utils/StrongPointer.h>
26
27#include <atomic>
28#include <condition_variable>
29#include <mutex>
30#include <queue>
31#include <utility>
32
33namespace android {
34
35auto constexpr LAYER_ALPHA = 190;
36
37struct Dimensions {
38 Dimensions() = default;
39 Dimensions(int w, int h) : width(w), height(h) {}
40
41 int width = 0;
42 int height = 0;
43};
44
45struct BufferEvent {
46 BufferEvent() = default;
47 BufferEvent(std::shared_ptr<Event> e, Dimensions d) : event(e), dimensions(d) {}
48
49 std::shared_ptr<Event> event;
50 Dimensions dimensions;
51};
52
53class BufferQueueScheduler {
54 public:
Sahil Dhanju01041fe2016-08-08 20:27:23 -070055 BufferQueueScheduler(const sp<SurfaceControl>& surfaceControl, const HSV& color, int id);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -070056
57 void startScheduling();
58 void addEvent(const BufferEvent&);
59 void stopScheduling();
60
Sahil Dhanju01041fe2016-08-08 20:27:23 -070061 void setSurfaceControl(const sp<SurfaceControl>& surfaceControl, const HSV& color);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -070062
63 private:
64 void bufferUpdate(const Dimensions& dimensions);
65
66 // Lock and fill the surface, block until the event is signaled by the main loop,
67 // then unlock and post the buffer.
Sahil Dhanju01041fe2016-08-08 20:27:23 -070068 void fillSurface(const std::shared_ptr<Event>& event);
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -070069
70 sp<SurfaceControl> mSurfaceControl;
Sahil Dhanju01041fe2016-08-08 20:27:23 -070071 HSV mColor;
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -070072 const int mSurfaceId;
73
74 bool mContinueScheduling;
75
76 std::queue<BufferEvent> mBufferEvents;
77 std::mutex mMutex;
78 std::condition_variable mCondition;
79};
80
81} // namespace android
82#endif