summaryrefslogtreecommitdiffstats
path: root/cc/test/layer_tree_pixel_resource_test.cc
blob: bc323f138dc2b6368a502b8b7051956e47527bc4 (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// Copyright 2014 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 "cc/test/layer_tree_pixel_resource_test.h"

#include "cc/layers/layer.h"
#include "cc/raster/bitmap_tile_task_worker_pool.h"
#include "cc/raster/gpu_rasterizer.h"
#include "cc/raster/gpu_tile_task_worker_pool.h"
#include "cc/raster/one_copy_tile_task_worker_pool.h"
#include "cc/raster/pixel_buffer_tile_task_worker_pool.h"
#include "cc/raster/tile_task_worker_pool.h"
#include "cc/raster/zero_copy_tile_task_worker_pool.h"
#include "cc/resources/resource_pool.h"
#include "cc/test/fake_output_surface.h"
#include "gpu/GLES2/gl2extchromium.h"

namespace cc {

namespace {

bool IsTestCaseSupported(PixelResourceTestCase test_case) {
  switch (test_case) {
    case SOFTWARE:
    case GL_GPU_RASTER_2D_DRAW:
    case GL_ZERO_COPY_2D_DRAW:
    case GL_ZERO_COPY_RECT_DRAW:
    case GL_ONE_COPY_2D_STAGING_2D_DRAW:
    case GL_ONE_COPY_RECT_STAGING_2D_DRAW:
    case GL_ASYNC_UPLOAD_2D_DRAW:
      return true;
    case GL_ZERO_COPY_EXTERNAL_DRAW:
    case GL_ONE_COPY_EXTERNAL_STAGING_2D_DRAW:
      // These should all be enabled in practice.
      // TODO(enne): look into getting texture external oes enabled.
      return false;
  }

  NOTREACHED();
  return false;
}

}  // namespace

LayerTreeHostPixelResourceTest::LayerTreeHostPixelResourceTest(
    PixelResourceTestCase test_case)
    : staging_texture_target_(GL_INVALID_VALUE),
      draw_texture_target_(GL_INVALID_VALUE),
      resource_pool_option_(BITMAP_TILE_TASK_WORKER_POOL),
      initialized_(false),
      test_case_(test_case) {
  InitializeFromTestCase(test_case);
}

LayerTreeHostPixelResourceTest::LayerTreeHostPixelResourceTest()
    : staging_texture_target_(GL_INVALID_VALUE),
      draw_texture_target_(GL_INVALID_VALUE),
      resource_pool_option_(BITMAP_TILE_TASK_WORKER_POOL),
      initialized_(false),
      test_case_(SOFTWARE) {
}

void LayerTreeHostPixelResourceTest::InitializeFromTestCase(
    PixelResourceTestCase test_case) {
  DCHECK(!initialized_);
  initialized_ = true;
  switch (test_case) {
    case SOFTWARE:
      test_type_ = PIXEL_TEST_SOFTWARE;
      staging_texture_target_ = GL_INVALID_VALUE;
      draw_texture_target_ = GL_INVALID_VALUE;
      resource_pool_option_ = BITMAP_TILE_TASK_WORKER_POOL;
      return;
    case GL_GPU_RASTER_2D_DRAW:
      test_type_ = PIXEL_TEST_GL;
      staging_texture_target_ = GL_INVALID_VALUE;
      draw_texture_target_ = GL_TEXTURE_2D;
      resource_pool_option_ = GPU_TILE_TASK_WORKER_POOL;
      return;
    case GL_ONE_COPY_2D_STAGING_2D_DRAW:
      test_type_ = PIXEL_TEST_GL;
      staging_texture_target_ = GL_TEXTURE_2D;
      draw_texture_target_ = GL_TEXTURE_2D;
      resource_pool_option_ = ONE_COPY_TILE_TASK_WORKER_POOL;
      return;
    case GL_ONE_COPY_RECT_STAGING_2D_DRAW:
      test_type_ = PIXEL_TEST_GL;
      staging_texture_target_ = GL_TEXTURE_RECTANGLE_ARB;
      draw_texture_target_ = GL_TEXTURE_2D;
      resource_pool_option_ = ONE_COPY_TILE_TASK_WORKER_POOL;
      return;
    case GL_ONE_COPY_EXTERNAL_STAGING_2D_DRAW:
      test_type_ = PIXEL_TEST_GL;
      staging_texture_target_ = GL_TEXTURE_EXTERNAL_OES;
      draw_texture_target_ = GL_TEXTURE_2D;
      resource_pool_option_ = ONE_COPY_TILE_TASK_WORKER_POOL;
      return;
    case GL_ZERO_COPY_2D_DRAW:
      test_type_ = PIXEL_TEST_GL;
      staging_texture_target_ = GL_INVALID_VALUE;
      draw_texture_target_ = GL_TEXTURE_2D;
      resource_pool_option_ = ZERO_COPY_TILE_TASK_WORKER_POOL;
      return;
    case GL_ZERO_COPY_RECT_DRAW:
      test_type_ = PIXEL_TEST_GL;
      staging_texture_target_ = GL_INVALID_VALUE;
      draw_texture_target_ = GL_TEXTURE_RECTANGLE_ARB;
      resource_pool_option_ = ZERO_COPY_TILE_TASK_WORKER_POOL;
      return;
    case GL_ZERO_COPY_EXTERNAL_DRAW:
      test_type_ = PIXEL_TEST_GL;
      staging_texture_target_ = GL_INVALID_VALUE;
      draw_texture_target_ = GL_TEXTURE_EXTERNAL_OES;
      resource_pool_option_ = ZERO_COPY_TILE_TASK_WORKER_POOL;
      return;
    case GL_ASYNC_UPLOAD_2D_DRAW:
      test_type_ = PIXEL_TEST_GL;
      staging_texture_target_ = GL_INVALID_VALUE;
      draw_texture_target_ = GL_TEXTURE_2D;
      resource_pool_option_ = PIXEL_BUFFER_TILE_TASK_WORKER_POOL;
      return;
  }
  NOTREACHED();
}

void LayerTreeHostPixelResourceTest::CreateResourceAndTileTaskWorkerPool(
    LayerTreeHostImpl* host_impl,
    scoped_ptr<TileTaskWorkerPool>* tile_task_worker_pool,
    scoped_ptr<ResourcePool>* resource_pool,
    scoped_ptr<ResourcePool>* staging_resource_pool) {
  base::SingleThreadTaskRunner* task_runner =
      proxy()->HasImplThread() ? proxy()->ImplThreadTaskRunner()
                               : proxy()->MainThreadTaskRunner();
  DCHECK(task_runner);
  DCHECK(initialized_);

  ContextProvider* context_provider =
      host_impl->output_surface()->context_provider();
  ResourceProvider* resource_provider = host_impl->resource_provider();
  size_t max_transfer_buffer_usage_bytes = 1024u * 1024u * 60u;
  int max_bytes_per_copy_operation = 1024 * 1024;

  switch (resource_pool_option_) {
    case BITMAP_TILE_TASK_WORKER_POOL:
      EXPECT_FALSE(context_provider);
      EXPECT_EQ(PIXEL_TEST_SOFTWARE, test_type_);
      *resource_pool =
          ResourcePool::Create(resource_provider,
                               draw_texture_target_);

      *tile_task_worker_pool = BitmapTileTaskWorkerPool::Create(
          task_runner, task_graph_runner(), resource_provider);
      break;
    case GPU_TILE_TASK_WORKER_POOL:
      EXPECT_TRUE(context_provider);
      EXPECT_EQ(PIXEL_TEST_GL, test_type_);
      *resource_pool =
          ResourcePool::Create(resource_provider,
                               draw_texture_target_);

      *tile_task_worker_pool = GpuTileTaskWorkerPool::Create(
          task_runner, task_graph_runner(), context_provider, resource_provider,
          false, 0);
      break;
    case ZERO_COPY_TILE_TASK_WORKER_POOL:
      EXPECT_TRUE(context_provider);
      EXPECT_EQ(PIXEL_TEST_GL, test_type_);
      EXPECT_TRUE(host_impl->GetRendererCapabilities().using_image);
      *resource_pool =
          ResourcePool::Create(resource_provider, draw_texture_target_);

      *tile_task_worker_pool = ZeroCopyTileTaskWorkerPool::Create(
          task_runner, task_graph_runner(), resource_provider);
      break;
    case ONE_COPY_TILE_TASK_WORKER_POOL:
      EXPECT_TRUE(context_provider);
      EXPECT_EQ(PIXEL_TEST_GL, test_type_);
      EXPECT_TRUE(host_impl->GetRendererCapabilities().using_image);
      // We need to create a staging resource pool when using copy rasterizer.
      *staging_resource_pool =
          ResourcePool::Create(resource_provider, staging_texture_target_);
      *resource_pool =
          ResourcePool::Create(resource_provider, draw_texture_target_);

      *tile_task_worker_pool = OneCopyTileTaskWorkerPool::Create(
          task_runner, task_graph_runner(), context_provider, resource_provider,
          staging_resource_pool->get(), max_bytes_per_copy_operation, false);
      break;
    case PIXEL_BUFFER_TILE_TASK_WORKER_POOL:
      EXPECT_TRUE(context_provider);
      EXPECT_EQ(PIXEL_TEST_GL, test_type_);
      *resource_pool = ResourcePool::Create(
          resource_provider, draw_texture_target_);

      *tile_task_worker_pool = PixelBufferTileTaskWorkerPool::Create(
          task_runner, task_graph_runner(), context_provider, resource_provider,
          max_transfer_buffer_usage_bytes);
      break;
  }
}

void LayerTreeHostPixelResourceTest::RunPixelResourceTest(
    scoped_refptr<Layer> content_root,
    base::FilePath file_name) {
  if (!IsTestCaseSupported(test_case_))
    return;
  RunPixelTest(test_type_, content_root, file_name);
}

ParameterizedPixelResourceTest::ParameterizedPixelResourceTest()
    : LayerTreeHostPixelResourceTest(GetParam()) {
}

}  // namespace cc