Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Unified Diff: cc/texture_uploader_unittest.cc

Issue 11413005: YUV software decode path stride fixes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed set of GL_UNPACK_ALIGNMENT Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/texture_uploader.cc ('k') | cc/video_layer_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/texture_uploader_unittest.cc
diff --git a/cc/texture_uploader_unittest.cc b/cc/texture_uploader_unittest.cc
index 85bc949d12c8ccefee2d3275b48574e63da39eb6..3266369d0cdf21f61643e2500edf0178af1119bf 100644
--- a/cc/texture_uploader_unittest.cc
+++ b/cc/texture_uploader_unittest.cc
@@ -1,10 +1,13 @@
// Copyright 2012 The Chromium Authors. All rights reserved.
+
danakj 2012/11/20 20:43:39 remove this extra newline
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cc/texture_uploader.h"
+#include "base/bits.h"
#include "cc/prioritized_resource.h"
+#include "cc/resource.h"
#include "cc/test/fake_web_graphics_context_3d.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -16,10 +19,35 @@ using namespace WebKit;
namespace cc {
namespace {
-class FakeWebGraphicsContext3DWithQueryTesting : public FakeWebGraphicsContext3D {
+class FakeWebGraphicsContext3DTextureUpload : public FakeWebGraphicsContext3D {
public:
- FakeWebGraphicsContext3DWithQueryTesting() : m_resultAvailable(0)
+ FakeWebGraphicsContext3DTextureUpload()
+ : m_resultAvailable(0),
+ m_unpackAlignment(4)
+ {
+ }
+
+ virtual void pixelStorei(WGC3Denum pname, WGC3Dint param)
{
+ switch (pname) {
+ case GL_UNPACK_ALIGNMENT:
+ // param should be a power of two <= 8
+ EXPECT_EQ(0, param & (param - 1));
+ EXPECT_GE(8, param);
+ switch (param) {
+ case 1:
+ case 2:
+ case 4:
+ case 8:
+ m_unpackAlignment = param;
+ break;
+ default:
+ break;
+ }
+ break;
+ default:
+ break;
+ }
}
virtual void getQueryObjectuivEXT(WebGLId, WGC3Denum type, WGC3Duint* value)
@@ -34,66 +62,165 @@ public:
}
}
+ virtual void texSubImage2D(WGC3Denum target, WGC3Dint level, WGC3Dint xoffset, WGC3Dint yoffset, WGC3Dsizei width, WGC3Dsizei height, WGC3Denum format, WGC3Denum type, const void* pixels)
+ {
+ EXPECT_EQ(GL_TEXTURE_2D, target);
+ EXPECT_EQ(0, level);
+ EXPECT_LE(0, width);
+ EXPECT_LE(0, height);
+ EXPECT_LE(0, xoffset);
+ EXPECT_LE(0, yoffset);
+ EXPECT_LE(0, width);
+ EXPECT_LE(0, height);
+
+ // Check for allowed format/type combination.
+ unsigned int bytesPerPixel = 0;
+ switch (format)
+ {
danakj 2012/11/20 20:43:39 { onto the previous line.
+ case GL_ALPHA:
danakj 2012/11/20 20:43:39 line up the cases with the swich
+ EXPECT_EQ(GL_UNSIGNED_BYTE, type);
+ bytesPerPixel = 1;
+ break;
+ case GL_RGB:
+ EXPECT_NE(GL_UNSIGNED_SHORT_4_4_4_4, type);
+ EXPECT_NE(GL_UNSIGNED_SHORT_5_5_5_1, type);
+ switch (type)
+ {
danakj 2012/11/20 20:43:39 { onto the previous line
+ case GL_UNSIGNED_BYTE:
+ bytesPerPixel = 3;
+ break;
+ case GL_UNSIGNED_SHORT_5_6_5:
+ bytesPerPixel = 2;
+ break;
+ }
+ break;
+ case GL_RGBA:
+ EXPECT_NE(GL_UNSIGNED_SHORT_5_6_5, type);
+ switch (type)
+ {
danakj 2012/11/20 20:43:39 { up
+ case GL_UNSIGNED_BYTE:
danakj 2012/11/20 20:43:39 line up case with switch
+ bytesPerPixel = 4;
+ break;
+ case GL_UNSIGNED_SHORT_4_4_4_4:
+ bytesPerPixel = 2;
+ break;
+ case GL_UNSIGNED_SHORT_5_5_5_1:
+ bytesPerPixel = 2;
+ break;
+ }
+ break;
+ case GL_LUMINANCE:
+ EXPECT_EQ(GL_UNSIGNED_BYTE, type);
+ bytesPerPixel = 1;
+ break;
+ case GL_LUMINANCE_ALPHA:
+ EXPECT_EQ(GL_UNSIGNED_BYTE, type);
+ bytesPerPixel = 2;
+ break;
+ }
+
+ // If NULL, we aren't checking texture contents.
+ if (pixels == NULL)
+ return;
+
+ const uint8 *bytes = static_cast<const uint8*>(pixels);
danakj 2012/11/20 20:43:39 uint8* bytes
+ // We'll expect the first byte of every row to be 0x1, and the last byte to be 0x2
+ const unsigned int stride = base::bits::RoundUp(bytesPerPixel * width, m_unpackAlignment);
+ for (WGC3Dsizei row = 0; row < height; row += 1)
danakj 2012/11/20 20:43:39 ++row
+ {
danakj 2012/11/20 20:43:39 { on previous line
+ const uint8 *rowBytes = bytes + (xoffset * bytesPerPixel + (yoffset + row) * stride);
danakj 2012/11/20 20:43:39 uint8* rowBytes
+ EXPECT_EQ(0x1, rowBytes[0]);
+ EXPECT_EQ(0x2, rowBytes[width * bytesPerPixel - 1]);
+ }
+ }
+
void setResultAvailable(unsigned resultAvailable) { m_resultAvailable = resultAvailable; }
private:
+ unsigned m_unpackAlignment;
unsigned m_resultAvailable;
};
-void uploadTexture(TextureUploader* uploader)
+void uploadTexture(TextureUploader* uploader, WGC3Denum format, const gfx::Size& size, const uint8* data)
{
- gfx::Size size(256, 256);
- uploader->upload(NULL,
+ uploader->upload(data,
gfx::Rect(gfx::Point(0, 0), size),
gfx::Rect(gfx::Point(0, 0), size),
gfx::Vector2d(),
- GL_RGBA,
+ format,
size);
}
TEST(TextureUploaderTest, NumBlockingUploads)
{
- scoped_ptr<FakeWebGraphicsContext3DWithQueryTesting> fakeContext(new FakeWebGraphicsContext3DWithQueryTesting);
+ scoped_ptr<FakeWebGraphicsContext3DTextureUpload> fakeContext(new FakeWebGraphicsContext3DTextureUpload);
scoped_ptr<TextureUploader> uploader = TextureUploader::create(fakeContext.get(), false, false);
fakeContext->setResultAvailable(0);
EXPECT_EQ(0, uploader->numBlockingUploads());
- uploadTexture(uploader.get());
+ uploadTexture(uploader.get(), GL_RGBA, gfx::Size(0, 0), NULL);
EXPECT_EQ(1, uploader->numBlockingUploads());
- uploadTexture(uploader.get());
+ uploadTexture(uploader.get(), GL_RGBA, gfx::Size(0, 0), NULL);
EXPECT_EQ(2, uploader->numBlockingUploads());
fakeContext->setResultAvailable(1);
EXPECT_EQ(0, uploader->numBlockingUploads());
- uploadTexture(uploader.get());
+ uploadTexture(uploader.get(), GL_RGBA, gfx::Size(0, 0), NULL);
EXPECT_EQ(0, uploader->numBlockingUploads());
- uploadTexture(uploader.get());
- uploadTexture(uploader.get());
+ uploadTexture(uploader.get(), GL_RGBA, gfx::Size(0, 0), NULL);
+ uploadTexture(uploader.get(), GL_RGBA, gfx::Size(0, 0), NULL);
EXPECT_EQ(0, uploader->numBlockingUploads());
}
TEST(TextureUploaderTest, MarkPendingUploadsAsNonBlocking)
{
- scoped_ptr<FakeWebGraphicsContext3DWithQueryTesting> fakeContext(new FakeWebGraphicsContext3DWithQueryTesting);
+ scoped_ptr<FakeWebGraphicsContext3DTextureUpload> fakeContext(new FakeWebGraphicsContext3DTextureUpload);
scoped_ptr<TextureUploader> uploader = TextureUploader::create(fakeContext.get(), false, false);
fakeContext->setResultAvailable(0);
EXPECT_EQ(0, uploader->numBlockingUploads());
- uploadTexture(uploader.get());
- uploadTexture(uploader.get());
+ uploadTexture(uploader.get(), GL_RGBA, gfx::Size(0, 0), NULL);
+ uploadTexture(uploader.get(), GL_RGBA, gfx::Size(0, 0), NULL);
EXPECT_EQ(2, uploader->numBlockingUploads());
uploader->markPendingUploadsAsNonBlocking();
EXPECT_EQ(0, uploader->numBlockingUploads());
- uploadTexture(uploader.get());
+ uploadTexture(uploader.get(), GL_RGBA, gfx::Size(0, 0), NULL);
EXPECT_EQ(1, uploader->numBlockingUploads());
fakeContext->setResultAvailable(1);
EXPECT_EQ(0, uploader->numBlockingUploads());
- uploadTexture(uploader.get());
+ uploadTexture(uploader.get(), GL_RGBA, gfx::Size(0, 0), NULL);
uploader->markPendingUploadsAsNonBlocking();
EXPECT_EQ(0, uploader->numBlockingUploads());
}
+TEST(TextureUploaderTest, UploadContentsTest)
+{
+ scoped_ptr<FakeWebGraphicsContext3DTextureUpload> fakeContext(new FakeWebGraphicsContext3DTextureUpload);
+ scoped_ptr<TextureUploader> uploader = TextureUploader::create(fakeContext.get(), false, false);
+ uint8 buffer[256 * 256 * 4];
+
+ // Upload a tightly packed 256x256 RGBA texture.
danakj 2012/11/20 20:43:39 How about a test with a non-multiple-of-bytes-per-
+ memset(buffer, 0, sizeof(buffer));
+ for (int i = 0; i < 256; i += 1)
danakj 2012/11/20 20:43:39 ++i
+ {
danakj 2012/11/20 20:43:39 { up
+ // Mark the beginning and end of each row, for the test.
+ buffer[i * 4 * 256] = 0x1;
+ buffer[(i + 1) * 4 * 256 - 1] = 0x2;
+ }
+ uploadTexture(uploader.get(), GL_RGBA, gfx::Size(256, 256), buffer);
+
+ // Upload a tightly packed 82x86 LUMINANCE texture.
+ memset(buffer, 0, sizeof(buffer));
+ for (int i = 0; i < 86; i += 1)
danakj 2012/11/20 20:43:39 ++i
+ {
danakj 2012/11/20 20:43:39 { up
+ // Mark the beginning and end of each row, for the test.
+ buffer[i * 1 * 82] = 0x1;
+ buffer[(i + 1) * 82 - 1] = 0x2;
+ }
+ uploadTexture(uploader.get(), GL_LUMINANCE, gfx::Size(82, 86), buffer);
+}
+
} // namespace
} // namespace cc
« no previous file with comments | « cc/texture_uploader.cc ('k') | cc/video_layer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698