finish.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /*
  2. * Copyright (C) 2007 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18. #include <time.h>
  19. #include <sched.h>
  20. #include <sys/resource.h>
  21. #include <EGL/egl.h>
  22. #include <GLES/gl.h>
  23. #include <GLES/glext.h>
  24. #include <utils/Timers.h>
  25. #include <WindowSurface.h>
  26. #include <EGLUtils.h>
  27. using namespace android;
  28. int main(int argc, char** argv)
  29. {
  30. EGLint configAttribs[] = {
  31. EGL_DEPTH_SIZE, 0,
  32. EGL_NONE
  33. };
  34. EGLint majorVersion;
  35. EGLint minorVersion;
  36. EGLContext context;
  37. EGLConfig config;
  38. EGLSurface surface;
  39. EGLint w, h;
  40. EGLDisplay dpy;
  41. WindowSurface windowSurface;
  42. EGLNativeWindowType window = windowSurface.getSurface();
  43. dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
  44. eglInitialize(dpy, &majorVersion, &minorVersion);
  45. status_t err = EGLUtils::selectConfigForNativeWindow(
  46. dpy, configAttribs, window, &config);
  47. if (err) {
  48. fprintf(stderr, "couldn't find an EGLConfig matching the screen format\n");
  49. return 0;
  50. }
  51. surface = eglCreateWindowSurface(dpy, config, window, NULL);
  52. context = eglCreateContext(dpy, config, NULL, NULL);
  53. eglMakeCurrent(dpy, surface, surface, context);
  54. eglQuerySurface(dpy, surface, EGL_WIDTH, &w);
  55. eglQuerySurface(dpy, surface, EGL_HEIGHT, &h);
  56. GLint dim = w<h ? w : h;
  57. glBindTexture(GL_TEXTURE_2D, 0);
  58. glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  59. glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  60. glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
  61. glEnable(GL_TEXTURE_2D);
  62. glColor4f(1,1,1,1);
  63. glDisable(GL_DITHER);
  64. glShadeModel(GL_FLAT);
  65. long long now, t;
  66. int i;
  67. char* texels = (char*)malloc(512*512*2);
  68. memset(texels,0xFF,512*512*2);
  69. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
  70. 512, 512, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, texels);
  71. char* dst = (char*)malloc(320*480*2);
  72. memset(dst, 0, 320*480*2);
  73. printf("307200 bytes memcpy\n");
  74. for (i=0 ; i<4 ; i++) {
  75. now = systemTime();
  76. memcpy(dst, texels, 320*480*2);
  77. t = systemTime();
  78. printf("memcpy() time = %llu us\n", (t-now)/1000);
  79. fflush(stdout);
  80. }
  81. free(dst);
  82. free(texels);
  83. setpriority(PRIO_PROCESS, 0, -20);
  84. printf("512x512 unmodified texture, 512x512 blit:\n");
  85. glClear(GL_COLOR_BUFFER_BIT);
  86. for (i=0 ; i<4 ; i++) {
  87. GLint crop[4] = { 0, 512, 512, -512 };
  88. glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
  89. now = systemTime();
  90. glDrawTexiOES(0, 0, 0, 512, 512);
  91. glFinish();
  92. t = systemTime();
  93. printf("glFinish() time = %llu us\n", (t-now)/1000);
  94. fflush(stdout);
  95. eglSwapBuffers(dpy, surface);
  96. }
  97. printf("512x512 unmodified texture, 1x1 blit:\n");
  98. glClear(GL_COLOR_BUFFER_BIT);
  99. for (i=0 ; i<4 ; i++) {
  100. GLint crop[4] = { 0, 1, 1, -1 };
  101. glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
  102. now = systemTime();
  103. glDrawTexiOES(0, 0, 0, 1, 1);
  104. glFinish();
  105. t = systemTime();
  106. printf("glFinish() time = %llu us\n", (t-now)/1000);
  107. fflush(stdout);
  108. eglSwapBuffers(dpy, surface);
  109. }
  110. printf("512x512 unmodified texture, 512x512 blit (x2):\n");
  111. glClear(GL_COLOR_BUFFER_BIT);
  112. for (i=0 ; i<4 ; i++) {
  113. GLint crop[4] = { 0, 512, 512, -512 };
  114. glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
  115. now = systemTime();
  116. glDrawTexiOES(0, 0, 0, 512, 512);
  117. glDrawTexiOES(0, 0, 0, 512, 512);
  118. glFinish();
  119. t = systemTime();
  120. printf("glFinish() time = %llu us\n", (t-now)/1000);
  121. fflush(stdout);
  122. eglSwapBuffers(dpy, surface);
  123. }
  124. printf("512x512 unmodified texture, 1x1 blit (x2):\n");
  125. glClear(GL_COLOR_BUFFER_BIT);
  126. for (i=0 ; i<4 ; i++) {
  127. GLint crop[4] = { 0, 1, 1, -1 };
  128. glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
  129. now = systemTime();
  130. glDrawTexiOES(0, 0, 0, 1, 1);
  131. glDrawTexiOES(0, 0, 0, 1, 1);
  132. glFinish();
  133. t = systemTime();
  134. printf("glFinish() time = %llu us\n", (t-now)/1000);
  135. fflush(stdout);
  136. eglSwapBuffers(dpy, surface);
  137. }
  138. printf("512x512 (1x1 texel MODIFIED texture), 512x512 blit:\n");
  139. glClear(GL_COLOR_BUFFER_BIT);
  140. for (i=0 ; i<4 ; i++) {
  141. uint16_t green = 0x7E0;
  142. GLint crop[4] = { 0, 512, 512, -512 };
  143. glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
  144. glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, &green);
  145. now = systemTime();
  146. glDrawTexiOES(0, 0, 0, 512, 512);
  147. glFinish();
  148. t = systemTime();
  149. printf("glFinish() time = %llu us\n", (t-now)/1000);
  150. fflush(stdout);
  151. eglSwapBuffers(dpy, surface);
  152. }
  153. int16_t texel = 0xF800;
  154. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
  155. 1, 1, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, &texel);
  156. printf("1x1 unmodified texture, 1x1 blit:\n");
  157. glClear(GL_COLOR_BUFFER_BIT);
  158. for (i=0 ; i<4 ; i++) {
  159. GLint crop[4] = { 0, 1, 1, -1 };
  160. glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
  161. now = systemTime();
  162. glDrawTexiOES(0, 0, 0, 1, 1);
  163. glFinish();
  164. t = systemTime();
  165. printf("glFinish() time = %llu us\n", (t-now)/1000);
  166. eglSwapBuffers(dpy, surface);
  167. }
  168. printf("1x1 unmodified texture, 512x512 blit:\n");
  169. glClear(GL_COLOR_BUFFER_BIT);
  170. for (i=0 ; i<4 ; i++) {
  171. GLint crop[4] = { 0, 1, 1, -1 };
  172. glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
  173. now = systemTime();
  174. glDrawTexiOES(0, 0, 0, 512, 512);
  175. glFinish();
  176. t = systemTime();
  177. printf("glFinish() time = %llu us\n", (t-now)/1000);
  178. fflush(stdout);
  179. eglSwapBuffers(dpy, surface);
  180. }
  181. printf("1x1 (1x1 texel MODIFIED texture), 512x512 blit:\n");
  182. glClear(GL_COLOR_BUFFER_BIT);
  183. for (i=0 ; i<4 ; i++) {
  184. uint16_t green = 0x7E0;
  185. GLint crop[4] = { 0, 1, 1, -1 };
  186. glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
  187. glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, &green);
  188. now = systemTime();
  189. glDrawTexiOES(0, 0, 0, 1, 1);
  190. glFinish();
  191. t = systemTime();
  192. printf("glFinish() time = %llu us\n", (t-now)/1000);
  193. fflush(stdout);
  194. eglSwapBuffers(dpy, surface);
  195. }
  196. return 0;
  197. }