fillrate.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  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. #define LOG_TAG "fillrate"
  18. #include <stdlib.h>
  19. #include <stdio.h>
  20. #include <EGL/egl.h>
  21. #include <GLES/gl.h>
  22. #include <GLES/glext.h>
  23. #include <utils/StopWatch.h>
  24. #include <WindowSurface.h>
  25. #include <EGLUtils.h>
  26. using namespace android;
  27. int main(int argc, char** argv)
  28. {
  29. EGLint configAttribs[] = {
  30. EGL_DEPTH_SIZE, 0,
  31. EGL_NONE
  32. };
  33. EGLint majorVersion;
  34. EGLint minorVersion;
  35. EGLContext context;
  36. EGLConfig config;
  37. EGLSurface surface;
  38. EGLint w, h;
  39. EGLDisplay dpy;
  40. WindowSurface windowSurface;
  41. EGLNativeWindowType window = windowSurface.getSurface();
  42. dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
  43. eglInitialize(dpy, &majorVersion, &minorVersion);
  44. status_t err = EGLUtils::selectConfigForNativeWindow(
  45. dpy, configAttribs, window, &config);
  46. if (err) {
  47. fprintf(stderr, "couldn't find an EGLConfig matching the screen format\n");
  48. return 0;
  49. }
  50. surface = eglCreateWindowSurface(dpy, config, window, NULL);
  51. context = eglCreateContext(dpy, config, NULL, NULL);
  52. eglMakeCurrent(dpy, surface, surface, context);
  53. eglQuerySurface(dpy, surface, EGL_WIDTH, &w);
  54. eglQuerySurface(dpy, surface, EGL_HEIGHT, &h);
  55. printf("w=%d, h=%d\n", w, h);
  56. glBindTexture(GL_TEXTURE_2D, 0);
  57. glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  58. glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  59. glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  60. glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  61. glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
  62. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  63. glDisable(GL_DITHER);
  64. glEnable(GL_BLEND);
  65. glEnable(GL_TEXTURE_2D);
  66. glColor4f(1,1,1,1);
  67. uint32_t* t32 = (uint32_t*)malloc(512*512*4);
  68. for (int y=0 ; y<512 ; y++) {
  69. for (int x=0 ; x<512 ; x++) {
  70. int u = x-256;
  71. int v = y-256;
  72. if (u*u+v*v < 256*256) {
  73. t32[x+y*512] = 0x10FFFFFF;
  74. } else {
  75. t32[x+y*512] = 0x20FF0000;
  76. }
  77. }
  78. }
  79. const GLfloat fh = h;
  80. const GLfloat fw = w;
  81. const GLfloat vertices[4][2] = {
  82. { 0, 0 },
  83. { 0, fh },
  84. { fw, fh },
  85. { fw, 0 }
  86. };
  87. const GLfloat texCoords[4][2] = {
  88. { 0, 0 },
  89. { 0, 1 },
  90. { 1, 1 },
  91. { 1, 0 }
  92. };
  93. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, t32);
  94. glViewport(0, 0, w, h);
  95. glMatrixMode(GL_PROJECTION);
  96. glLoadIdentity();
  97. glOrthof(0, w, 0, h, 0, 1);
  98. glEnableClientState(GL_VERTEX_ARRAY);
  99. glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  100. glVertexPointer(2, GL_FLOAT, 0, vertices);
  101. glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
  102. eglSwapInterval(dpy, 1);
  103. glClearColor(1,0,0,0);
  104. glClear(GL_COLOR_BUFFER_BIT);
  105. glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
  106. eglSwapBuffers(dpy, surface);
  107. nsecs_t times[32];
  108. for (int c=1 ; c<32 ; c++) {
  109. glClear(GL_COLOR_BUFFER_BIT);
  110. for (int i=0 ; i<c ; i++) {
  111. glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
  112. }
  113. eglSwapBuffers(dpy, surface);
  114. }
  115. // for (int c=31 ; c>=1 ; c--) {
  116. int j=0;
  117. for (int c=1 ; c<32 ; c++) {
  118. glClear(GL_COLOR_BUFFER_BIT);
  119. nsecs_t now = systemTime();
  120. for (int i=0 ; i<c ; i++) {
  121. glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
  122. }
  123. eglSwapBuffers(dpy, surface);
  124. nsecs_t t = systemTime() - now;
  125. times[j++] = t;
  126. }
  127. for (int c=1, j=0 ; c<32 ; c++, j++) {
  128. nsecs_t t = times[j];
  129. printf("%lld\t%d\t%f\n", t, c, (double(t)/c)/1000000.0);
  130. }
  131. eglTerminate(dpy);
  132. return 0;
  133. }