glamor_picture.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Copyright © 2009 Intel Corporation
  3. * Copyright © 1998 Keith Packard
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the next
  13. * paragraph) shall be included in all copies or substantial portions of the
  14. * Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  22. * IN THE SOFTWARE.
  23. *
  24. * Authors:
  25. * Zhigang Gong <zhigang.gong@gmail.com>
  26. *
  27. */
  28. #include <stdlib.h>
  29. #include "glamor_priv.h"
  30. #include "mipict.h"
  31. /* Upload picture to texture. We may need to flip the y axis or
  32. * wire alpha to 1. So we may conditional create fbo for the picture.
  33. * */
  34. enum glamor_pixmap_status
  35. glamor_upload_picture_to_texture(PicturePtr picture)
  36. {
  37. PixmapPtr pixmap;
  38. assert(picture->pDrawable);
  39. pixmap = glamor_get_drawable_pixmap(picture->pDrawable);
  40. return glamor_upload_pixmap_to_texture(pixmap);
  41. }
  42. Bool
  43. glamor_prepare_access_picture(PicturePtr picture, glamor_access_t access)
  44. {
  45. if (!picture || !picture->pDrawable)
  46. return TRUE;
  47. return glamor_prepare_access(picture->pDrawable, access);
  48. }
  49. void
  50. glamor_finish_access_picture(PicturePtr picture)
  51. {
  52. if (!picture || !picture->pDrawable)
  53. return;
  54. glamor_finish_access(picture->pDrawable);
  55. }
  56. /*
  57. * We should already have drawable attached to it, if it has one.
  58. * Then set the attached pixmap to is_picture format, and set
  59. * the pict format.
  60. * */
  61. int
  62. glamor_create_picture(PicturePtr picture)
  63. {
  64. PixmapPtr pixmap;
  65. glamor_pixmap_private *pixmap_priv;
  66. if (!picture || !picture->pDrawable)
  67. return 0;
  68. pixmap = glamor_get_drawable_pixmap(picture->pDrawable);
  69. pixmap_priv = glamor_get_pixmap_private(pixmap);
  70. if (!pixmap_priv) {
  71. /* We must create a pixmap priv to track the picture format even
  72. * if the pixmap is a pure in memory pixmap. The reason is that
  73. * we may need to upload this pixmap to a texture on the fly. During
  74. * the uploading, we need to know the picture format. */
  75. glamor_set_pixmap_type(pixmap, GLAMOR_MEMORY);
  76. pixmap_priv = glamor_get_pixmap_private(pixmap);
  77. }
  78. else {
  79. if (GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv)) {
  80. /* If the picture format is not compatible with glamor fbo format,
  81. * we have to mark this pixmap as a separated texture, and don't
  82. * fallback to DDX layer. */
  83. if (pixmap_priv->type == GLAMOR_TEXTURE_DRM
  84. && !glamor_pict_format_is_compatible(picture))
  85. glamor_set_pixmap_type(pixmap, GLAMOR_SEPARATE_TEXTURE);
  86. }
  87. }
  88. pixmap_priv->base.is_picture = 1;
  89. pixmap_priv->base.picture = picture;
  90. return miCreatePicture(picture);
  91. }
  92. void
  93. glamor_destroy_picture(PicturePtr picture)
  94. {
  95. PixmapPtr pixmap;
  96. glamor_pixmap_private *pixmap_priv;
  97. if (!picture || !picture->pDrawable)
  98. return;
  99. pixmap = glamor_get_drawable_pixmap(picture->pDrawable);
  100. pixmap_priv = glamor_get_pixmap_private(pixmap);
  101. if (pixmap_priv) {
  102. pixmap_priv->base.is_picture = 0;
  103. pixmap_priv->base.picture = NULL;
  104. }
  105. miDestroyPicture(picture);
  106. }
  107. void
  108. glamor_picture_format_fixup(PicturePtr picture,
  109. glamor_pixmap_private *pixmap_priv)
  110. {
  111. pixmap_priv->base.picture = picture;
  112. }