HWComposer.h revision 2965b26022f95051f65b09d7eac47cbe923855c9
1a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian/* 2a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * Copyright (C) 2010 The Android Open Source Project 3a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * 4a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * Licensed under the Apache License, Version 2.0 (the "License"); 5a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * you may not use this file except in compliance with the License. 6a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * You may obtain a copy of the License at 7a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * 8a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * http://www.apache.org/licenses/LICENSE-2.0 9a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * 10a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * Unless required by applicable law or agreed to in writing, software 11a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * distributed under the License is distributed on an "AS IS" BASIS, 12a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * See the License for the specific language governing permissions and 14a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian * limitations under the License. 15a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian */ 16a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 17a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#ifndef ANDROID_SF_HWCOMPOSER_H 18a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#define ANDROID_SF_HWCOMPOSER_H 19a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 20a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include <stdint.h> 21a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include <sys/types.h> 22a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 23a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include <EGL/egl.h> 24a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 25a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#include <hardware/hwcomposer.h> 26a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 27c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian#include <utils/StrongPointer.h> 2822da60c3e64cd57535cbba063c07127814a2b52fMathias Agopian#include <utils/Vector.h> 29c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian 303eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopianextern "C" int clock_nanosleep(clockid_t clock_id, int flags, 313eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian const struct timespec *request, 323eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian struct timespec *remain); 333eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian 34a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopiannamespace android { 35a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian// --------------------------------------------------------------------------- 36a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 378372785879d329f592f6883620b5a32d80d74691Mathias Agopianclass String8; 38c7d14e247117392fbd44aa454622778a25c076aeMathias Agopianclass SurfaceFlinger; 3922da60c3e64cd57535cbba063c07127814a2b52fMathias Agopianclass LayerBase; 408372785879d329f592f6883620b5a32d80d74691Mathias Agopian 41a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopianclass HWComposer 42a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian{ 43a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopianpublic: 443eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian class EventHandler { 453eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian friend class HWComposer; 463eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian virtual void onVSyncReceived(int dpy, nsecs_t timestamp) = 0; 473eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian protected: 483eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian virtual ~EventHandler() {} 493eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian }; 50a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 513eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian HWComposer(const sp<SurfaceFlinger>& flinger, 523eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian EventHandler& handler, nsecs_t refreshPeriod); 53a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian ~HWComposer(); 54a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 55a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian status_t initCheck() const; 56a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 57a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian // tells the HAL what the framebuffer is 58a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian void setFrameBuffer(EGLDisplay dpy, EGLSurface sur); 59a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 603eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian // create a work list for numLayers layer. sets HWC_GEOMETRY_CHANGED. 61a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian status_t createWorkList(size_t numLayers); 62a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 63a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian // Asks the HAL what it can do 64a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian status_t prepare() const; 65a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 667ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian // disable hwc until next createWorkList 677ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian status_t disable(); 687ee4cd5556cef1878e1d4729f1b389f186311027Mathias Agopian 69a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian // commits the list 70a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian status_t commit() const; 71a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 72f5f2712854599b4970643c6000fe6ae950a08ba9Antti Hatala // release hardware resources 73f5f2712854599b4970643c6000fe6ae950a08ba9Antti Hatala status_t release() const; 74a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 753eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian // get the layer array created by createWorkList() 7645721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian size_t getNumLayers() const; 7745721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian hwc_layer_t* getLayers() const; 78a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 793eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian // get number of layers of the given type as updated in prepare(). 803eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian // type is HWC_OVERLAY or HWC_FRAMEBUFFER 819c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian size_t getLayerCount(int type) const; 829c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian 833eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian // Events handling --------------------------------------------------------- 843eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian 853eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian enum { 863eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian EVENT_VSYNC = HWC_EVENT_VSYNC 873eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian }; 883eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian 893eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian status_t eventControl(int event, int enabled); 903eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian 913eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian // this class is only used to fake the VSync event on systems that don't 923eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian // have it. 933eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian class VSyncThread : public Thread { 943eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian HWComposer& mHwc; 953eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian mutable Mutex mLock; 963eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian Condition mCondition; 973eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian bool mEnabled; 983eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian mutable nsecs_t mNextFakeVSync; 993eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian nsecs_t mRefreshPeriod; 1002965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian virtual void onFirstRef(); 1012965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian virtual bool threadLoop(); 1023eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian public: 1032965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian VSyncThread(HWComposer& hwc); 1042965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian void setEnabled(bool enabled); 1053eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian }; 1063eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian 1073eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian friend class VSyncThread; 1083eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian 1093eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian // for debugging ---------------------------------------------------------- 11022da60c3e64cd57535cbba063c07127814a2b52fMathias Agopian void dump(String8& out, char* scratch, size_t SIZE, 11122da60c3e64cd57535cbba063c07127814a2b52fMathias Agopian const Vector< sp<LayerBase> >& visibleLayersSortedByZ) const; 1128372785879d329f592f6883620b5a32d80d74691Mathias Agopian 113a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopianprivate: 11431d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian 11531d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian struct callbacks : public hwc_procs_t { 11631d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian // these are here to facilitate the transition when adding 11731d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian // new callbacks (an implementation can check for NULL before 11831d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian // calling a new callback). 11931d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian void (*zero[4])(void); 12031d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian }; 12131d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian 122c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian struct cb_context { 12331d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian callbacks procs; 124c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian HWComposer* hwc; 125c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian }; 12631d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian 127c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian static void hook_invalidate(struct hwc_procs* procs); 12831d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian static void hook_vsync(struct hwc_procs* procs, int dpy, int64_t timestamp); 12931d2843b45ebdb69ec3355111b7567363fd2a6b7Mathias Agopian 1303eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian inline void invalidate(); 1313eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian inline void vsync(int dpy, int64_t timestamp); 132c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian 133c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian sp<SurfaceFlinger> mFlinger; 134a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian hw_module_t const* mModule; 135a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian hwc_composer_device_t* mHwc; 136a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian hwc_layer_list_t* mList; 13745721773e1a68e96da4b6cc04cef276bae7ca3e9Mathias Agopian size_t mCapacity; 1389c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian mutable size_t mNumOVLayers; 1399c6e297271ec9af9d974242d89cfa08cb6ceaa0aMathias Agopian mutable size_t mNumFBLayers; 140a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian hwc_display_t mDpy; 141a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian hwc_surface_t mSur; 142c7d14e247117392fbd44aa454622778a25c076aeMathias Agopian cb_context mCBContext; 1433eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian EventHandler& mEventHandler; 1443eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian nsecs_t mRefreshPeriod; 1452965b26022f95051f65b09d7eac47cbe923855c9Mathias Agopian size_t mVSyncCount; 1463eb38cb33e41ce40dd1094bdec850f0fca9f8a53Mathias Agopian sp<VSyncThread> mVSyncThread; 147a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian}; 148a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 149a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 150a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian// --------------------------------------------------------------------------- 151a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian}; // namespace android 152a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian 153a350ff98692b3a50cad5cc93f9f83221242ca86aMathias Agopian#endif // ANDROID_SF_HWCOMPOSER_H 154