blob: f727547ab439aaae7414f4b85ab0063a3152c4a8 [file] [log] [blame]
Alexey Marinichev9f9b8732010-05-20 19:33:44 -07001// 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"
Chris Masone28cc0252011-05-13 11:45:07 -07006#include "base/memory/scoped_ptr.h"
Alexey Marinichev9f9b8732010-05-20 19:33:44 -07007
8#include "main.h"
9#include "testbase.h"
10
11
12namespace glbench {
13
14
15class ReadPixelTest : public TestBase {
16 public:
17 ReadPixelTest() : pixels_(NULL) {}
18 virtual ~ReadPixelTest() {}
Ilja H. Friedel439ea142014-02-21 20:29:10 -080019 virtual bool TestFunc(uint64_t iterations);
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070020 virtual bool Run();
Alexey Marinichevf50ecb12010-06-14 15:21:41 -070021 virtual const char* Name() const { return "pixel_read"; }
Daniel Kurtzbcad4fb2014-06-18 12:31:03 +080022 virtual bool IsDrawTest() const { return false; }
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070023
24 private:
25 void* pixels_;
26 DISALLOW_COPY_AND_ASSIGN(ReadPixelTest);
27};
28
29
Ilja H. Friedel439ea142014-02-21 20:29:10 -080030bool ReadPixelTest::TestFunc(uint64_t iterations) {
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070031 glReadPixels(0, 0, g_width, g_height, GL_RGBA, GL_UNSIGNED_BYTE, pixels_);
32 CHECK(glGetError() == 0);
Ilja H. Friedel439ea142014-02-21 20:29:10 -080033 for (uint64_t i = 0; i < iterations - 1; i++)
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070034 glReadPixels(0, 0, g_width, g_height, GL_RGBA, GL_UNSIGNED_BYTE, pixels_);
35 return true;
36}
37
38
39bool ReadPixelTest::Run() {
40 // One GL_RGBA pixel takes 4 bytes.
41 const int row_size = g_width * 4;
42 // Default GL_PACK_ALIGNMENT is 4, round up pixel row size to multiple of 4.
43 // This is a no-op because row_size is already divisible by 4.
44 // One is added so that we can test reads into unaligned location.
Ben Chan88548a12014-01-27 23:38:25 -080045 scoped_ptr<char[]> buf(new char[((row_size + 3) & ~3) * g_height + 1]);
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070046 pixels_ = buf.get();
Ilja Friedel3907fd12014-04-15 14:29:43 -070047 RunTest(this, "mpixels_sec_pixel_read", g_width * g_height, g_width, g_height, true);
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070048
49 // Reducing GL_PACK_ALIGNMENT can only make rows smaller. No need to
50 // reallocate the buffer.
51 glPixelStorei(GL_PACK_ALIGNMENT, 1);
Ilja Friedel3907fd12014-04-15 14:29:43 -070052 RunTest(this, "mpixels_sec_pixel_read_2", g_width * g_height, g_width, g_height, true);
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070053
54 pixels_ = static_cast<void*>(buf.get() + 1);
Ilja Friedel3907fd12014-04-15 14:29:43 -070055 RunTest(this, "mpixels_sec_pixel_read_3", g_width * g_height, g_width, g_height, true);
Alexey Marinichev9f9b8732010-05-20 19:33:44 -070056
57 return true;
58}
59
60
61TestBase* GetReadPixelTest() {
62 return new ReadPixelTest;
63}
64
65
66} // namespace glbench