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 "Display.h" 16 17 #include "DisplaySurface.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 ~DisplaySurfaceUser()26DisplaySurfaceUser::~DisplaySurfaceUser() { 27 if (mBoundSurface != nullptr) { 28 GFXSTREAM_ABORT(FatalError(ABORT_REASON_OTHER)) 29 << "Failed to unbind a DisplaySurface before DisplaySurfaceUser destruction."; 30 } 31 } 32 bindToSurface(DisplaySurface * surface)33void DisplaySurfaceUser::bindToSurface(DisplaySurface* surface) { 34 if (mBoundSurface != nullptr) { 35 GFXSTREAM_ABORT(FatalError(ABORT_REASON_OTHER)) 36 << "Attempting to bind a DisplaySurface while another is already bound."; 37 } 38 39 this->bindToSurfaceImpl(surface); 40 surface->registerUser(this); 41 mBoundSurface = surface; 42 } 43 unbindFromSurface()44void DisplaySurfaceUser::unbindFromSurface() { 45 this->unbindFromSurfaceImpl(); 46 if (mBoundSurface != nullptr) { 47 mBoundSurface->unregisterUser(this); 48 mBoundSurface = nullptr; 49 } 50 } 51 52 } // namespace gfxstream 53