gralloc.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. **
  3. ** Copyright 2009, 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 "StopWatch"
  18. #include <stdlib.h>
  19. #include <stdio.h>
  20. #include <utils/StopWatch.h>
  21. #include <utils/Log.h>
  22. #include <ui/GraphicBuffer.h>
  23. #include <ui/GraphicBufferMapper.h>
  24. using namespace android;
  25. void* lamecpy(void* d, void const* s, size_t size) {
  26. char* dst = (char*)d;
  27. char const* src = (char const*)s;
  28. while (size) {
  29. *dst++ = *src++;
  30. size--;
  31. }
  32. return d;
  33. }
  34. int main(int argc, char** argv)
  35. {
  36. size_t size = 128*256*4;
  37. void* temp = malloc(size);
  38. void* temp2 = malloc(size);
  39. memset(temp, 0, size);
  40. memset(temp2, 0, size);
  41. sp<GraphicBuffer> buffer = new GraphicBuffer(128, 256, HAL_PIXEL_FORMAT_RGBA_8888,
  42. GRALLOC_USAGE_SW_READ_OFTEN |
  43. GRALLOC_USAGE_SW_WRITE_OFTEN);
  44. status_t err = buffer->initCheck();
  45. if (err != NO_ERROR) {
  46. printf("%s\n", strerror(-err));
  47. return 0;
  48. }
  49. void* vaddr;
  50. buffer->lock(
  51. GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN,
  52. &vaddr);
  53. {
  54. StopWatch watch("memset");
  55. for (int i=0 ; i<10 ; i++)
  56. memset(vaddr, 0, size);
  57. }
  58. {
  59. StopWatch watch("memcpy baseline");
  60. for (int i=0 ; i<10 ; i++)
  61. memcpy(temp, temp2, size);
  62. }
  63. {
  64. StopWatch watch("memcpy from gralloc");
  65. for (int i=0 ; i<10 ; i++)
  66. memcpy(temp, vaddr, size);
  67. }
  68. {
  69. StopWatch watch("memcpy into gralloc");
  70. for (int i=0 ; i<10 ; i++)
  71. memcpy(vaddr, temp, size);
  72. }
  73. {
  74. StopWatch watch("lamecpy baseline");
  75. for (int i=0 ; i<10 ; i++)
  76. lamecpy(temp, temp2, size);
  77. }
  78. {
  79. StopWatch watch("lamecpy from gralloc");
  80. for (int i=0 ; i<10 ; i++)
  81. lamecpy(temp, vaddr, size);
  82. }
  83. {
  84. StopWatch watch("lamecpy into gralloc");
  85. for (int i=0 ; i<10 ; i++)
  86. lamecpy(vaddr, temp, size);
  87. }
  88. buffer->unlock();
  89. return 0;
  90. }