Advertisement
Guest User

Untitled

a guest
Feb 10th, 2015
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 8.34 KB | None | 0 0
  1. diff --git a/src/armsoc_dri2.c b/src/armsoc_dri2.c
  2. index 2e8571a..5f6fbe1 100644
  3. --- a/src/armsoc_dri2.c
  4. +++ b/src/armsoc_dri2.c
  5. @@ -80,19 +80,12 @@ struct ARMSOCDRI2BufferRec {
  6.     int refcnt;
  7.  
  8.     /**
  9. -    * The value of canflip() for the previous frame. Used so that we can
  10. -    * tell whether the buffer should be re-allocated, e.g into scanout-able
  11. -    * memory if the buffer can now be flipped.
  12. -    *
  13. -    * We don't want to re-allocate every frame because it is unnecessary
  14. -    * overhead most of the time apart from when we switch from flipping
  15. -    * to blitting or vice versa.
  16. -    *
  17. -    * We should bump the serial number of the drawable if canflip() returns
  18. -    * something different to what is stored here, so that the DRI2 buffers
  19. -    * will get re-allocated.
  20. -    */
  21. -   int previous_canflip;
  22. +         * We don't want to overdo attempting fb allocation for mapped
  23. +         * scanout buffers, to behave nice under low memory conditions.
  24. +         * Instead we use this flag to attempt the allocation just once
  25. +         * every time the window is mapped.
  26. +         */
  27. +   int attempted_fb_alloc;
  28.  
  29.  };
  30.  
  31. @@ -249,7 +242,6 @@ ARMSOCDRI2CreateBuffer(DrawablePtr pDraw, unsigned int attachment,
  32.     DRIBUF(buf)->format = format;
  33.     DRIBUF(buf)->flags = 0;
  34.     buf->refcnt = 1;
  35. -   buf->previous_canflip = canflip(pDraw);
  36.  
  37.     ret = armsoc_bo_get_name(bo, &DRIBUF(buf)->name);
  38.     if (ret) {
  39. @@ -262,8 +254,13 @@ ARMSOCDRI2CreateBuffer(DrawablePtr pDraw, unsigned int attachment,
  40.         * fall back to blitting if the display controller hardware
  41.         * cannot scan out this buffer (for example, if it doesn't
  42.         * support the format or there was insufficient scanout memory
  43. -       * at buffer creation time). */
  44. +       * at buffer creation time).
  45. +       *
  46. +       * If the window is not mapped at this time, we will not hit
  47. +       * this codepath, but ARMSOCDRI2ReuseBufferNotify will create
  48. +       * a framebuffer if it gets mapped later on. */
  49.        int ret = armsoc_bo_add_fb(bo);
  50. +    buf->attempted_fb_alloc = TRUE;
  51.        if (ret) {
  52.           WARNING_MSG(
  53.                 "Falling back to blitting a flippable window");
  54. @@ -296,6 +293,56 @@ fail:
  55.     return NULL;
  56.  }
  57.  
  58. +/* Called when DRI2 is handling a GetBuffers request and is going to
  59. + * reuse a buffer that we created earlier.
  60. + * Our interest in this situation is that we might have omitted creating
  61. + * a framebuffer for a backbuffer due to it not being flippable at creation
  62. + * time (e.g. because the window wasn't mapped yet).
  63. + * But if GetBuffers has been called because the window is now mapped,
  64. + * we are going to need a framebuffer so that we can page flip it later.
  65. + * We avoid creating a framebuffer when it is not necessary in order to save
  66. + * on scanout memory which is potentially scarce.
  67. + *
  68. + * Mali r4p0 is generally light on calling GetBuffers (e.g. it doesn't do it
  69. + * in response to an InvalidateBuffers event) but we have determined
  70. + * experimentally that it does always seem to call GetBuffers upon a
  71. + * unmapped-to-mapped transition.
  72. + */
  73. +static void
  74. +ARMSOCDRI2ReuseBufferNotify(DrawablePtr pDraw, DRI2BufferPtr buffer)
  75. +{
  76. +   struct ARMSOCDRI2BufferRec *buf = ARMSOCBUF(buffer);
  77. +   struct armsoc_bo *bo;
  78. +   Bool flippable;
  79. +   int fb_id;
  80. +
  81. +   if (buffer->attachment == DRI2BufferFrontLeft)
  82. +      return;
  83. +
  84. +   bo = ARMSOCPixmapBo(buf->pPixmaps[0]);
  85. +   fb_id = armsoc_bo_get_fb(bo);
  86. +   flippable = canflip(pDraw);
  87. +
  88. +   /* Detect unflippable-to-flippable transition:
  89. +    * Window is flippable, but we haven't yet tried to allocate a
  90. +    * framebuffer for it, and it doesn't already have a framebuffer.
  91. +    * This can happen when CreateBuffer was called before the window
  92. +    * was mapped, and we have now been mapped. */
  93. +   if (flippable && !buf->attempted_fb_alloc && fb_id == 0) {
  94. +      armsoc_bo_add_fb(bo);
  95. +           buf->attempted_fb_alloc = TRUE;
  96. +   }
  97. +
  98. +   /* Detect flippable-to-unflippable transition:
  99. +    * Window is now unflippable, but we have a framebuffer allocated for
  100. +    * it. Now we can free the framebuffer to save on scanout memory, and
  101. +    * reset state in case it gets mapped again later. */
  102. +   if (!flippable && fb_id != 0) {
  103. +           buf->attempted_fb_alloc = FALSE;
  104. +      armsoc_bo_rm_fb(bo);
  105. +   }
  106. +}
  107. +
  108.  /**
  109.   * Destroy Buffer
  110.   */
  111. @@ -355,7 +402,6 @@ ARMSOCDRI2CopyRegion(DrawablePtr pDraw, RegionPtr pRegion,
  112.  
  113.     DEBUG_MSG("pDraw=%p, pDstBuffer=%p (%p), pSrcBuffer=%p (%p)",
  114.           pDraw, pDstBuffer, pSrcDraw, pSrcBuffer, pDstDraw);
  115. -
  116.     pGC = GetScratchGC(pDstDraw->depth, pScreen);
  117.     if (!pGC)
  118.        return;
  119. @@ -414,30 +460,6 @@ ARMSOCDRI2GetMSC(DrawablePtr pDraw, CARD64 *ust, CARD64 *msc)
  120.     return TRUE;
  121.  }
  122.  
  123. -#if DRI2INFOREC_VERSION >= 6
  124. -/**
  125. - * Called by DRI2 to validate that any new swap limit being set by
  126. - * DRI2 is in range. In our case the range is 1 to the DRI2MaxBuffers
  127. - * option, plus one in the case of early display usage.
  128. - */
  129. -static Bool
  130. -ARMSOCDRI2SwapLimitValidate(DrawablePtr pDraw, int swap_limit) {
  131. -   ScreenPtr pScreen = pDraw->pScreen;
  132. -   ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
  133. -   struct ARMSOCRec *pARMSOC = ARMSOCPTR(pScrn);
  134. -   int32_t lower_limit, upper_limit;
  135. -
  136. -   lower_limit = 1;
  137. -   upper_limit = pARMSOC->driNumBufs-1;
  138. -
  139. -   if (pARMSOC->drmmode_interface->use_early_display)
  140. -      upper_limit += 1;
  141. -
  142. -   return ((swap_limit >= lower_limit) && (swap_limit <= upper_limit))
  143. -      ? TRUE : FALSE;
  144. -}
  145. -#endif /* DRI2INFOREC_VERSION >= 6 */
  146. -
  147.  #define ARMSOC_SWAP_FAKE_FLIP (1 << 0)
  148.  #define ARMSOC_SWAP_FAIL      (1 << 1)
  149.  
  150. @@ -716,12 +738,10 @@ ARMSOCDRI2ScheduleSwap(ClientPtr client, DrawablePtr pDraw,
  151.     ScreenPtr pScreen = pDraw->pScreen;
  152.     ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
  153.     struct ARMSOCRec *pARMSOC = ARMSOCPTR(pScrn);
  154. -   struct ARMSOCDRI2BufferRec *src = ARMSOCBUF(pSrcBuffer);
  155. -   struct ARMSOCDRI2BufferRec *dst = ARMSOCBUF(pDstBuffer);
  156.     struct ARMSOCDRISwapCmd *cmd;
  157.     struct armsoc_bo *src_bo, *dst_bo;
  158.     int src_fb_id, dst_fb_id;
  159. -   int new_canflip, ret, do_flip;
  160. +   int ret, do_flip;
  161.     unsigned int idx;
  162.     RegionRec region;
  163.     PixmapPtr pDstPixmap = draw2pix(dri2draw(pDraw, pDstBuffer));
  164. @@ -773,26 +793,6 @@ ARMSOCDRI2ScheduleSwap(ClientPtr client, DrawablePtr pDraw,
  165.     DEBUG_MSG("SWAP %d SCHEDULED : %d -> %d ", cmd->swap_id,
  166.              pSrcBuffer->attachment, pDstBuffer->attachment);
  167.  
  168. -   new_canflip = canflip(pDraw);
  169. -   if ((src->previous_canflip != new_canflip) ||
  170. -       (dst->previous_canflip != new_canflip)) {
  171. -      /* The drawable has transitioned between being flippable and
  172. -       * non-flippable or vice versa. Bump the serial number to force
  173. -       * the DRI2 buffers to be re-allocated during the next frame so
  174. -       * that:
  175. -       * - It is able to be scanned out
  176. -       *        (if drawable is now flippable), or
  177. -       * - It is not taking up possibly scarce scanout-able memory
  178. -       *        (if drawable is now not flippable)
  179. -       */
  180. -
  181. -      PixmapPtr pPix = pScreen->GetWindowPixmap((WindowPtr)pDraw);
  182. -      pPix->drawable.serialNumber = NEXT_SERIAL_NUMBER;
  183. -   }
  184. -
  185. -   src->previous_canflip = new_canflip;
  186. -   dst->previous_canflip = new_canflip;
  187. -
  188.     do_flip = src_fb_id && dst_fb_id && canflip(pDraw);
  189.  
  190.     /* After a resolution change the back buffer (src) will still be
  191. @@ -930,24 +930,20 @@ ARMSOCDRI2ScreenInit(ScreenPtr pScreen)
  192.     ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
  193.     struct ARMSOCRec *pARMSOC = ARMSOCPTR(pScrn);
  194.     DRI2InfoRec info = {
  195. -#if DRI2INFOREC_VERSION >= 6
  196.        .version           = 6,
  197. -#else
  198. -      .version           = 5,
  199. -#endif
  200.        .fd                = pARMSOC->drmFD,
  201.        .driverName        = "armsoc",
  202.        .deviceName        = pARMSOC->deviceName,
  203.        .CreateBuffer      = ARMSOCDRI2CreateBuffer,
  204.        .DestroyBuffer     = ARMSOCDRI2DestroyBuffer,
  205. +      .ReuseBufferNotify = ARMSOCDRI2ReuseBufferNotify,
  206.        .CopyRegion        = ARMSOCDRI2CopyRegion,
  207.        .ScheduleSwap      = ARMSOCDRI2ScheduleSwap,
  208.        .ScheduleWaitMSC   = ARMSOCDRI2ScheduleWaitMSC,
  209.        .GetMSC            = ARMSOCDRI2GetMSC,
  210.        .AuthMagic         = drmAuthMagic,
  211. -#if DRI2INFOREC_VERSION >= 6
  212. -      .SwapLimitValidate = ARMSOCDRI2SwapLimitValidate,
  213. -#endif
  214. +      .SwapLimitValidate = NULL,
  215. +
  216.     };
  217.     int minor = 1, major = 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement