summaryrefslogtreecommitdiffstats
path: root/cc/throttled_texture_uploader_unittest.cc
blob: 83f4415c9f5ed448557d88d2eedf9015142a6289 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "config.h"

#include "cc/throttled_texture_uploader.h"

#include "CCPrioritizedTexture.h"
#include "cc/test/fake_web_graphics_context_3d.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/khronos/GLES2/gl2.h"
#include "third_party/khronos/GLES2/gl2ext.h"

using namespace cc;
using namespace WebKit;

namespace {

class FakeWebGraphicsContext3DWithQueryTesting : public FakeWebGraphicsContext3D {
public:
    FakeWebGraphicsContext3DWithQueryTesting() : m_resultAvailable(0)
    {
    }

    virtual void getQueryObjectuivEXT(WebGLId, WGC3Denum type, WGC3Duint* value)
    {
        switch (type) {
        case GL_QUERY_RESULT_AVAILABLE_EXT:
            *value = m_resultAvailable;
            break;
        default:
            *value = 0;
            break;
        }
    }

    void setResultAvailable(unsigned resultAvailable) { m_resultAvailable = resultAvailable; }

private:
    unsigned m_resultAvailable;
};

void uploadTexture(
    ThrottledTextureUploader* uploader, CCPrioritizedTexture* texture)
{
    uploader->uploadTexture(NULL,
                            texture,
                            NULL,
                            IntRect(IntPoint(0,0), texture->size()),
                            IntRect(IntPoint(0,0), texture->size()),
                            IntSize());
}

TEST(ThrottledTextureUploaderTest, NumBlockingUploads)
{
    scoped_ptr<FakeWebGraphicsContext3DWithQueryTesting> fakeContext(new FakeWebGraphicsContext3DWithQueryTesting);
    scoped_ptr<ThrottledTextureUploader> uploader = ThrottledTextureUploader::create(fakeContext.get());
    scoped_ptr<CCPrioritizedTexture> texture =
        CCPrioritizedTexture::create(NULL, IntSize(256, 256), GL_RGBA);

    fakeContext->setResultAvailable(0);
    EXPECT_EQ(0, uploader->numBlockingUploads());
    uploadTexture(uploader.get(), texture.get());
    EXPECT_EQ(1, uploader->numBlockingUploads());
    uploadTexture(uploader.get(), texture.get());
    EXPECT_EQ(2, uploader->numBlockingUploads());

    fakeContext->setResultAvailable(1);
    EXPECT_EQ(0, uploader->numBlockingUploads());
    uploadTexture(uploader.get(), texture.get());
    EXPECT_EQ(0, uploader->numBlockingUploads());
    uploadTexture(uploader.get(), texture.get());
    uploadTexture(uploader.get(), texture.get());
    EXPECT_EQ(0, uploader->numBlockingUploads());
}

TEST(ThrottledTextureUploaderTest, MarkPendingUploadsAsNonBlocking)
{
    scoped_ptr<FakeWebGraphicsContext3DWithQueryTesting> fakeContext(new FakeWebGraphicsContext3DWithQueryTesting);
    scoped_ptr<ThrottledTextureUploader> uploader = ThrottledTextureUploader::create(fakeContext.get());
    scoped_ptr<CCPrioritizedTexture> texture =
        CCPrioritizedTexture::create(NULL, IntSize(256, 256), GL_RGBA);

    fakeContext->setResultAvailable(0);
    EXPECT_EQ(0, uploader->numBlockingUploads());
    uploadTexture(uploader.get(), texture.get());
    uploadTexture(uploader.get(), texture.get());
    EXPECT_EQ(2, uploader->numBlockingUploads());

    uploader->markPendingUploadsAsNonBlocking();
    EXPECT_EQ(0, uploader->numBlockingUploads());
    uploadTexture(uploader.get(), texture.get());
    EXPECT_EQ(1, uploader->numBlockingUploads());

    fakeContext->setResultAvailable(1);
    EXPECT_EQ(0, uploader->numBlockingUploads());
    uploadTexture(uploader.get(), texture.get());
    uploader->markPendingUploadsAsNonBlocking();
    EXPECT_EQ(0, uploader->numBlockingUploads());
}

} // namespace