HWC2On1Adapter.h revision 076ac670262e448c531e6db7727cfade325866ca
1/* 2 * Copyright 2015 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 17#ifndef ANDROID_SF_HWC2_ON_1_ADAPTER_H 18#define ANDROID_SF_HWC2_ON_1_ADAPTER_H 19 20#define HWC2_INCLUDE_STRINGIFICATION 21#define HWC2_USE_CPP11 22#include <hardware/hwcomposer2.h> 23#undef HWC2_INCLUDE_STRINGIFICATION 24#undef HWC2_USE_CPP11 25 26#include <ui/Fence.h> 27 28#include <atomic> 29#include <map> 30#include <mutex> 31#include <queue> 32#include <set> 33#include <unordered_map> 34#include <unordered_set> 35#include <vector> 36 37struct hwc_composer_device_1; 38struct hwc_display_contents_1; 39struct hwc_layer_1; 40 41namespace android { 42 43class HWC2On1Adapter : public hwc2_device_t 44{ 45public: 46 HWC2On1Adapter(struct hwc_composer_device_1* hwc1Device); 47 ~HWC2On1Adapter(); 48 49 struct hwc_composer_device_1* getHwc1Device() const { return mHwc1Device; } 50 uint8_t getHwc1MinorVersion() const { return mHwc1MinorVersion; } 51 52private: 53 static inline HWC2On1Adapter* getAdapter(hwc2_device_t* device) { 54 return static_cast<HWC2On1Adapter*>(device); 55 } 56 57 // getCapabilities 58 59 void doGetCapabilities(uint32_t* outCount, 60 int32_t* /*hwc2_capability_t*/ outCapabilities); 61 static void getCapabilitiesHook(hwc2_device_t* device, uint32_t* outCount, 62 int32_t* /*hwc2_capability_t*/ outCapabilities) { 63 getAdapter(device)->doGetCapabilities(outCount, outCapabilities); 64 } 65 66 // getFunction 67 68 hwc2_function_pointer_t doGetFunction(HWC2::FunctionDescriptor descriptor); 69 static hwc2_function_pointer_t getFunctionHook(hwc2_device_t* device, 70 int32_t intDesc) { 71 auto descriptor = static_cast<HWC2::FunctionDescriptor>(intDesc); 72 return getAdapter(device)->doGetFunction(descriptor); 73 } 74 75 // Device functions 76 77 HWC2::Error createVirtualDisplay(uint32_t width, uint32_t height, 78 hwc2_display_t* outDisplay); 79 static int32_t createVirtualDisplayHook(hwc2_device_t* device, 80 uint32_t width, uint32_t height, hwc2_display_t* outDisplay) { 81 auto error = getAdapter(device)->createVirtualDisplay(width, height, 82 outDisplay); 83 return static_cast<int32_t>(error); 84 } 85 86 HWC2::Error destroyVirtualDisplay(hwc2_display_t display); 87 static int32_t destroyVirtualDisplayHook(hwc2_device_t* device, 88 hwc2_display_t display) { 89 auto error = getAdapter(device)->destroyVirtualDisplay(display); 90 return static_cast<int32_t>(error); 91 } 92 93 std::string mDumpString; 94 void dump(uint32_t* outSize, char* outBuffer); 95 static void dumpHook(hwc2_device_t* device, uint32_t* outSize, 96 char* outBuffer) { 97 getAdapter(device)->dump(outSize, outBuffer); 98 } 99 100 uint32_t getMaxVirtualDisplayCount(); 101 static uint32_t getMaxVirtualDisplayCountHook(hwc2_device_t* device) { 102 return getAdapter(device)->getMaxVirtualDisplayCount(); 103 } 104 105 HWC2::Error registerCallback(HWC2::Callback descriptor, 106 hwc2_callback_data_t callbackData, hwc2_function_pointer_t pointer); 107 static int32_t registerCallbackHook(hwc2_device_t* device, 108 int32_t intDesc, hwc2_callback_data_t callbackData, 109 hwc2_function_pointer_t pointer) { 110 auto descriptor = static_cast<HWC2::Callback>(intDesc); 111 auto error = getAdapter(device)->registerCallback(descriptor, 112 callbackData, pointer); 113 return static_cast<int32_t>(error); 114 } 115 116 // Display functions 117 118 class Layer; 119 120 class SortLayersByZ { 121 public: 122 bool operator()(const std::shared_ptr<Layer>& lhs, 123 const std::shared_ptr<Layer>& rhs); 124 }; 125 126 class DisplayContentsDeleter { 127 public: 128 void operator()(struct hwc_display_contents_1* contents); 129 }; 130 131 class DeferredFence { 132 public: 133 DeferredFence() 134 : mMutex(), 135 mFences({Fence::NO_FENCE, Fence::NO_FENCE}) {} 136 137 void add(int32_t fenceFd) { 138 mFences.emplace(new Fence(fenceFd)); 139 mFences.pop(); 140 } 141 142 const sp<Fence>& get() const { 143 return mFences.front(); 144 } 145 146 private: 147 mutable std::mutex mMutex; 148 std::queue<sp<Fence>> mFences; 149 }; 150 151 class FencedBuffer { 152 public: 153 FencedBuffer() : mBuffer(nullptr), mFence(Fence::NO_FENCE) {} 154 155 void setBuffer(buffer_handle_t buffer) { mBuffer = buffer; } 156 void setFence(int fenceFd) { mFence = new Fence(fenceFd); } 157 158 buffer_handle_t getBuffer() const { return mBuffer; } 159 int getFence() const { return mFence->dup(); } 160 161 private: 162 buffer_handle_t mBuffer; 163 sp<Fence> mFence; 164 }; 165 166 class Display { 167 public: 168 typedef std::unique_ptr<hwc_display_contents_1, 169 DisplayContentsDeleter> HWC1Contents; 170 171 Display(HWC2On1Adapter& device, HWC2::DisplayType type); 172 173 hwc2_display_t getId() const { return mId; } 174 HWC2On1Adapter& getDevice() const { return mDevice; } 175 176 // Does not require locking because it is set before adding the 177 // Displays to the Adapter's list of displays 178 void setHwc1Id(int32_t id) { mHwc1Id = id; } 179 int32_t getHwc1Id() const { return mHwc1Id; } 180 181 void incDirty() { ++mDirtyCount; } 182 void decDirty() { --mDirtyCount; } 183 bool isDirty() const { return mDirtyCount > 0 || mZIsDirty; } 184 185 // HWC2 Display functions 186 HWC2::Error acceptChanges(); 187 HWC2::Error createLayer(hwc2_layer_t* outLayerId); 188 HWC2::Error destroyLayer(hwc2_layer_t layerId); 189 HWC2::Error getActiveConfig(hwc2_config_t* outConfigId); 190 HWC2::Error getAttribute(hwc2_config_t configId, 191 HWC2::Attribute attribute, int32_t* outValue); 192 HWC2::Error getChangedCompositionTypes(uint32_t* outNumElements, 193 hwc2_layer_t* outLayers, int32_t* outTypes); 194 HWC2::Error getColorModes(uint32_t* outNumModes, int32_t* outModes); 195 HWC2::Error getConfigs(uint32_t* outNumConfigs, 196 hwc2_config_t* outConfigIds); 197 HWC2::Error getDozeSupport(int32_t* outSupport); 198 HWC2::Error getHdrCapabilities(uint32_t* outNumTypes, 199 int32_t* outTypes, float* outMaxLuminance, 200 float* outMaxAverageLuminance, float* outMinLuminance); 201 HWC2::Error getName(uint32_t* outSize, char* outName); 202 HWC2::Error getReleaseFences(uint32_t* outNumElements, 203 hwc2_layer_t* outLayers, int32_t* outFences); 204 HWC2::Error getRequests(int32_t* outDisplayRequests, 205 uint32_t* outNumElements, hwc2_layer_t* outLayers, 206 int32_t* outLayerRequests); 207 HWC2::Error getType(int32_t* outType); 208 HWC2::Error present(int32_t* outRetireFence); 209 HWC2::Error setActiveConfig(hwc2_config_t configId); 210 HWC2::Error setClientTarget(buffer_handle_t target, 211 int32_t acquireFence, int32_t dataspace); 212 HWC2::Error setColorMode(int32_t mode); 213 HWC2::Error setColorTransform(android_color_transform_t hint); 214 HWC2::Error setOutputBuffer(buffer_handle_t buffer, 215 int32_t releaseFence); 216 HWC2::Error setPowerMode(HWC2::PowerMode mode); 217 HWC2::Error setVsyncEnabled(HWC2::Vsync enabled); 218 HWC2::Error validate(uint32_t* outNumTypes, 219 uint32_t* outNumRequests); 220 221 HWC2::Error updateLayerZ(hwc2_layer_t layerId, uint32_t z); 222 223 // Read configs from HWC1 device 224 void populateConfigs(); 225 226 // Set configs for a virtual display 227 void populateConfigs(uint32_t width, uint32_t height); 228 229 bool prepare(); 230 HWC1Contents cloneRequestedContents() const; 231 void setReceivedContents(HWC1Contents contents); 232 bool hasChanges() const; 233 HWC2::Error set(hwc_display_contents_1& hwcContents); 234 void addRetireFence(int fenceFd); 235 void addReleaseFences(const hwc_display_contents_1& hwcContents); 236 237 bool hasColorTransform() const; 238 239 std::string dump() const; 240 241 private: 242 class Config { 243 public: 244 Config(Display& display) 245 : mDisplay(display), 246 mAttributes() {} 247 248 bool isOnDisplay(const Display& display) const { 249 return display.getId() == mDisplay.getId(); 250 } 251 252 void setAttribute(HWC2::Attribute attribute, int32_t value); 253 int32_t getAttribute(HWC2::Attribute attribute) const; 254 255 void setHwc1Id(uint32_t id); 256 bool hasHwc1Id(uint32_t id) const; 257 int32_t getColorModeForHwc1Id(uint32_t id) const; 258 HWC2::Error getHwc1IdForColorMode(int32_t mode, 259 uint32_t* outId) const; 260 261 void setId(hwc2_config_t id) { mId = id; } 262 hwc2_config_t getId() const { return mId; } 263 264 // Attempts to merge two configs that differ only in color 265 // mode. Returns whether the merge was successful 266 bool merge(const Config& other); 267 268 std::set<int32_t> getColorTransforms() const; 269 270 // splitLine divides the output into two lines suitable for 271 // dumpsys SurfaceFlinger 272 std::string toString(bool splitLine = false) const; 273 274 private: 275 Display& mDisplay; 276 hwc2_config_t mId; 277 std::unordered_map<HWC2::Attribute, int32_t> mAttributes; 278 279 // Maps from color transform to HWC1 config ID 280 std::unordered_map<int32_t, uint32_t> mHwc1Ids; 281 }; 282 283 class Changes { 284 public: 285 uint32_t getNumTypes() const { 286 return static_cast<uint32_t>(mTypeChanges.size()); 287 } 288 289 uint32_t getNumLayerRequests() const { 290 return static_cast<uint32_t>(mLayerRequests.size()); 291 } 292 293 const std::unordered_map<hwc2_layer_t, HWC2::Composition>& 294 getTypeChanges() const { 295 return mTypeChanges; 296 } 297 298 const std::unordered_map<hwc2_layer_t, HWC2::LayerRequest>& 299 getLayerRequests() const { 300 return mLayerRequests; 301 } 302 303 int32_t getDisplayRequests() const { 304 int32_t requests = 0; 305 for (auto request : mDisplayRequests) { 306 requests |= static_cast<int32_t>(request); 307 } 308 return requests; 309 } 310 311 void addTypeChange(hwc2_layer_t layerId, 312 HWC2::Composition type) { 313 mTypeChanges.insert({layerId, type}); 314 } 315 316 void clearTypeChanges() { mTypeChanges.clear(); } 317 318 void addLayerRequest(hwc2_layer_t layerId, 319 HWC2::LayerRequest request) { 320 mLayerRequests.insert({layerId, request}); 321 } 322 323 private: 324 std::unordered_map<hwc2_layer_t, HWC2::Composition> 325 mTypeChanges; 326 std::unordered_map<hwc2_layer_t, HWC2::LayerRequest> 327 mLayerRequests; 328 std::unordered_set<HWC2::DisplayRequest> mDisplayRequests; 329 }; 330 331 std::shared_ptr<const Config> 332 getConfig(hwc2_config_t configId) const; 333 334 void populateColorModes(); 335 void initializeActiveConfig(); 336 337 void reallocateHwc1Contents(); 338 void assignHwc1LayerIds(); 339 340 void updateTypeChanges(const struct hwc_layer_1& hwc1Layer, 341 const Layer& layer); 342 void updateLayerRequests(const struct hwc_layer_1& hwc1Layer, 343 const Layer& layer); 344 345 void prepareFramebufferTarget(); 346 347 static std::atomic<hwc2_display_t> sNextId; 348 const hwc2_display_t mId; 349 HWC2On1Adapter& mDevice; 350 351 std::atomic<size_t> mDirtyCount; 352 353 // The state of this display should only be modified from 354 // SurfaceFlinger's main loop, with the exception of when dump is 355 // called. To prevent a bad state from crashing us during a dump 356 // call, all public calls into Display must acquire this mutex. 357 // 358 // It is recursive because we don't want to deadlock in validate 359 // (or present) when we call HWC2On1Adapter::prepareAllDisplays 360 // (or setAllDisplays), which calls back into Display functions 361 // which require locking. 362 mutable std::recursive_mutex mStateMutex; 363 364 bool mZIsDirty; 365 HWC1Contents mHwc1RequestedContents; 366 HWC1Contents mHwc1ReceivedContents; 367 DeferredFence mRetireFence; 368 369 // Will only be non-null after the layer has been validated but 370 // before it has been presented 371 std::unique_ptr<Changes> mChanges; 372 373 int32_t mHwc1Id; 374 375 std::vector<std::shared_ptr<Config>> mConfigs; 376 std::shared_ptr<const Config> mActiveConfig; 377 std::set<int32_t> mColorModes; 378 int32_t mActiveColorMode; 379 std::string mName; 380 HWC2::DisplayType mType; 381 HWC2::PowerMode mPowerMode; 382 HWC2::Vsync mVsyncEnabled; 383 384 FencedBuffer mClientTarget; 385 FencedBuffer mOutputBuffer; 386 387 bool mHasColorTransform; 388 389 std::multiset<std::shared_ptr<Layer>, SortLayersByZ> mLayers; 390 std::unordered_map<size_t, std::shared_ptr<Layer>> mHwc1LayerMap; 391 }; 392 393 template <typename ...Args> 394 static int32_t callDisplayFunction(hwc2_device_t* device, 395 hwc2_display_t displayId, HWC2::Error (Display::*member)(Args...), 396 Args... args) { 397 auto display = getAdapter(device)->getDisplay(displayId); 398 if (!display) { 399 return static_cast<int32_t>(HWC2::Error::BadDisplay); 400 } 401 auto error = ((*display).*member)(std::forward<Args>(args)...); 402 return static_cast<int32_t>(error); 403 } 404 405 template <typename MF, MF memFunc, typename ...Args> 406 static int32_t displayHook(hwc2_device_t* device, hwc2_display_t displayId, 407 Args... args) { 408 return HWC2On1Adapter::callDisplayFunction(device, displayId, memFunc, 409 std::forward<Args>(args)...); 410 } 411 412 static int32_t getDisplayAttributeHook(hwc2_device_t* device, 413 hwc2_display_t display, hwc2_config_t config, 414 int32_t intAttribute, int32_t* outValue) { 415 auto attribute = static_cast<HWC2::Attribute>(intAttribute); 416 return callDisplayFunction(device, display, &Display::getAttribute, 417 config, attribute, outValue); 418 } 419 420 static int32_t setColorTransformHook(hwc2_device_t* device, 421 hwc2_display_t display, const float* /*matrix*/, 422 int32_t /*android_color_transform_t*/ intHint) { 423 // We intentionally throw away the matrix, because if the hint is 424 // anything other than IDENTITY, we have to fall back to client 425 // composition anyway 426 auto hint = static_cast<android_color_transform_t>(intHint); 427 return callDisplayFunction(device, display, &Display::setColorTransform, 428 hint); 429 } 430 431 static int32_t setPowerModeHook(hwc2_device_t* device, 432 hwc2_display_t display, int32_t intMode) { 433 auto mode = static_cast<HWC2::PowerMode>(intMode); 434 return callDisplayFunction(device, display, &Display::setPowerMode, 435 mode); 436 } 437 438 static int32_t setVsyncEnabledHook(hwc2_device_t* device, 439 hwc2_display_t display, int32_t intEnabled) { 440 auto enabled = static_cast<HWC2::Vsync>(intEnabled); 441 return callDisplayFunction(device, display, &Display::setVsyncEnabled, 442 enabled); 443 } 444 445 // Layer functions 446 447 template <typename T> 448 class LatchedState { 449 public: 450 LatchedState(Layer& parent, T initialValue) 451 : mParent(parent), 452 mPendingValue(initialValue), 453 mValue(initialValue) {} 454 455 void setPending(T value) { 456 if (value == mPendingValue) { 457 return; 458 } 459 if (mPendingValue == mValue) { 460 mParent.incDirty(); 461 } else if (value == mValue) { 462 mParent.decDirty(); 463 } 464 mPendingValue = value; 465 } 466 467 T getValue() const { return mValue; } 468 T getPendingValue() const { return mPendingValue; } 469 470 bool isDirty() const { return mPendingValue != mValue; } 471 472 void latch() { 473 if (isDirty()) { 474 mValue = mPendingValue; 475 mParent.decDirty(); 476 } 477 } 478 479 private: 480 Layer& mParent; 481 T mPendingValue; 482 T mValue; 483 }; 484 485 class Layer { 486 public: 487 Layer(Display& display); 488 489 bool operator==(const Layer& other) { return mId == other.mId; } 490 bool operator!=(const Layer& other) { return !(*this == other); } 491 492 hwc2_layer_t getId() const { return mId; } 493 Display& getDisplay() const { return mDisplay; } 494 495 void incDirty() { if (mDirtyCount++ == 0) mDisplay.incDirty(); } 496 void decDirty() { if (--mDirtyCount == 0) mDisplay.decDirty(); } 497 bool isDirty() const { return mDirtyCount > 0; } 498 499 // HWC2 Layer functions 500 HWC2::Error setBuffer(buffer_handle_t buffer, int32_t acquireFence); 501 HWC2::Error setCursorPosition(int32_t x, int32_t y); 502 HWC2::Error setSurfaceDamage(hwc_region_t damage); 503 504 // HWC2 Layer state functions 505 HWC2::Error setBlendMode(HWC2::BlendMode mode); 506 HWC2::Error setColor(hwc_color_t color); 507 HWC2::Error setCompositionType(HWC2::Composition type); 508 HWC2::Error setDataspace(android_dataspace_t dataspace); 509 HWC2::Error setDisplayFrame(hwc_rect_t frame); 510 HWC2::Error setPlaneAlpha(float alpha); 511 HWC2::Error setSidebandStream(const native_handle_t* stream); 512 HWC2::Error setSourceCrop(hwc_frect_t crop); 513 HWC2::Error setTransform(HWC2::Transform transform); 514 HWC2::Error setVisibleRegion(hwc_region_t visible); 515 HWC2::Error setZ(uint32_t z); 516 517 HWC2::Composition getCompositionType() const { 518 return mCompositionType.getValue(); 519 } 520 uint32_t getZ() const { return mZ; } 521 522 void addReleaseFence(int fenceFd); 523 const sp<Fence>& getReleaseFence() const; 524 525 void setHwc1Id(size_t id) { mHwc1Id = id; } 526 size_t getHwc1Id() const { return mHwc1Id; } 527 528 void applyState(struct hwc_layer_1& hwc1Layer, bool applyAllState); 529 530 std::string dump() const; 531 532 private: 533 void applyCommonState(struct hwc_layer_1& hwc1Layer, 534 bool applyAllState); 535 void applySolidColorState(struct hwc_layer_1& hwc1Layer, 536 bool applyAllState); 537 void applySidebandState(struct hwc_layer_1& hwc1Layer, 538 bool applyAllState); 539 void applyBufferState(struct hwc_layer_1& hwc1Layer); 540 void applyCompositionType(struct hwc_layer_1& hwc1Layer, 541 bool applyAllState); 542 543 static std::atomic<hwc2_layer_t> sNextId; 544 const hwc2_layer_t mId; 545 Display& mDisplay; 546 size_t mDirtyCount; 547 548 FencedBuffer mBuffer; 549 std::vector<hwc_rect_t> mSurfaceDamage; 550 551 LatchedState<HWC2::BlendMode> mBlendMode; 552 LatchedState<hwc_color_t> mColor; 553 LatchedState<HWC2::Composition> mCompositionType; 554 LatchedState<hwc_rect_t> mDisplayFrame; 555 LatchedState<float> mPlaneAlpha; 556 LatchedState<const native_handle_t*> mSidebandStream; 557 LatchedState<hwc_frect_t> mSourceCrop; 558 LatchedState<HWC2::Transform> mTransform; 559 LatchedState<std::vector<hwc_rect_t>> mVisibleRegion; 560 uint32_t mZ; 561 562 DeferredFence mReleaseFence; 563 564 size_t mHwc1Id; 565 bool mHasUnsupportedDataspace; 566 bool mHasUnsupportedPlaneAlpha; 567 }; 568 569 template <typename ...Args> 570 static int32_t callLayerFunction(hwc2_device_t* device, 571 hwc2_display_t displayId, hwc2_layer_t layerId, 572 HWC2::Error (Layer::*member)(Args...), Args... args) { 573 auto result = getAdapter(device)->getLayer(displayId, layerId); 574 auto error = std::get<HWC2::Error>(result); 575 if (error == HWC2::Error::None) { 576 auto layer = std::get<Layer*>(result); 577 error = ((*layer).*member)(std::forward<Args>(args)...); 578 } 579 return static_cast<int32_t>(error); 580 } 581 582 template <typename MF, MF memFunc, typename ...Args> 583 static int32_t layerHook(hwc2_device_t* device, hwc2_display_t displayId, 584 hwc2_layer_t layerId, Args... args) { 585 return HWC2On1Adapter::callLayerFunction(device, displayId, layerId, 586 memFunc, std::forward<Args>(args)...); 587 } 588 589 // Layer state functions 590 591 static int32_t setLayerBlendModeHook(hwc2_device_t* device, 592 hwc2_display_t display, hwc2_layer_t layer, int32_t intMode) { 593 auto mode = static_cast<HWC2::BlendMode>(intMode); 594 return callLayerFunction(device, display, layer, 595 &Layer::setBlendMode, mode); 596 } 597 598 static int32_t setLayerCompositionTypeHook(hwc2_device_t* device, 599 hwc2_display_t display, hwc2_layer_t layer, int32_t intType) { 600 auto type = static_cast<HWC2::Composition>(intType); 601 return callLayerFunction(device, display, layer, 602 &Layer::setCompositionType, type); 603 } 604 605 static int32_t setLayerDataspaceHook(hwc2_device_t* device, 606 hwc2_display_t display, hwc2_layer_t layer, int32_t intDataspace) { 607 auto dataspace = static_cast<android_dataspace_t>(intDataspace); 608 return callLayerFunction(device, display, layer, &Layer::setDataspace, 609 dataspace); 610 } 611 612 static int32_t setLayerTransformHook(hwc2_device_t* device, 613 hwc2_display_t display, hwc2_layer_t layer, int32_t intTransform) { 614 auto transform = static_cast<HWC2::Transform>(intTransform); 615 return callLayerFunction(device, display, layer, &Layer::setTransform, 616 transform); 617 } 618 619 static int32_t setLayerZOrderHook(hwc2_device_t* device, 620 hwc2_display_t display, hwc2_layer_t layer, uint32_t z) { 621 return callDisplayFunction(device, display, &Display::updateLayerZ, 622 layer, z); 623 } 624 625 // Adapter internals 626 627 void populateCapabilities(); 628 Display* getDisplay(hwc2_display_t id); 629 std::tuple<Layer*, HWC2::Error> getLayer(hwc2_display_t displayId, 630 hwc2_layer_t layerId); 631 void populatePrimary(); 632 633 bool prepareAllDisplays(); 634 std::vector<struct hwc_display_contents_1*> mHwc1Contents; 635 HWC2::Error setAllDisplays(); 636 637 void hwc1Invalidate(); 638 void hwc1Vsync(int hwc1DisplayId, int64_t timestamp); 639 void hwc1Hotplug(int hwc1DisplayId, int connected); 640 641 // These are set in the constructor and before any asynchronous events are 642 // possible 643 644 struct hwc_composer_device_1* const mHwc1Device; 645 const uint8_t mHwc1MinorVersion; 646 bool mHwc1SupportsVirtualDisplays; 647 648 class Callbacks; 649 const std::unique_ptr<Callbacks> mHwc1Callbacks; 650 651 std::unordered_set<HWC2::Capability> mCapabilities; 652 653 // These are only accessed from the main SurfaceFlinger thread (not from 654 // callbacks or dump 655 656 std::map<hwc2_layer_t, std::shared_ptr<Layer>> mLayers; 657 std::shared_ptr<Display> mHwc1VirtualDisplay; 658 659 // These are potentially accessed from multiple threads, and are protected 660 // by this mutex. This needs to be recursive, since the HWC1 implementation 661 // can call back into the invalidate callback on the same thread that is 662 // calling prepare. 663 std::recursive_timed_mutex mStateMutex; 664 665 struct CallbackInfo { 666 hwc2_callback_data_t data; 667 hwc2_function_pointer_t pointer; 668 }; 669 std::unordered_map<HWC2::Callback, CallbackInfo> mCallbacks; 670 bool mHasPendingInvalidate; 671 std::vector<std::pair<int, int64_t>> mPendingVsyncs; 672 std::vector<std::pair<int, int>> mPendingHotplugs; 673 674 std::map<hwc2_display_t, std::shared_ptr<Display>> mDisplays; 675 std::unordered_map<int, hwc2_display_t> mHwc1DisplayMap; 676}; 677 678} // namespace android 679 680#endif 681