picker.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /* libs/pixelflinger/picker.cpp
  2. **
  3. ** Copyright 2006, The Android Open Source Project
  4. **
  5. ** Licensed under the Apache License, Version 2.0 (the "License");
  6. ** you may not use this file except in compliance with the License.
  7. ** You may obtain a copy of the License at
  8. **
  9. ** http://www.apache.org/licenses/LICENSE-2.0
  10. **
  11. ** Unless required by applicable law or agreed to in writing, software
  12. ** distributed under the License is distributed on an "AS IS" BASIS,
  13. ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. ** See the License for the specific language governing permissions and
  15. ** limitations under the License.
  16. */
  17. #include <stdio.h>
  18. #include "buffer.h"
  19. #include "scanline.h"
  20. #include "picker.h"
  21. namespace android {
  22. // ----------------------------------------------------------------------------
  23. void ggl_init_picker(context_t* /*c*/)
  24. {
  25. }
  26. void ggl_pick(context_t* c)
  27. {
  28. if (ggl_likely(!c->dirty))
  29. return;
  30. // compute needs, see if they changed...
  31. const uint32_t enables = c->state.enables;
  32. needs_t new_needs(c->state.needs);
  33. if (c->dirty & GGL_CB_STATE) {
  34. new_needs.n &= ~GGL_NEEDS_CB_FORMAT_MASK;
  35. new_needs.n |= GGL_BUILD_NEEDS(c->state.buffers.color.format, CB_FORMAT);
  36. if (enables & GGL_ENABLE_BLENDING)
  37. c->dirty |= GGL_PIXEL_PIPELINE_STATE;
  38. }
  39. if (c->dirty & GGL_PIXEL_PIPELINE_STATE) {
  40. uint32_t n = GGL_BUILD_NEEDS(c->state.buffers.color.format, CB_FORMAT);
  41. uint32_t p = 0;
  42. if (enables & GGL_ENABLE_BLENDING) {
  43. uint32_t src = c->state.blend.src;
  44. uint32_t dst = c->state.blend.dst;
  45. uint32_t src_alpha = c->state.blend.src_alpha;
  46. uint32_t dst_alpha = c->state.blend.dst_alpha;
  47. const GGLFormat& cbf = c->formats[ c->state.buffers.color.format ];
  48. if (!cbf.c[GGLFormat::ALPHA].h) {
  49. if ((src == GGL_ONE_MINUS_DST_ALPHA) ||
  50. (src == GGL_DST_ALPHA)) {
  51. src = GGL_ONE;
  52. }
  53. if ((src_alpha == GGL_ONE_MINUS_DST_ALPHA) ||
  54. (src_alpha == GGL_DST_ALPHA)) {
  55. src_alpha = GGL_ONE;
  56. }
  57. if ((dst == GGL_ONE_MINUS_DST_ALPHA) ||
  58. (dst == GGL_DST_ALPHA)) {
  59. dst = GGL_ONE;
  60. }
  61. if ((dst_alpha == GGL_ONE_MINUS_DST_ALPHA) ||
  62. (dst_alpha == GGL_DST_ALPHA)) {
  63. dst_alpha = GGL_ONE;
  64. }
  65. }
  66. src = ggl_blendfactor_to_needs(src);
  67. dst = ggl_blendfactor_to_needs(dst);
  68. src_alpha = ggl_blendfactor_to_needs(src_alpha);
  69. dst_alpha = ggl_blendfactor_to_needs(dst_alpha);
  70. n |= GGL_BUILD_NEEDS( src, BLEND_SRC );
  71. n |= GGL_BUILD_NEEDS( dst, BLEND_DST );
  72. if (c->state.blend.alpha_separate) {
  73. n |= GGL_BUILD_NEEDS( src_alpha, BLEND_SRCA );
  74. n |= GGL_BUILD_NEEDS( dst_alpha, BLEND_DSTA );
  75. } else {
  76. n |= GGL_BUILD_NEEDS( src, BLEND_SRCA );
  77. n |= GGL_BUILD_NEEDS( dst, BLEND_DSTA );
  78. }
  79. } else {
  80. n |= GGL_BUILD_NEEDS( GGL_ONE, BLEND_SRC );
  81. n |= GGL_BUILD_NEEDS( GGL_ZERO, BLEND_DST );
  82. n |= GGL_BUILD_NEEDS( GGL_ONE, BLEND_SRCA );
  83. n |= GGL_BUILD_NEEDS( GGL_ZERO, BLEND_DSTA );
  84. }
  85. n |= GGL_BUILD_NEEDS(c->state.mask.color^0xF, MASK_ARGB);
  86. n |= GGL_BUILD_NEEDS((enables & GGL_ENABLE_SMOOTH) ?1:0, SHADE);
  87. if (enables & GGL_ENABLE_TMUS) {
  88. n |= GGL_BUILD_NEEDS((enables & GGL_ENABLE_W) ?1:0, W);
  89. }
  90. p |= GGL_BUILD_NEEDS((enables & GGL_ENABLE_DITHER) ?1:0, P_DITHER);
  91. p |= GGL_BUILD_NEEDS((enables & GGL_ENABLE_AA) ?1:0, P_AA);
  92. p |= GGL_BUILD_NEEDS((enables & GGL_ENABLE_FOG) ?1:0, P_FOG);
  93. if (enables & GGL_ENABLE_LOGIC_OP) {
  94. n |= GGL_BUILD_NEEDS(c->state.logic_op.opcode, LOGIC_OP);
  95. } else {
  96. n |= GGL_BUILD_NEEDS(GGL_COPY, LOGIC_OP);
  97. }
  98. if (enables & GGL_ENABLE_ALPHA_TEST) {
  99. p |= GGL_BUILD_NEEDS(c->state.alpha_test.func, P_ALPHA_TEST);
  100. } else {
  101. p |= GGL_BUILD_NEEDS(GGL_ALWAYS, P_ALPHA_TEST);
  102. }
  103. if (enables & GGL_ENABLE_DEPTH_TEST) {
  104. p |= GGL_BUILD_NEEDS(c->state.depth_test.func, P_DEPTH_TEST);
  105. p |= GGL_BUILD_NEEDS(c->state.mask.depth&1, P_MASK_Z);
  106. } else {
  107. p |= GGL_BUILD_NEEDS(GGL_ALWAYS, P_DEPTH_TEST);
  108. // writing to the z-buffer is always disabled if depth-test
  109. // is disabled.
  110. }
  111. new_needs.n = n;
  112. new_needs.p = p;
  113. }
  114. if (c->dirty & GGL_TMU_STATE) {
  115. int idx = 0;
  116. for (int i=0 ; i<GGL_TEXTURE_UNIT_COUNT ; ++i) {
  117. const texture_t& tx = c->state.texture[i];
  118. if (tx.enable) {
  119. uint32_t t = 0;
  120. t |= GGL_BUILD_NEEDS(tx.surface.format, T_FORMAT);
  121. t |= GGL_BUILD_NEEDS(ggl_env_to_needs(tx.env), T_ENV);
  122. t |= GGL_BUILD_NEEDS(0, T_POT); // XXX: not used yet
  123. if (tx.s_coord==GGL_ONE_TO_ONE && tx.t_coord==GGL_ONE_TO_ONE) {
  124. // we encode 1-to-1 into the wrap mode
  125. t |= GGL_BUILD_NEEDS(GGL_NEEDS_WRAP_11, T_S_WRAP);
  126. t |= GGL_BUILD_NEEDS(GGL_NEEDS_WRAP_11, T_T_WRAP);
  127. } else {
  128. t |= GGL_BUILD_NEEDS(ggl_wrap_to_needs(tx.s_wrap), T_S_WRAP);
  129. t |= GGL_BUILD_NEEDS(ggl_wrap_to_needs(tx.t_wrap), T_T_WRAP);
  130. }
  131. if (tx.mag_filter == GGL_LINEAR) {
  132. t |= GGL_BUILD_NEEDS(1, T_LINEAR);
  133. }
  134. if (tx.min_filter == GGL_LINEAR) {
  135. t |= GGL_BUILD_NEEDS(1, T_LINEAR);
  136. }
  137. new_needs.t[idx++] = t;
  138. } else {
  139. new_needs.t[i] = 0;
  140. }
  141. }
  142. }
  143. if (new_needs != c->state.needs) {
  144. c->state.needs = new_needs;
  145. ggl_pick_texture(c);
  146. ggl_pick_cb(c);
  147. ggl_pick_scanline(c);
  148. }
  149. c->dirty = 0;
  150. }
  151. // ----------------------------------------------------------------------------
  152. }; // namespace android