EventControlThread.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (C) 2013 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. #include "EventControlThread.h"
  17. #include "SurfaceFlinger.h"
  18. namespace android {
  19. EventControlThread::EventControlThread(const sp<SurfaceFlinger>& flinger):
  20. mFlinger(flinger),
  21. mVsyncEnabled(false) {
  22. }
  23. void EventControlThread::setVsyncEnabled(bool enabled) {
  24. Mutex::Autolock lock(mMutex);
  25. mVsyncEnabled = enabled;
  26. mCond.signal();
  27. }
  28. bool EventControlThread::threadLoop() {
  29. Mutex::Autolock lock(mMutex);
  30. bool vsyncEnabled = mVsyncEnabled;
  31. mFlinger->eventControl(HWC_DISPLAY_PRIMARY, SurfaceFlinger::EVENT_VSYNC,
  32. mVsyncEnabled);
  33. while (true) {
  34. status_t err = mCond.wait(mMutex);
  35. if (err != NO_ERROR) {
  36. ALOGE("error waiting for new events: %s (%d)",
  37. strerror(-err), err);
  38. return false;
  39. }
  40. if (vsyncEnabled != mVsyncEnabled) {
  41. mFlinger->eventControl(HWC_DISPLAY_PRIMARY,
  42. SurfaceFlinger::EVENT_VSYNC, mVsyncEnabled);
  43. vsyncEnabled = mVsyncEnabled;
  44. }
  45. }
  46. return false;
  47. }
  48. } // namespace android