1 // Copyright (C) 2022 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "DisplaySurface.h"
16
17 #include "Display.h"
18 #include "host-common/GfxstreamFatalError.h"
19 #include "host-common/logging.h"
20
21 namespace gfxstream {
22
23 using emugl::ABORT_REASON_OTHER;
24 using emugl::FatalError;
25
DisplaySurface(uint32_t width,uint32_t height,std::unique_ptr<DisplaySurfaceImpl> impl)26 DisplaySurface::DisplaySurface(uint32_t width,
27 uint32_t height,
28 std::unique_ptr<DisplaySurfaceImpl> impl)
29 : mWidth(width),
30 mHeight(height),
31 mImpl(std::move(impl)) {}
32
~DisplaySurface()33 DisplaySurface::~DisplaySurface() {
34 if (!mBoundUsers.empty()) {
35 GFXSTREAM_ABORT(FatalError(ABORT_REASON_OTHER))
36 << "DisplaySurface destroyed while there are still users!";
37 }
38 }
39
getWidth() const40 uint32_t DisplaySurface::getWidth() const {
41 std::lock_guard<std::mutex> lock(mParamsMutex);
42 return mWidth;
43 }
44
getHeight() const45 uint32_t DisplaySurface::getHeight() const {
46 std::lock_guard<std::mutex> lock(mParamsMutex);
47 return mHeight;
48 }
49
updateSize(uint32_t newWidth,uint32_t newHeight)50 void DisplaySurface::updateSize(uint32_t newWidth, uint32_t newHeight) {
51 {
52 std::lock_guard<std::mutex> lock(mParamsMutex);
53 if (mWidth != newWidth || mHeight != newHeight) {
54 mWidth = newWidth;
55 mHeight = newHeight;
56 }
57 }
58 for (auto & users : mBoundUsers) {
59 users->surfaceUpdated(this);
60 }
61 }
62
registerUser(DisplaySurfaceUser * user)63 void DisplaySurface::registerUser(DisplaySurfaceUser* user) {
64 mBoundUsers.insert(user);
65 }
66
unregisterUser(DisplaySurfaceUser * user)67 void DisplaySurface::unregisterUser(DisplaySurfaceUser* user) {
68 mBoundUsers.erase(user);
69 }
70
71 } // namespace gfxstream
72