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 "base/logging.h"
6 #include "base/memory/scoped_ptr.h"
7
8 #include "main.h"
9 #include "testbase.h"
10
11
12 namespace glbench {
13
14
15 class ReadPixelTest : public TestBase {
16 public:
ReadPixelTest()17 ReadPixelTest() : pixels_(NULL) {}
~ReadPixelTest()18 virtual ~ReadPixelTest() {}
19 virtual bool TestFunc(uint64_t iterations);
20 virtual bool Run();
Name() const21 virtual const char* Name() const { return "pixel_read"; }
IsDrawTest() const22 virtual bool IsDrawTest() const { return false; }
Unit() const23 virtual const char* Unit() const { return "mpixels_sec"; }
24
25 private:
26 void* pixels_;
27 DISALLOW_COPY_AND_ASSIGN(ReadPixelTest);
28 };
29
30
TestFunc(uint64_t iterations)31 bool ReadPixelTest::TestFunc(uint64_t iterations) {
32 glReadPixels(0, 0, g_width, g_height, GL_RGBA, GL_UNSIGNED_BYTE, pixels_);
33 CHECK(glGetError() == 0);
34 for (uint64_t i = 0; i < iterations - 1; i++)
35 glReadPixels(0, 0, g_width, g_height, GL_RGBA, GL_UNSIGNED_BYTE, pixels_);
36 return true;
37 }
38
39
Run()40 bool ReadPixelTest::Run() {
41 // One GL_RGBA pixel takes 4 bytes.
42 const int row_size = g_width * 4;
43 // Default GL_PACK_ALIGNMENT is 4, round up pixel row size to multiple of 4.
44 // This is a no-op because row_size is already divisible by 4.
45 // One is added so that we can test reads into unaligned location.
46 scoped_ptr<char[]> buf(new char[((row_size + 3) & ~3) * g_height + 1]);
47 pixels_ = buf.get();
48 RunTest(this, "pixel_read", g_width * g_height, g_width, g_height, true);
49
50 // Reducing GL_PACK_ALIGNMENT can only make rows smaller. No need to
51 // reallocate the buffer.
52 glPixelStorei(GL_PACK_ALIGNMENT, 1);
53 RunTest(this, "pixel_read_2", g_width * g_height, g_width, g_height, true);
54
55 pixels_ = static_cast<void*>(buf.get() + 1);
56 RunTest(this, "pixel_read_3", g_width * g_height, g_width, g_height, true);
57
58 return true;
59 }
60
61
GetReadPixelTest()62 TestBase* GetReadPixelTest() {
63 return new ReadPixelTest;
64 }
65
66
67 } // namespace glbench
68