SurfaceTextureFBO_test.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright 2013 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. #define LOG_TAG "SurfaceTextureFBO_test"
  17. //#define LOG_NDEBUG 0
  18. #include "SurfaceTextureFBO.h"
  19. namespace android {
  20. // This test is intended to verify that proper synchronization is done when
  21. // rendering into an FBO.
  22. TEST_F(SurfaceTextureFBOTest, BlitFromCpuFilledBufferToFbo) {
  23. const int texWidth = 64;
  24. const int texHeight = 64;
  25. ASSERT_EQ(NO_ERROR, native_window_set_buffers_dimensions(mANW.get(),
  26. texWidth, texHeight));
  27. ASSERT_EQ(NO_ERROR, native_window_set_buffers_format(mANW.get(),
  28. HAL_PIXEL_FORMAT_RGBA_8888));
  29. ASSERT_EQ(NO_ERROR, native_window_set_usage(mANW.get(),
  30. GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN));
  31. android_native_buffer_t* anb;
  32. ASSERT_EQ(NO_ERROR, native_window_dequeue_buffer_and_wait(mANW.get(),
  33. &anb));
  34. ASSERT_TRUE(anb != NULL);
  35. sp<GraphicBuffer> buf(new GraphicBuffer(anb, false));
  36. // Fill the buffer with green
  37. uint8_t* img = NULL;
  38. buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)(&img));
  39. fillRGBA8BufferSolid(img, texWidth, texHeight, buf->getStride(), 0, 255,
  40. 0, 255);
  41. buf->unlock();
  42. ASSERT_EQ(NO_ERROR, mANW->queueBuffer(mANW.get(), buf->getNativeBuffer(),
  43. -1));
  44. ASSERT_EQ(NO_ERROR, mST->updateTexImage());
  45. glBindFramebuffer(GL_FRAMEBUFFER, mFbo);
  46. drawTexture();
  47. glBindFramebuffer(GL_FRAMEBUFFER, 0);
  48. for (int i = 0; i < 4; i++) {
  49. SCOPED_TRACE(String8::format("frame %d", i).string());
  50. ASSERT_EQ(NO_ERROR, native_window_dequeue_buffer_and_wait(mANW.get(),
  51. &anb));
  52. ASSERT_TRUE(anb != NULL);
  53. buf = new GraphicBuffer(anb, false);
  54. // Fill the buffer with red
  55. ASSERT_EQ(NO_ERROR, buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN,
  56. (void**)(&img)));
  57. fillRGBA8BufferSolid(img, texWidth, texHeight, buf->getStride(), 255, 0,
  58. 0, 255);
  59. ASSERT_EQ(NO_ERROR, buf->unlock());
  60. ASSERT_EQ(NO_ERROR, mANW->queueBuffer(mANW.get(),
  61. buf->getNativeBuffer(), -1));
  62. ASSERT_EQ(NO_ERROR, mST->updateTexImage());
  63. drawTexture();
  64. EXPECT_TRUE(checkPixel( 24, 39, 255, 0, 0, 255));
  65. }
  66. glBindFramebuffer(GL_FRAMEBUFFER, mFbo);
  67. EXPECT_TRUE(checkPixel( 24, 39, 0, 255, 0, 255));
  68. }
  69. } // namespace android