Skip to content

Commit

Permalink
Change std::find() to use base:: functions: gpu/
Browse files Browse the repository at this point in the history
Simplifies code slightly.

Bug: 1368812
Change-Id: I17971cc782478419bec924854a16eafaed74f4cc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3928121
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Zhenyao Mo <zmo@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1052791}
  • Loading branch information
pkasting authored and Chromium LUCI CQ committed Sep 29, 2022
1 parent c541bce commit fb15d03
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "gpu/command_buffer/service/shared_image/shared_image_backing.h"

#include "base/notreached.h"
#include "base/ranges/algorithm.h"
#include "base/trace_event/process_memory_dump.h"
#include "build/build_config.h"
#include "components/viz/common/resources/resource_format_utils.h"
Expand Down Expand Up @@ -218,7 +219,7 @@ void SharedImageBacking::ReleaseRef(SharedImageRepresentation* representation) {
AutoLock auto_lock(this);
DCHECK(is_ref_counted_);

auto found = std::find(refs_.begin(), refs_.end(), representation);
auto found = base::ranges::find(refs_, representation);
DCHECK(found != refs_.end());

// If the found representation is the first (owning) ref, free the attributed
Expand Down
10 changes: 5 additions & 5 deletions gpu/command_buffer/service/value_validator.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
#ifndef GPU_COMMAND_BUFFER_SERVICE_VALUE_VALIDATOR_H_
#define GPU_COMMAND_BUFFER_SERVICE_VALUE_VALIDATOR_H_

#include <algorithm>
#include <vector>

#include "base/containers/contains.h"
#include "base/ranges/algorithm.h"

namespace gpu {

// ValueValidator returns true if a value is valid.
Expand All @@ -36,8 +38,7 @@ class ValueValidator {

void RemoveValues(const T* invalid_values, int num_values) {
for (int ii = 0; ii < num_values; ++ii) {
auto iter = std::find(valid_values_.begin(), valid_values_.end(),
invalid_values[ii]);
auto iter = base::ranges::find(valid_values_, invalid_values[ii]);
if (iter != valid_values_.end()) {
valid_values_.erase(iter);
DCHECK(!IsValid(invalid_values[ii]));
Expand All @@ -46,8 +47,7 @@ class ValueValidator {
}

bool IsValid(const T value) const {
return std::find(valid_values_.begin(), valid_values_.end(), value) !=
valid_values_.end();
return base::Contains(valid_values_, value);
}

const std::vector<T>& GetValues() const { return valid_values_; }
Expand Down
5 changes: 2 additions & 3 deletions gpu/command_buffer/service/webgpu_decoder_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
#include <dawn/platform/DawnPlatform.h>
#include <dawn/wire/WireServer.h>

#include <algorithm>
#include <memory>
#include <vector>

#include "base/bits.h"
#include "base/containers/contains.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
Expand Down Expand Up @@ -1081,8 +1081,7 @@ WebGPUDecoderImpl::WebGPUDecoderImpl(
// Only allow unsafe APIs if the disallow_unsafe_apis toggle is explicitly
// disabled.
allow_unsafe_apis_ =
std::find(force_disabled_toggles_.begin(), force_disabled_toggles_.end(),
"disallow_unsafe_apis") != force_disabled_toggles_.end();
base::Contains(force_disabled_toggles_, "disallow_unsafe_apis");

DawnProcTable wire_procs = dawn::native::GetProcs();
wire_procs.createInstance =
Expand Down
8 changes: 2 additions & 6 deletions gpu/config/gpu_feature_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

#include "gpu/config/gpu_feature_info.h"

#include <algorithm>

#include "base/containers/contains.h"
#include "gpu/config/gpu_blocklist.h"
#include "gpu/config/gpu_driver_bug_list.h"
#include "gpu/config/gpu_driver_bug_workaround_type.h"
Expand Down Expand Up @@ -42,10 +41,7 @@ void GpuFeatureInfo::ApplyToGLContext(gl::GLContext* gl_context) const {
}

bool GpuFeatureInfo::IsWorkaroundEnabled(int32_t workaround) const {
return std::find(this->enabled_gpu_driver_bug_workarounds.begin(),
this->enabled_gpu_driver_bug_workarounds.end(),
workaround) !=
this->enabled_gpu_driver_bug_workarounds.end();
return base::Contains(this->enabled_gpu_driver_bug_workarounds, workaround);
}

bool GpuFeatureInfo::IsInitialized() const {
Expand Down
12 changes: 3 additions & 9 deletions gpu/config/gpu_switching.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
#include <OpenGL/OpenGL.h>
#endif

#include <algorithm>
#include <vector>

#include "base/command_line.h"
#include "base/containers/contains.h"
#include "gpu/config/gpu_driver_bug_workaround_type.h"
#include "gpu/config/gpu_info.h"
#include "ui/gl/gl_context.h"
Expand All @@ -37,12 +37,6 @@ typedef void* PlatformPixelFormatObj;

PlatformPixelFormatObj g_discrete_pixel_format_obj = nullptr;

bool ContainsWorkaround(const std::vector<int32_t>& workarounds,
int32_t workaround) {
return (std::find(workarounds.begin(), workarounds.end(), workaround) !=
workarounds.end());
}

void ForceDiscreteGPU() {
if (g_discrete_pixel_format_obj)
return;
Expand Down Expand Up @@ -98,10 +92,10 @@ bool SwitchableGPUsSupported(const GPUInfo& gpu_info,
void InitializeSwitchableGPUs(
const std::vector<int32_t>& driver_bug_workarounds) {
gl::GLContext::SetSwitchableGPUsSupported();
if (ContainsWorkaround(driver_bug_workarounds, FORCE_HIGH_PERFORMANCE_GPU)) {
if (base::Contains(driver_bug_workarounds, FORCE_HIGH_PERFORMANCE_GPU)) {
gl::GLSurface::SetForcedGpuPreference(gl::GpuPreference::kHighPerformance);
ForceDiscreteGPU();
} else if (ContainsWorkaround(driver_bug_workarounds, FORCE_LOW_POWER_GPU)) {
} else if (base::Contains(driver_bug_workarounds, FORCE_LOW_POWER_GPU)) {
gl::GLSurface::SetForcedGpuPreference(gl::GpuPreference::kLowPower);
}
}
Expand Down
9 changes: 5 additions & 4 deletions gpu/gles2_conform_support/egl/display.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <memory>

#include "base/ranges/algorithm.h"
#include "build/build_config.h"
#include "gpu/gles2_conform_support/egl/config.h"
#include "gpu/gles2_conform_support/egl/context.h"
Expand Down Expand Up @@ -236,7 +237,7 @@ EGLBoolean Display::DestroySurface(ThreadState* ts, EGLSurface sfe) {
base::AutoLock auto_lock(lock_);
if (!is_initialized_)
return ts->ReturnError(EGL_NOT_INITIALIZED, EGL_FALSE);
auto it = std::find(surfaces_.begin(), surfaces_.end(), sfe);
auto it = base::ranges::find(surfaces_, sfe);
if (it == surfaces_.end())
return ts->ReturnError(EGL_BAD_SURFACE, EGL_FALSE);
surfaces_.erase(it);
Expand Down Expand Up @@ -347,7 +348,7 @@ EGLBoolean Display::DestroyContext(ThreadState* ts, EGLContext ctx) {
base::AutoLock auto_lock(lock_);
if (!is_initialized_)
return ts->ReturnError(EGL_NOT_INITIALIZED, EGL_FALSE);
auto it = std::find(contexts_.begin(), contexts_.end(), ctx);
auto it = base::ranges::find(contexts_, ctx);
if (it == contexts_.end())
return ts->ReturnError(EGL_BAD_CONTEXT, EGL_FALSE);
(*it)->MarkDestroyed();
Expand Down Expand Up @@ -383,15 +384,15 @@ const Config* Display::GetConfig(EGLConfig cfg) {

Surface* Display::GetSurface(EGLSurface surface) {
lock_.AssertAcquired();
auto it = std::find(surfaces_.begin(), surfaces_.end(), surface);
auto it = base::ranges::find(surfaces_, surface);
if (it == surfaces_.end())
return nullptr;
return it->get();
}

Context* Display::GetContext(EGLContext context) {
lock_.AssertAcquired();
auto it = std::find(contexts_.begin(), contexts_.end(), context);
auto it = base::ranges::find(contexts_, context);
if (it == contexts_.end())
return nullptr;
return it->get();
Expand Down

0 comments on commit fb15d03

Please sign in to comment.