glamor_points.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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@linux.intel.com>
  26. *
  27. */
  28. #include "glamor_priv.h"
  29. #include "glamor_transform.h"
  30. static const glamor_facet glamor_facet_point = {
  31. .name = "poly_point",
  32. .vs_vars = "attribute vec2 primitive;\n",
  33. .vs_exec = GLAMOR_POS(gl_Position, primitive),
  34. };
  35. static Bool
  36. glamor_poly_point_gl(DrawablePtr drawable, GCPtr gc, int mode, int npt, DDXPointPtr ppt)
  37. {
  38. ScreenPtr screen = drawable->pScreen;
  39. glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
  40. PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable);
  41. glamor_program *prog = &glamor_priv->point_prog;
  42. glamor_pixmap_private *pixmap_priv;
  43. int off_x, off_y;
  44. GLshort *vbo_ppt;
  45. char *vbo_offset;
  46. int box_x, box_y;
  47. pixmap_priv = glamor_get_pixmap_private(pixmap);
  48. if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv))
  49. goto bail;
  50. glamor_make_current(glamor_priv);
  51. if (prog->failed)
  52. goto bail_ctx;
  53. if (!prog->prog) {
  54. if (!glamor_build_program(screen, prog,
  55. &glamor_facet_point,
  56. &glamor_fill_solid))
  57. goto bail_ctx;
  58. }
  59. if (!glamor_use_program(pixmap, gc, prog, NULL))
  60. goto bail_ctx;
  61. vbo_ppt = glamor_get_vbo_space(screen, npt * (2 * sizeof (INT16)), &vbo_offset);
  62. glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
  63. glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_SHORT, GL_FALSE, 0, vbo_offset);
  64. if (mode == CoordModePrevious) {
  65. int n = npt;
  66. INT16 x = 0, y = 0;
  67. while (n--) {
  68. vbo_ppt[0] = (x += ppt->x);
  69. vbo_ppt[1] = (y += ppt->y);
  70. vbo_ppt += 2;
  71. ppt++;
  72. }
  73. } else
  74. memcpy(vbo_ppt, ppt, npt * (2 * sizeof (INT16)));
  75. glamor_put_vbo_space(screen);
  76. glEnable(GL_SCISSOR_TEST);
  77. glamor_pixmap_loop(pixmap_priv, box_x, box_y) {
  78. int nbox = RegionNumRects(gc->pCompositeClip);
  79. BoxPtr box = RegionRects(gc->pCompositeClip);
  80. glamor_set_destination_drawable(drawable, box_x, box_y, TRUE, TRUE, prog->matrix_uniform, &off_x, &off_y);
  81. while (nbox--) {
  82. glScissor(box->x1 + off_x,
  83. box->y1 + off_y,
  84. box->x2 - box->x1,
  85. box->y2 - box->y1);
  86. box++;
  87. glDrawArrays(GL_POINTS, 0, npt);
  88. }
  89. }
  90. glDisable(GL_SCISSOR_TEST);
  91. glDisable(GL_COLOR_LOGIC_OP);
  92. glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
  93. glamor_priv->state = RENDER_STATE;
  94. glamor_priv->render_idle_cnt = 0;
  95. return TRUE;
  96. bail_ctx:
  97. glDisable(GL_COLOR_LOGIC_OP);
  98. bail:
  99. return FALSE;
  100. }
  101. void
  102. glamor_poly_point(DrawablePtr drawable, GCPtr gc, int mode, int npt,
  103. DDXPointPtr ppt)
  104. {
  105. if (glamor_poly_point_gl(drawable, gc, mode, npt, ppt))
  106. return;
  107. miPolyPoint(drawable, gc, mode, npt, ppt);
  108. }
  109. Bool
  110. glamor_poly_point_nf(DrawablePtr drawable, GCPtr gc, int mode, int npt,
  111. DDXPointPtr ppt)
  112. {
  113. if (glamor_poly_point_gl(drawable, gc, mode, npt, ppt))
  114. return TRUE;
  115. if (glamor_ddx_fallback_check_pixmap(drawable) && glamor_ddx_fallback_check_gc(gc))
  116. return FALSE;
  117. miPolyPoint(drawable, gc, mode, npt, ppt);
  118. return TRUE;
  119. }