HWComposer.h revision 41d67d7ab4da1c393497a620a116a854b3c618e7
1682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns/* 2682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns * Copyright (C) 2010 The Android Open Source Project 3682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns * 4682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns * Licensed under the Apache License, Version 2.0 (the "License"); 5682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns * you may not use this file except in compliance with the License. 6682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns * You may obtain a copy of the License at 7682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns * 8682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns * http://www.apache.org/licenses/LICENSE-2.0 9682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns * 10682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns * Unless required by applicable law or agreed to in writing, software 11682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns * distributed under the License is distributed on an "AS IS" BASIS, 12682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns * See the License for the specific language governing permissions and 14682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns * limitations under the License. 15682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns */ 16682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns 17682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns#ifndef ANDROID_SF_HWCOMPOSER_H 18682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns#define ANDROID_SF_HWCOMPOSER_H 19682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns 20682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns#include <stdint.h> 21682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns#include <sys/types.h> 22682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns 23682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns#include <hardware/hwcomposer_defs.h> 24682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns 25682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns#include <ui/Fence.h> 26682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns 27682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns#include <utils/BitSet.h> 28682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns#include <utils/Condition.h> 29682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns#include <utils/Mutex.h> 30682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns#include <utils/StrongPointer.h> 31682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns#include <utils/Thread.h> 32682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns#include <utils/Timers.h> 33682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns#include <utils/Vector.h> 34682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns 35682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johnsextern "C" int clock_nanosleep(clockid_t clock_id, int flags, 36682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns const struct timespec *request, 37682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns struct timespec *remain); 38682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns 39682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johnsstruct hwc_composer_device_1; 40682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johnsstruct hwc_display_contents_1; 41682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johnsstruct hwc_layer_1; 42682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johnsstruct hwc_procs; 43682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johnsstruct framebuffer_device_t; 44682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns 45682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johnsnamespace android { 46682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns// --------------------------------------------------------------------------- 47682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns 48682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johnsclass Fence; 49682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johnsclass FloatRect; 50682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johnsclass GraphicBuffer; 51682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johnsclass NativeHandle; 52682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johnsclass Region; 53682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johnsclass String8; 54682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johnsclass SurfaceFlinger; 55682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns 56682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johnsclass HWComposer 57682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns{ 58682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johnspublic: 59682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns class EventHandler { 60682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns friend class HWComposer; 61682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns virtual void onVSyncReceived(int disp, nsecs_t timestamp) = 0; 62682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns virtual void onHotplugReceived(int disp, bool connected) = 0; 63682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns protected: 64682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns virtual ~EventHandler() {} 65682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns }; 66682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns 67682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns enum { 68682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns NUM_BUILTIN_DISPLAYS = HWC_NUM_PHYSICAL_DISPLAY_TYPES, 69682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns MAX_HWC_DISPLAYS = HWC_NUM_DISPLAY_TYPES, 70682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns VIRTUAL_DISPLAY_ID_BASE = HWC_DISPLAY_VIRTUAL, 71682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns }; 72682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns 73682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns HWComposer( 74682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns const sp<SurfaceFlinger>& flinger, 75682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns EventHandler& handler); 76682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns 77682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns ~HWComposer(); 78682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns 79682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns status_t initCheck() const; 80682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns 81682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns // Returns a display ID starting at VIRTUAL_DISPLAY_ID_BASE, this ID is to 82682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns // be used with createWorkList (and all other methods requiring an ID 83682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns // below). 84682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns // IDs below NUM_BUILTIN_DISPLAYS are pre-defined and therefore are 85682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns // always valid. 86682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns // Returns -1 if an ID cannot be allocated 87682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns int32_t allocateDisplayId(); 88682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns 89682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns // Recycles the given virtual display ID and frees the associated worklist. 90682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns // IDs below NUM_BUILTIN_DISPLAYS are not recycled. 91682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns status_t freeDisplayId(int32_t id); 92682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns 93682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns 94682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns // Asks the HAL what it can do 95682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns status_t prepare(); 96682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns 97682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns // commits the list 98682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns status_t commit(); 99682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns 100682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns // release hardware resources and blank screen 101682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns status_t release(int disp); 102682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns 103682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns // acquire hardware resources and unblank screen 104682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns status_t acquire(int disp); 105682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns 106682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns // reset state when an external, non-virtual display is disconnected 107682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns void disconnectDisplay(int disp); 108682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns 109682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns // create a work list for numLayers layer. sets HWC_GEOMETRY_CHANGED. 110682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns status_t createWorkList(int32_t id, size_t numLayers); 111682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns 112682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns bool supportsFramebufferTarget() const; 113682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns 114682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns // does this display have layers handled by HWC 115682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns bool hasHwcComposition(int32_t id) const; 116682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns 117682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns // does this display have layers handled by GLES 118682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns bool hasGlesComposition(int32_t id) const; 119682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns 120682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns // get the releaseFence file descriptor for a display's framebuffer layer. 121682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns // the release fence is only valid after commit() 122682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns sp<Fence> getAndResetReleaseFence(int32_t id); 123682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns 124682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns // needed forward declarations 125682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns class LayerListIterator; 126682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns 127682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns // return the visual id to be used to find a suitable EGLConfig for 128682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns // *ALL* displays. 129682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns int getVisualID() const; 130682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns 131682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns // Forwarding to FB HAL for pre-HWC-1.1 code (see FramebufferSurface). 132682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns int fbPost(int32_t id, const sp<Fence>& acquireFence, const sp<GraphicBuffer>& buf); 133682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns int fbCompositionComplete(); 134682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns void fbDump(String8& result); 135682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns 136682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns // Set the output buffer and acquire fence for a virtual display. 137682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns // Returns INVALID_OPERATION if id is not a virtual display. 138682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns status_t setOutputBuffer(int32_t id, const sp<Fence>& acquireFence, 139682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns const sp<GraphicBuffer>& buf); 140682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns 141682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns // Get the retire fence for the last committed frame. This fence will 142682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns // signal when the h/w composer is completely finished with the frame. 143682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns // For physical displays, it is no longer being displayed. For virtual 144682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns // displays, writes to the output buffer are complete. 145682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns sp<Fence> getLastRetireFence(int32_t id) const; 146682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns 147682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns /* 148682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns * Interface to hardware composer's layers functionality. 149682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns * This abstracts the HAL interface to layers which can evolve in 150682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns * incompatible ways from one release to another. 151682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns * The idea is that we could extend this interface as we add 152682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns * features to h/w composer. 153682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns */ 154682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns class HWCLayerInterface { 155682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns protected: 156682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns virtual ~HWCLayerInterface() { } 157682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns public: 158682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns virtual int32_t getCompositionType() const = 0; 159682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns virtual uint32_t getHints() const = 0; 160682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns virtual sp<Fence> getAndResetReleaseFence() = 0; 161682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns virtual void setDefaultState() = 0; 162682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns virtual void setSkip(bool skip) = 0; 163682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns virtual void setBlending(uint32_t blending) = 0; 164682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns virtual void setTransform(uint32_t transform) = 0; 165682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns virtual void setFrame(const Rect& frame) = 0; 166682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns virtual void setCrop(const FloatRect& crop) = 0; 167682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns virtual void setVisibleRegionScreen(const Region& reg) = 0; 168682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns virtual void setSidebandStream(const sp<NativeHandle>& stream) = 0; 169682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns virtual void setBuffer(const sp<GraphicBuffer>& buffer) = 0; 170682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns virtual void setAcquireFenceFd(int fenceFd) = 0; 171682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns virtual void setPlaneAlpha(uint8_t alpha) = 0; 172682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns virtual void onDisplayed() = 0; 173682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns }; 174682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns 175682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns /* 176682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns * Interface used to implement an iterator to a list 177682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns * of HWCLayer. 178682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns */ 179682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns class HWCLayer : public HWCLayerInterface { 180682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns friend class LayerListIterator; 181682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns // select the layer at the given index 182682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns virtual status_t setLayer(size_t index) = 0; 183682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns virtual HWCLayer* dup() = 0; 184682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns static HWCLayer* copy(HWCLayer *rhs) { 185682c24e22811d4ee17ae1cd61bf255c3f7e722b7Trevor Johns return rhs ? rhs->dup() : NULL; 186 } 187 protected: 188 virtual ~HWCLayer() { } 189 }; 190 191 /* 192 * Iterator through a HWCLayer list. 193 * This behaves more or less like a forward iterator. 194 */ 195 class LayerListIterator { 196 friend struct HWComposer; 197 HWCLayer* const mLayerList; 198 size_t mIndex; 199 200 LayerListIterator() : mLayerList(NULL), mIndex(0) { } 201 202 LayerListIterator(HWCLayer* layer, size_t index) 203 : mLayerList(layer), mIndex(index) { } 204 205 // we don't allow assignment, because we don't need it for now 206 LayerListIterator& operator = (const LayerListIterator& rhs); 207 208 public: 209 // copy operators 210 LayerListIterator(const LayerListIterator& rhs) 211 : mLayerList(HWCLayer::copy(rhs.mLayerList)), mIndex(rhs.mIndex) { 212 } 213 214 ~LayerListIterator() { delete mLayerList; } 215 216 // pre-increment 217 LayerListIterator& operator++() { 218 mLayerList->setLayer(++mIndex); 219 return *this; 220 } 221 222 // dereference 223 HWCLayerInterface& operator * () { return *mLayerList; } 224 HWCLayerInterface* operator -> () { return mLayerList; } 225 226 // comparison 227 bool operator == (const LayerListIterator& rhs) const { 228 return mIndex == rhs.mIndex; 229 } 230 bool operator != (const LayerListIterator& rhs) const { 231 return !operator==(rhs); 232 } 233 }; 234 235 // Returns an iterator to the beginning of the layer list 236 LayerListIterator begin(int32_t id); 237 238 // Returns an iterator to the end of the layer list 239 LayerListIterator end(int32_t id); 240 241 242 // Events handling --------------------------------------------------------- 243 244 enum { 245 EVENT_VSYNC = HWC_EVENT_VSYNC 246 }; 247 248 void eventControl(int disp, int event, int enabled); 249 250 // Query display parameters. Pass in a display index (e.g. 251 // HWC_DISPLAY_PRIMARY). 252 nsecs_t getRefreshPeriod(int disp) const; 253 nsecs_t getRefreshTimestamp(int disp) const; 254 sp<Fence> getDisplayFence(int disp) const; 255 uint32_t getWidth(int disp) const; 256 uint32_t getHeight(int disp) const; 257 uint32_t getFormat(int disp) const; 258 float getDpiX(int disp) const; 259 float getDpiY(int disp) const; 260 bool isConnected(int disp) const; 261 262 status_t setVirtualDisplayProperties(int32_t id, uint32_t w, uint32_t h, 263 uint32_t format); 264 265 // this class is only used to fake the VSync event on systems that don't 266 // have it. 267 class VSyncThread : public Thread { 268 HWComposer& mHwc; 269 mutable Mutex mLock; 270 Condition mCondition; 271 bool mEnabled; 272 mutable nsecs_t mNextFakeVSync; 273 nsecs_t mRefreshPeriod; 274 virtual void onFirstRef(); 275 virtual bool threadLoop(); 276 public: 277 VSyncThread(HWComposer& hwc); 278 void setEnabled(bool enabled); 279 }; 280 281 friend class VSyncThread; 282 283 // for debugging ---------------------------------------------------------- 284 void dump(String8& out) const; 285 286private: 287 void loadHwcModule(); 288 int loadFbHalModule(); 289 290 LayerListIterator getLayerIterator(int32_t id, size_t index); 291 292 struct cb_context; 293 294 static void hook_invalidate(const struct hwc_procs* procs); 295 static void hook_vsync(const struct hwc_procs* procs, int disp, 296 int64_t timestamp); 297 static void hook_hotplug(const struct hwc_procs* procs, int disp, 298 int connected); 299 300 inline void invalidate(); 301 inline void vsync(int disp, int64_t timestamp); 302 inline void hotplug(int disp, int connected); 303 304 status_t queryDisplayProperties(int disp); 305 306 status_t setFramebufferTarget(int32_t id, 307 const sp<Fence>& acquireFence, const sp<GraphicBuffer>& buf); 308 309 310 struct DisplayData { 311 DisplayData(); 312 ~DisplayData(); 313 uint32_t width; 314 uint32_t height; 315 uint32_t format; // pixel format from FB hal, for pre-hwc-1.1 316 float xdpi; 317 float ydpi; 318 nsecs_t refresh; 319 bool connected; 320 bool hasFbComp; 321 bool hasOvComp; 322 size_t capacity; 323 hwc_display_contents_1* list; 324 hwc_layer_1* framebufferTarget; 325 buffer_handle_t fbTargetHandle; 326 sp<Fence> lastRetireFence; // signals when the last set op retires 327 sp<Fence> lastDisplayFence; // signals when the last set op takes 328 // effect on screen 329 buffer_handle_t outbufHandle; 330 sp<Fence> outbufAcquireFence; 331 332 // protected by mEventControlLock 333 int32_t events; 334 }; 335 336 sp<SurfaceFlinger> mFlinger; 337 framebuffer_device_t* mFbDev; 338 struct hwc_composer_device_1* mHwc; 339 // invariant: mLists[0] != NULL iff mHwc != NULL 340 // mLists[i>0] can be NULL. that display is to be ignored 341 struct hwc_display_contents_1* mLists[MAX_HWC_DISPLAYS]; 342 DisplayData mDisplayData[MAX_HWC_DISPLAYS]; 343 size_t mNumDisplays; 344 345 cb_context* mCBContext; 346 EventHandler& mEventHandler; 347 size_t mVSyncCounts[HWC_NUM_PHYSICAL_DISPLAY_TYPES]; 348 sp<VSyncThread> mVSyncThread; 349 bool mDebugForceFakeVSync; 350 BitSet32 mAllocatedDisplayIDs; 351 352 // protected by mLock 353 mutable Mutex mLock; 354 mutable nsecs_t mLastHwVSync[HWC_NUM_PHYSICAL_DISPLAY_TYPES]; 355 356 // thread-safe 357 mutable Mutex mEventControlLock; 358}; 359 360// --------------------------------------------------------------------------- 361}; // namespace android 362 363#endif // ANDROID_SF_HWCOMPOSER_H 364