ExVirtualDisplaySurface.cpp 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* Copyright (c) 2015, The Linux Foundation. All rights reserved.
  2. *
  3. * Redistribution and use in source and binary forms, with or without
  4. * modification, are permitted provided that the following conditions are
  5. * met:
  6. * * Redistributions of source code must retain the above copyright
  7. * notice, this list of conditions and the following disclaimer.
  8. * * Redistributions in binary form must reproduce the above
  9. * copyright notice, this list of conditions and the following
  10. * disclaimer in the documentation and/or other materials provided
  11. * with the distribution.
  12. * * Neither the name of The Linux Foundation nor the names of its
  13. * contributors may be used to endorse or promote products derived
  14. * from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
  17. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
  19. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
  20. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  21. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  22. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  23. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  24. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  25. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  26. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. #include "ExVirtualDisplaySurface.h"
  29. #ifdef QTI_BSP
  30. #include <gralloc_priv.h>
  31. #endif
  32. namespace android {
  33. #define VDS_LOGE(msg, ...) ALOGE("[%s] " msg, \
  34. mDisplayName.string(), ##__VA_ARGS__)
  35. #define VDS_LOGW_IF(cond, msg, ...) ALOGW_IF(cond, "[%s] " msg, \
  36. mDisplayName.string(), ##__VA_ARGS__)
  37. #define VDS_LOGV(msg, ...) ALOGV("[%s] " msg, \
  38. mDisplayName.string(), ##__VA_ARGS__)
  39. ExVirtualDisplaySurface::ExVirtualDisplaySurface(HWComposer& hwc, int32_t dispId,
  40. const sp<IGraphicBufferProducer>& sink,
  41. const sp<IGraphicBufferProducer>& bqProducer,
  42. const sp<IGraphicBufferConsumer>& bqConsumer,
  43. const String8& name,
  44. bool secure)
  45. : VirtualDisplaySurface(hwc, dispId, sink, bqProducer, bqConsumer, name),
  46. mSecure(secure) {
  47. sink->query(NATIVE_WINDOW_CONSUMER_USAGE_BITS, &mSinkUsage);
  48. mSinkUsage |= GRALLOC_USAGE_HW_COMPOSER;
  49. setOutputUsage(mSinkUsage);
  50. }
  51. status_t ExVirtualDisplaySurface::beginFrame(bool mustRecompose) {
  52. if (mDisplayId < 0)
  53. return NO_ERROR;
  54. mMustRecompose = mustRecompose;
  55. /* For WFD use cases we must always set the recompose flag in order
  56. * to support pause/resume functionality
  57. */
  58. if (mOutputUsage & GRALLOC_USAGE_HW_VIDEO_ENCODER) {
  59. mMustRecompose = true;
  60. }
  61. VDS_LOGW_IF(mDbgState != DBG_STATE_IDLE,
  62. "Unexpected beginFrame() in %s state", dbgStateStr());
  63. mDbgState = DBG_STATE_BEGUN;
  64. return refreshOutputBuffer();
  65. }
  66. /* Helper to update the output usage when the display is secure */
  67. void ExVirtualDisplaySurface::setOutputUsage(uint32_t /*flag*/) {
  68. mOutputUsage = mSinkUsage;
  69. if (mSecure && (mOutputUsage & GRALLOC_USAGE_HW_VIDEO_ENCODER)) {
  70. /* TODO: Currently, the framework can only say whether the display
  71. * and its subsequent session are secure or not. However, there is
  72. * no mechanism to distinguish the different levels of security.
  73. * The current solution assumes WV L3 protection.
  74. */
  75. mOutputUsage |= GRALLOC_USAGE_PROTECTED;
  76. #ifdef QTI_BSP
  77. mOutputUsage |= GRALLOC_USAGE_PRIVATE_MM_HEAP |
  78. GRALLOC_USAGE_PRIVATE_UNCACHED;
  79. #endif
  80. }
  81. }
  82. }; // namespace android