File: DrawingBufferSoftwareRenderingTest.cpp

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (104 lines) | stat: -rw-r--r-- 4,182 bytes parent folder | download
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 2016 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 "platform/graphics/gpu/DrawingBuffer.h"

#include "cc/resources/single_release_callback.h"
#include "cc/resources/texture_mailbox.h"
#include "gpu/command_buffer/client/gles2_interface_stub.h"
#include "platform/graphics/gpu/DrawingBufferTestHelpers.h"
#include "testing/gtest/include/gtest/gtest.h"

// These unit tests are separate from DrawingBufferTests.cpp because they are
// built as a part of webkit_unittests instead blink_platform_unittests. This is
// because the software rendering mode has a dependency on the blink::Platform
// interface for buffer allocations.

namespace blink {
namespace {

using namespace testing;

class WebGraphicsContext3DProviderSoftwareRenderingForTests
    : public WebGraphicsContext3DProvider {
 public:
  WebGraphicsContext3DProviderSoftwareRenderingForTests(
      std::unique_ptr<gpu::gles2::GLES2Interface> gl)
      : m_gl(std::move(gl)) {}

  gpu::gles2::GLES2Interface* contextGL() override { return m_gl.get(); }
  bool isSoftwareRendering() const override { return true; }

  // Not used by WebGL code.
  GrContext* grContext() override { return nullptr; }
  bool bindToCurrentThread() override { return false; }
  gpu::Capabilities getCapabilities() override { return gpu::Capabilities(); }
  void setLostContextCallback(const base::Closure&) {}
  void setErrorMessageCallback(
      const base::Callback<void(const char*, int32_t id)>&) {}
  void signalQuery(uint32_t, const base::Closure&) override {}

 private:
  std::unique_ptr<gpu::gles2::GLES2Interface> m_gl;
};

class DrawingBufferSoftwareRenderingTest : public Test {
 protected:
  void SetUp() override {
    IntSize initialSize(InitialWidth, InitialHeight);
    std::unique_ptr<GLES2InterfaceForTests> gl =
        WTF::wrapUnique(new GLES2InterfaceForTests);
    std::unique_ptr<WebGraphicsContext3DProviderSoftwareRenderingForTests>
        provider = WTF::wrapUnique(
            new WebGraphicsContext3DProviderSoftwareRenderingForTests(
                std::move(gl)));
    m_drawingBuffer = DrawingBufferForTests::create(
        std::move(provider), nullptr, initialSize, DrawingBuffer::Preserve);
    CHECK(m_drawingBuffer);
  }

  RefPtr<DrawingBufferForTests> m_drawingBuffer;
  bool m_isSoftwareRendering = false;
};

TEST_F(DrawingBufferSoftwareRenderingTest, bitmapRecycling) {
  cc::TextureMailbox textureMailbox;
  std::unique_ptr<cc::SingleReleaseCallback> releaseCallback1;
  std::unique_ptr<cc::SingleReleaseCallback> releaseCallback2;
  std::unique_ptr<cc::SingleReleaseCallback> releaseCallback3;
  IntSize initialSize(InitialWidth, InitialHeight);
  IntSize alternateSize(InitialWidth, AlternateHeight);

  m_drawingBuffer->resize(initialSize);
  m_drawingBuffer->markContentsChanged();
  m_drawingBuffer->PrepareTextureMailbox(
      &textureMailbox, &releaseCallback1);  // create a bitmap.
  EXPECT_EQ(0, m_drawingBuffer->recycledBitmapCount());
  releaseCallback1->Run(
      gpu::SyncToken(),
      false /* lostResource */);  // release bitmap to the recycling queue
  EXPECT_EQ(1, m_drawingBuffer->recycledBitmapCount());
  m_drawingBuffer->markContentsChanged();
  m_drawingBuffer->PrepareTextureMailbox(
      &textureMailbox, &releaseCallback2);  // recycle a bitmap.
  EXPECT_EQ(0, m_drawingBuffer->recycledBitmapCount());
  releaseCallback2->Run(
      gpu::SyncToken(),
      false /* lostResource */);  // release bitmap to the recycling queue
  EXPECT_EQ(1, m_drawingBuffer->recycledBitmapCount());
  m_drawingBuffer->resize(alternateSize);
  m_drawingBuffer->markContentsChanged();
  // Regression test for crbug.com/647896 - Next line must not crash
  m_drawingBuffer->PrepareTextureMailbox(
      &textureMailbox,
      &releaseCallback3);  // cause recycling queue to be purged due to resize
  EXPECT_EQ(0, m_drawingBuffer->recycledBitmapCount());
  releaseCallback3->Run(gpu::SyncToken(), false /* lostResource */);
  EXPECT_EQ(1, m_drawingBuffer->recycledBitmapCount());

  m_drawingBuffer->beginDestruction();
}

}  // unnamed namespace
}  // blink