File: test_raster_interface.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (219 lines) | stat: -rw-r--r-- 6,582 bytes parent folder | download | duplicates (6)
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
216
217
218
219
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "components/viz/test/test_raster_interface.h"

#include <limits>
#include <utility>

#include "base/notreached.h"
#include "base/time/time.h"
#include "gpu/GLES2/gl2extchromium.h"
#include "gpu/command_buffer/common/constants.h"

namespace viz {

TestRasterInterface::TestRasterInterface() {
  caps_.max_texture_size = 2048;
}

TestRasterInterface::~TestRasterInterface() = default;

void TestRasterInterface::Finish() {
  if (test_support_)
    test_support_->CallAllSyncPointCallbacks();
}

void TestRasterInterface::Flush() {
  if (test_support_)
    test_support_->CallAllSyncPointCallbacks();
}

GLenum TestRasterInterface::GetError() {
  return 0;
}

GLenum TestRasterInterface::GetGraphicsResetStatusKHR() {
  if (context_lost_)
    return GL_UNKNOWN_CONTEXT_RESET_KHR;
  return GL_NO_ERROR;
}

void TestRasterInterface::LoseContextCHROMIUM(GLenum current, GLenum other) {
  if (context_lost_)
    return;

  context_lost_ = true;
  if (context_lost_callback_)
    std::move(context_lost_callback_).Run();
}

void TestRasterInterface::GenQueriesEXT(GLsizei n, GLuint* queries) {
  for (GLsizei i = 0; i < n; ++i) {
    queries[i] = 1u;
  }
}

void TestRasterInterface::DeleteQueriesEXT(GLsizei n, const GLuint* queries) {}
void TestRasterInterface::BeginQueryEXT(GLenum target, GLuint id) {}
void TestRasterInterface::EndQueryEXT(GLenum target) {}
void TestRasterInterface::QueryCounterEXT(GLuint id, GLenum target) {}

void TestRasterInterface::GetQueryObjectuivEXT(GLuint id,
                                               GLenum pname,
                                               GLuint* params) {
  // If the context is lost, behave as if result is available.
  if (pname == GL_QUERY_RESULT_AVAILABLE_EXT ||
      pname == GL_QUERY_RESULT_AVAILABLE_NO_FLUSH_CHROMIUM_EXT) {
    *params = 1;
  }
}

void TestRasterInterface::GetQueryObjectui64vEXT(GLuint id,
                                                 GLenum pname,
                                                 GLuint64* params) {
  // This is used for testing GL_COMMANDS_ISSUED_TIMESTAMP_QUERY, so we return
  // the maximum that base::TimeDelta()::InMicroseconds() could return.
  if (pname == GL_QUERY_RESULT_EXT) {
    static_assert(std::is_same<decltype(base::TimeDelta().InMicroseconds()),
                               int64_t>::value,
                  "Expected the return type of "
                  "base::TimeDelta()::InMicroseconds() to be int64_t");
    *params = std::numeric_limits<int64_t>::max();
  } else {
    NOTREACHED();
  }
}

gpu::SyncToken TestRasterInterface::ScheduleImageDecode(
    base::span<const uint8_t> encoded_data,
    const gfx::Size& output_size,
    uint32_t transfer_cache_entry_id,
    const gfx::ColorSpace& target_color_space,
    bool needs_mips) {
  return gpu::SyncToken();
}

GLuint TestRasterInterface::CreateAndConsumeForGpuRaster(
    const gpu::Mailbox& mailbox) {
  NOTREACHED();
}

GLuint TestRasterInterface::CreateAndConsumeForGpuRaster(
    const scoped_refptr<gpu::ClientSharedImage>& shared_image) {
  NOTREACHED();
}

void TestRasterInterface::DeleteGpuRasterTexture(GLuint texture) {
  NOTREACHED();
}

void TestRasterInterface::BeginGpuRaster() {
  NOTREACHED();
}

void TestRasterInterface::EndGpuRaster() {
  NOTREACHED();
}

void TestRasterInterface::BeginSharedImageAccessDirectCHROMIUM(GLuint texture,
                                                               GLenum mode) {
  NOTREACHED();
}

void TestRasterInterface::EndSharedImageAccessDirectCHROMIUM(GLuint texture) {
  NOTREACHED();
}

void TestRasterInterface::InitializeDiscardableTextureCHROMIUM(GLuint texture) {
  NOTREACHED();
}

void TestRasterInterface::UnlockDiscardableTextureCHROMIUM(GLuint texture) {
  NOTREACHED();
}

bool TestRasterInterface::LockDiscardableTextureCHROMIUM(GLuint texture) {
  NOTREACHED();
}

void TestRasterInterface::GenSyncTokenCHROMIUM(GLbyte* sync_token) {
  // Don't return a valid sync token if context is lost. This matches behavior
  // of CommandBufferProxyImpl.
  if (context_lost_)
    return;

  gpu::SyncToken sync_token_data(gpu::CommandBufferNamespace::GPU_IO,
                                 gpu::CommandBufferId(),
                                 next_insert_fence_sync_++);
  sync_token_data.SetVerifyFlush();
  memcpy(sync_token, &sync_token_data, sizeof(sync_token_data));
}

void TestRasterInterface::GenUnverifiedSyncTokenCHROMIUM(GLbyte* sync_token) {
  // Don't return a valid sync token if context is lost. This matches behavior
  // of CommandBufferProxyImpl.
  if (context_lost_)
    return;

  gpu::SyncToken sync_token_data(gpu::CommandBufferNamespace::GPU_IO,
                                 gpu::CommandBufferId(),
                                 next_insert_fence_sync_++);
  memcpy(sync_token, &sync_token_data, sizeof(sync_token_data));
}

void TestRasterInterface::VerifySyncTokensCHROMIUM(GLbyte** sync_tokens,
                                                   GLsizei count) {
  for (GLsizei i = 0; i < count; ++i) {
    gpu::SyncToken sync_token_data;
    memcpy(sync_token_data.GetData(), sync_tokens[i], sizeof(sync_token_data));
    sync_token_data.SetVerifyFlush();
    memcpy(sync_tokens[i], &sync_token_data, sizeof(sync_token_data));
  }
}

void TestRasterInterface::WaitSyncTokenCHROMIUM(const GLbyte* sync_token) {
  gpu::SyncToken sync_token_data;
  if (sync_token)
    memcpy(&sync_token_data, sync_token, sizeof(sync_token_data));

  if (sync_token_data.release_count() >
      last_waited_sync_token_.release_count()) {
    last_waited_sync_token_ = sync_token_data;
  }
}

void TestRasterInterface::ShallowFlushCHROMIUM() {
  if (test_support_)
    test_support_->CallAllSyncPointCallbacks();
}

void TestRasterInterface::set_supports_gpu_memory_buffer_format(
    gfx::BufferFormat format,
    bool support) {
  if (support) {
    caps_.gpu_memory_buffer_formats.Put(format);
  } else {
    caps_.gpu_memory_buffer_formats.Remove(format);
  }
}

bool TestRasterInterface::ReadbackImagePixels(
    const gpu::Mailbox& source_mailbox,
    const SkImageInfo& dst_info,
    GLuint dst_row_bytes,
    int src_x,
    int src_y,
    int plane_index,
    void* dst_pixels) {
  auto size = dst_info.computeByteSize(dst_row_bytes);
  memset(dst_pixels, 0, size);
  return true;
}
}  // namespace viz