1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include <memory> 6 7 #include "main.h" 8 #include "testbase.h" 9 #include "utils.h" 10 11 namespace glbench { 12 13 class ReadPixelTest : public TestBase { 14 public: 15 ReadPixelTest() : pixels_(NULL) {} 16 virtual ~ReadPixelTest() {} 17 virtual bool TestFunc(uint64_t iterations); 18 virtual bool Run(); 19 virtual const char* Name() const { return "pixel_read"; } 20 virtual bool IsDrawTest() const { return false; } 21 virtual const char* Unit() const { return "mpixels_sec"; } 22 23 private: 24 void* pixels_; 25 DISALLOW_COPY_AND_ASSIGN(ReadPixelTest); 26 }; 27 28 bool ReadPixelTest::TestFunc(uint64_t iterations) { 29 glReadPixels(0, 0, g_width, g_height, GL_RGBA, GL_UNSIGNED_BYTE, pixels_); 30 CHECK(glGetError() == 0); 31 for (uint64_t i = 0; i < iterations - 1; i++) 32 glReadPixels(0, 0, g_width, g_height, GL_RGBA, GL_UNSIGNED_BYTE, pixels_); 33 return true; 34 } 35 36 bool ReadPixelTest::Run() { 37 // One GL_RGBA pixel takes 4 bytes. 38 const int row_size = g_width * 4; 39 // Default GL_PACK_ALIGNMENT is 4, round up pixel row size to multiple of 4. 40 // This is a no-op because row_size is already divisible by 4. 41 // One is added so that we can test reads into unaligned location. 42 std::unique_ptr<char[]> buf(new char[((row_size + 3) & ~3) * g_height + 1]); 43 pixels_ = buf.get(); 44 RunTest(this, "pixel_read", g_width * g_height, g_width, g_height, true); 45 46 // Reducing GL_PACK_ALIGNMENT can only make rows smaller. No need to 47 // reallocate the buffer. 48 glPixelStorei(GL_PACK_ALIGNMENT, 1); 49 RunTest(this, "pixel_read_2", g_width * g_height, g_width, g_height, true); 50 51 pixels_ = static_cast<void*>(buf.get() + 1); 52 RunTest(this, "pixel_read_3", g_width * g_height, g_width, g_height, true); 53 54 return true; 55 } 56 57 TestBase* GetReadPixelTest() { 58 return new ReadPixelTest; 59 } 60 61 } // namespace glbench 62