ui/gl: Use BUILDFLAG for OS checking

Use BUILDFLAG(IS_XXX) instead of defined(OS_XXX).

Generated by `os_buildflag_migration.py` (https://crrev.com/c/3311983).

R=thakis@chromium.org

Bug: 1234043
Test: No functionality change
Change-Id: I56085b377c2d824afa52faa9ac6cd4cabb184297
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3403352
Reviewed-by: Nico Weber <thakis@chromium.org>
Commit-Queue: Xiaohan Wang <xhwang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#961344}
diff --git a/ui/gl/egl_api_unittest.cc b/ui/gl/egl_api_unittest.cc
index eba8a60..64b35c3d 100644
--- a/ui/gl/egl_api_unittest.cc
+++ b/ui/gl/egl_api_unittest.cc
@@ -27,7 +27,7 @@
     g_driver_egl.fn.eglGetErrorFn = &FakeGetError;
     g_driver_egl.fn.eglGetProcAddressFn = &FakeGetProcAddress;
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
     SetGLImplementation(kGLImplementationEGLANGLE);
 #else
     SetGLImplementation(kGLImplementationEGLGLES2);
diff --git a/ui/gl/egl_util.cc b/ui/gl/egl_util.cc
index 77044f4..6b9e301 100644
--- a/ui/gl/egl_util.cc
+++ b/ui/gl/egl_util.cc
@@ -6,7 +6,7 @@
 
 #include "build/build_config.h"
 
-#if defined(OS_ANDROID)
+#if BUILDFLAG(IS_ANDROID)
 #include <EGL/egl.h>
 #else
 #include "third_party/khronos/EGL/egl.h"
diff --git a/ui/gl/gl_bindings.h b/ui/gl/gl_bindings.h
index 492db1bf..2f52c66 100644
--- a/ui/gl/gl_bindings.h
+++ b/ui/gl/gl_bindings.h
@@ -13,7 +13,7 @@
 // __STDC_FORMAT_MACROS is defined in order for //base/format_macros.h to
 // function correctly. See comment and #error message in //base/format_macros.h
 // for details.
-#if defined(OS_POSIX) && !defined(__STDC_FORMAT_MACROS)
+#if BUILDFLAG(IS_POSIX) && !defined(__STDC_FORMAT_MACROS)
 #define __STDC_FORMAT_MACROS
 #endif
 
@@ -32,9 +32,9 @@
 #include "ui/gl/gl_export.h"
 
 // The standard OpenGL native extension headers are also included.
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 #include <GL/wglext.h>
-#elif defined(OS_APPLE)
+#elif BUILDFLAG(IS_APPLE)
 #include <OpenGL/OpenGL.h>
 #elif defined(USE_GLX)
 using Display = struct _XDisplay;
@@ -483,7 +483,7 @@
 
 #define GL_GLEXT_PROTOTYPES 1
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 #define GL_BINDING_CALL WINAPI
 #else
 #define GL_BINDING_CALL
diff --git a/ui/gl/gl_context.cc b/ui/gl/gl_context.cc
index 2a3eed9..58f70f3 100644
--- a/ui/gl/gl_context.cc
+++ b/ui/gl/gl_context.cc
@@ -25,7 +25,7 @@
 #include "ui/gl/gl_version_info.h"
 #include "ui/gl/gpu_timing.h"
 
-#if defined(OS_APPLE)
+#if BUILDFLAG(IS_APPLE)
 #include "base/mac/mac_util.h"
 #endif
 
@@ -74,7 +74,7 @@
 }
 
 GLContext::~GLContext() {
-#if defined(OS_APPLE)
+#if BUILDFLAG(IS_APPLE)
   DCHECK(!HasBackpressureFences());
 #endif
   share_group_->RemoveContext(this);
@@ -185,7 +185,7 @@
   current_virtual_context_ = nullptr;
 }
 
-#if defined(OS_APPLE)
+#if BUILDFLAG(IS_APPLE)
 constexpr uint64_t kInvalidFenceId = 0;
 
 uint64_t GLContext::BackpressureFenceCreate() {
diff --git a/ui/gl/gl_context.h b/ui/gl/gl_context.h
index 4c742bb..8466234 100644
--- a/ui/gl/gl_context.h
+++ b/ui/gl/gl_context.h
@@ -247,7 +247,7 @@
   // context is made current.
   void DirtyVirtualContextState();
 
-#if defined(OS_APPLE)
+#if BUILDFLAG(IS_APPLE)
   // Create a fence for all work submitted to this context so far, and return a
   // monotonically increasing handle to it. This returned handle never needs to
   // be freed. This method is used to create backpressure to throttle GL work
@@ -297,7 +297,7 @@
 
   GLApi* gl_api() { return gl_api_wrapper_->api(); }
 
-#if defined(OS_APPLE)
+#if BUILDFLAG(IS_APPLE)
   // Child classes are responsible for calling DestroyBackpressureFences during
   // their destruction while a context is current.
   bool HasBackpressureFences() const;
@@ -338,7 +338,7 @@
   // where this underlying context becomes lost.  https://crbug.com/1061442
   bool context_lost_ = false;
 
-#if defined(OS_APPLE)
+#if BUILDFLAG(IS_APPLE)
   std::map<uint64_t, std::unique_ptr<GLFence>> backpressure_fences_;
   uint64_t next_backpressure_fence_ = 0;
 #endif
diff --git a/ui/gl/gl_context_egl.cc b/ui/gl/gl_context_egl.cc
index f95ada82..cc6a58e 100644
--- a/ui/gl/gl_context_egl.cc
+++ b/ui/gl/gl_context_egl.cc
@@ -404,7 +404,7 @@
 }
 
 void GLContextEGL::ReleaseYUVToRGBConvertersAndBackpressureFences() {
-#if defined(OS_APPLE)
+#if BUILDFLAG(IS_APPLE)
   bool has_backpressure_fences = HasBackpressureFences();
 #else
   bool has_backpressure_fences = false;
@@ -434,7 +434,7 @@
     }
 
     yuv_to_rgb_converters_.clear();
-#if defined(OS_APPLE)
+#if BUILDFLAG(IS_APPLE)
     DestroyBackpressureFences();
 #endif
 
diff --git a/ui/gl/gl_context_stub.cc b/ui/gl/gl_context_stub.cc
index 56eca51..c5282539 100644
--- a/ui/gl/gl_context_stub.cc
+++ b/ui/gl/gl_context_stub.cc
@@ -4,6 +4,7 @@
 
 #include "ui/gl/gl_context_stub.h"
 
+#include "build/build_config.h"
 #include "ui/gl/gl_gl_api_implementation.h"
 #include "ui/gl/gl_stub_api.h"
 
@@ -75,7 +76,7 @@
          HasExtension("GL_KHR_robustness") || HasExtension("GL_EXT_robustness");
 }
 
-#if defined(OS_APPLE)
+#if BUILDFLAG(IS_APPLE)
 void GLContextStub::FlushForDriverCrashWorkaround() {}
 #endif
 
diff --git a/ui/gl/gl_context_stub.h b/ui/gl/gl_context_stub.h
index 1e1b8fa..a52e7fe 100644
--- a/ui/gl/gl_context_stub.h
+++ b/ui/gl/gl_context_stub.h
@@ -38,7 +38,7 @@
   void SetGLVersionString(const char* version_str);
   bool HasRobustness();
 
-#if defined(OS_APPLE)
+#if BUILDFLAG(IS_APPLE)
   void FlushForDriverCrashWorkaround() override;
 #endif
 
diff --git a/ui/gl/gl_features.cc b/ui/gl/gl_features.cc
index 55e2711..78b741f 100644
--- a/ui/gl/gl_features.cc
+++ b/ui/gl/gl_features.cc
@@ -10,7 +10,7 @@
 #include "build/chromeos_buildflags.h"
 #include "ui/gl/gl_switches.h"
 
-#if defined(OS_ANDROID)
+#if BUILDFLAG(IS_ANDROID)
 #include "base/android/build_info.h"
 #include "base/metrics/field_trial_params.h"
 #include "base/strings/pattern.h"
@@ -22,7 +22,7 @@
 
 const base::Feature kGpuVsync{"GpuVsync", base::FEATURE_ENABLED_BY_DEFAULT};
 
-#if defined(OS_ANDROID)
+#if BUILDFLAG(IS_ANDROID)
 const base::FeatureParam<std::string>
     kPassthroughCommandDecoderBlockListByBrand{
         &kDefaultPassthroughCommandDecoder, "BlockListByBrand", ""};
@@ -71,8 +71,8 @@
 // Launched on Windows, still experimental on other platforms.
 const base::Feature kDefaultPassthroughCommandDecoder {
   "DefaultPassthroughCommandDecoder",
-#if defined(OS_WIN) || defined(OS_FUCHSIA) ||                \
-    ((defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)) && \
+#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_FUCHSIA) ||              \
+    ((BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)) && \
      !defined(CHROMECAST_BUILD))
       base::FEATURE_ENABLED_BY_DEFAULT
 #else
@@ -90,7 +90,7 @@
   if (!base::FeatureList::IsEnabled(kDefaultPassthroughCommandDecoder))
     return false;
 
-#if defined(OS_ANDROID)
+#if BUILDFLAG(IS_ANDROID)
   // Check block list against build info.
   const auto* build_info = base::android::BuildInfo::GetInstance();
   if (IsDeviceBlocked(build_info->brand(),
@@ -116,7 +116,7 @@
           build_info->android_build_fp(),
           kPassthroughCommandDecoderBlockListByAndroidBuildFP.Get()))
     return false;
-#endif  // defined(OS_ANDROID)
+#endif  // BUILDFLAG(IS_ANDROID)
 
   return true;
 }
diff --git a/ui/gl/gl_fence.cc b/ui/gl/gl_fence.cc
index 12f725e..28cbcb1 100644
--- a/ui/gl/gl_fence.cc
+++ b/ui/gl/gl_fence.cc
@@ -14,17 +14,17 @@
 #include "ui/gl/gl_implementation.h"
 #include "ui/gl/gl_version_info.h"
 
-#if defined(OS_APPLE)
+#if BUILDFLAG(IS_APPLE)
 #include "ui/gl/gl_fence_apple.h"
 #endif
 
-#if defined(USE_EGL) && defined(OS_POSIX) && !defined(OS_APPLE)
+#if defined(USE_EGL) && BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_APPLE)
 #define USE_GL_FENCE_ANDROID_NATIVE_FENCE_SYNC
 #include "ui/gl/gl_fence_android_native_fence_sync.h"
 #include "ui/gl/gl_surface_egl.h"
 #endif
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 #include "ui/gl/gl_fence_win.h"
 #endif
 
@@ -41,7 +41,7 @@
   return g_current_gl_driver->ext.b_GL_ARB_sync ||
          g_current_gl_version->is_es3 ||
          g_current_gl_version->is_desktop_core_profile ||
-#if defined(OS_APPLE)
+#if BUILDFLAG(IS_APPLE)
          g_current_gl_driver->ext.b_GL_APPLE_fence ||
 #else
          g_driver_egl.ext.b_EGL_KHR_fence_sync ||
@@ -54,7 +54,7 @@
       << "Trying to create fence with no context";
 
   std::unique_ptr<GLFence> fence;
-#if !defined(OS_APPLE)
+#if !BUILDFLAG(IS_APPLE)
   if (g_driver_egl.ext.b_EGL_KHR_fence_sync &&
       g_driver_egl.ext.b_EGL_KHR_wait_sync) {
     // Prefer GLFenceEGL which doesn't require GL context switching.
@@ -67,7 +67,7 @@
           g_current_gl_version->is_desktop_core_profile) {
     // Prefer ARB_sync which supports server-side wait.
     fence = std::make_unique<GLFenceARB>();
-#if defined(OS_APPLE)
+#if BUILDFLAG(IS_APPLE)
   } else if (g_current_gl_driver->ext.b_GL_APPLE_fence) {
     fence = std::make_unique<GLFenceAPPLE>();
 #else
@@ -99,7 +99,7 @@
 bool GLFence::IsGpuFenceSupported() {
 #if defined(USE_GL_FENCE_ANDROID_NATIVE_FENCE_SYNC)
   return gl::GLSurfaceEGL::IsAndroidNativeFenceSyncSupported();
-#elif defined(OS_WIN)
+#elif BUILDFLAG(IS_WIN)
   return gl::GLFenceWin::IsSupported();
 #else
   return false;
@@ -112,7 +112,7 @@
   DCHECK(IsGpuFenceSupported());
 #if defined(USE_GL_FENCE_ANDROID_NATIVE_FENCE_SYNC)
   return GLFenceAndroidNativeFenceSync::CreateFromGpuFence(gpu_fence);
-#elif defined(OS_WIN)
+#elif BUILDFLAG(IS_WIN)
   return GLFenceWin::CreateFromGpuFence(gpu_fence);
 #else
   NOTREACHED();
@@ -125,7 +125,7 @@
   DCHECK(IsGpuFenceSupported());
 #if defined(USE_GL_FENCE_ANDROID_NATIVE_FENCE_SYNC)
   return GLFenceAndroidNativeFenceSync::CreateForGpuFence();
-#elif defined(OS_WIN)
+#elif BUILDFLAG(IS_WIN)
   return GLFenceWin::CreateForGpuFence();
 #else
   NOTREACHED();
diff --git a/ui/gl/gl_fence_android_native_fence_sync.cc b/ui/gl/gl_fence_android_native_fence_sync.cc
index 6332dc1..5f09e6b 100644
--- a/ui/gl/gl_fence_android_native_fence_sync.cc
+++ b/ui/gl/gl_fence_android_native_fence_sync.cc
@@ -10,11 +10,12 @@
 #include "base/logging.h"
 #include "base/memory/ptr_util.h"
 #include "base/time/time.h"
+#include "build/build_config.h"
 #include "ui/gfx/gpu_fence.h"
 #include "ui/gfx/gpu_fence_handle.h"
 #include "ui/gl/gl_surface_egl.h"
 
-#if defined(OS_POSIX) || defined(OS_FUCHSIA)
+#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
 #include <unistd.h>
 
 #include "base/posix/eintr_wrapper.h"
diff --git a/ui/gl/gl_image.cc b/ui/gl/gl_image.cc
index 4dca245..e190dadcb 100644
--- a/ui/gl/gl_image.cc
+++ b/ui/gl/gl_image.cc
@@ -5,9 +5,10 @@
 #include "ui/gl/gl_image.h"
 
 #include "base/notreached.h"
+#include "build/build_config.h"
 #include "ui/gl/gl_bindings.h"
 
-#if defined(OS_ANDROID)
+#if BUILDFLAG(IS_ANDROID)
 #include "base/android/scoped_hardware_buffer_fence_sync.h"
 #endif
 
@@ -118,7 +119,7 @@
   return Type::NONE;
 }
 
-#if defined(OS_ANDROID)
+#if BUILDFLAG(IS_ANDROID)
 std::unique_ptr<base::android::ScopedHardwareBufferFenceSync>
 GLImage::GetAHardwareBuffer() {
   return nullptr;
diff --git a/ui/gl/gl_image.h b/ui/gl/gl_image.h
index 91d26506..b19a927 100644
--- a/ui/gl/gl_image.h
+++ b/ui/gl/gl_image.h
@@ -23,7 +23,7 @@
 #include "ui/gfx/overlay_transform.h"
 #include "ui/gl/gl_export.h"
 
-#if defined(OS_ANDROID)
+#if BUILDFLAG(IS_ANDROID)
 #include <android/hardware_buffer.h>
 #include <memory>
 #include "base/android/scoped_hardware_buffer_handle.h"
@@ -126,7 +126,7 @@
   // If called, then IsInUseByWindowServer will always return false.
   virtual void DisableInUseByWindowServer();
 
-#if defined(OS_ANDROID)
+#if BUILDFLAG(IS_ANDROID)
   // Provides the buffer backing this image, if it is backed by an
   // AHardwareBuffer. The ScopedHardwareBuffer returned may include a fence
   // which will be signaled when all pending work for the buffer has been
diff --git a/ui/gl/gl_image_memory.cc b/ui/gl/gl_image_memory.cc
index 2fbd058..963860f 100644
--- a/ui/gl/gl_image_memory.cc
+++ b/ui/gl/gl_image_memory.cc
@@ -266,9 +266,9 @@
   stride_ = stride;
 
   bool tex_image_from_pbo_is_slow = false;
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
   tex_image_from_pbo_is_slow = true;
-#endif  // OS_WIN
+#endif  // BUILDFLAG(IS_WIN)
   GLContext* context = GLContext::GetCurrent();
   DCHECK(context);
   if (!tex_image_from_pbo_is_slow && SupportsPBO(context) &&
diff --git a/ui/gl/gl_image_native_pixmap.cc b/ui/gl/gl_image_native_pixmap.cc
index 9f9e0ab..503e185 100644
--- a/ui/gl/gl_image_native_pixmap.cc
+++ b/ui/gl/gl_image_native_pixmap.cc
@@ -275,11 +275,11 @@
     }
   }
 
-#if defined(OS_FUCHSIA)
+#if BUILDFLAG(IS_FUCHSIA)
   // TODO(crbug.com/852011): Implement image handle export on Fuchsia.
   NOTIMPLEMENTED();
   return gfx::NativePixmapHandle();
-#else   // defined(OS_FUCHSIA)
+#else   // BUILDFLAG(IS_FUCHSIA)
   std::vector<int> fds(num_planes);
   std::vector<EGLint> strides(num_planes);
   std::vector<EGLint> offsets(num_planes);
@@ -308,7 +308,7 @@
   }
 
   return handle;
-#endif  // !defined(OS_FUCHSIA)
+#endif  // BUILDFLAG(IS_FUCHSIA)
 }
 
 unsigned GLImageNativePixmap::GetInternalFormat() {
diff --git a/ui/gl/gl_image_native_pixmap_unittest.cc b/ui/gl/gl_image_native_pixmap_unittest.cc
index 4818747..2941b08 100644
--- a/ui/gl/gl_image_native_pixmap_unittest.cc
+++ b/ui/gl/gl_image_native_pixmap_unittest.cc
@@ -34,7 +34,7 @@
  public:
   absl::optional<GLImplementationParts> GetPreferedGLImplementation()
       const override {
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
     return absl::optional<GLImplementationParts>(GLImplementationParts(
         kGLImplementationEGLANGLE, ANGLEImplementation::kNone));
 #else
diff --git a/ui/gl/gl_image_shared_memory_unittest.cc b/ui/gl/gl_image_shared_memory_unittest.cc
index 7df0ea3..ad11fe4 100644
--- a/ui/gl/gl_image_shared_memory_unittest.cc
+++ b/ui/gl/gl_image_shared_memory_unittest.cc
@@ -51,7 +51,7 @@
     GLImageSharedMemoryTestDelegate<gfx::BufferFormat::RGBX_8888>,
     GLImageSharedMemoryTestDelegate<gfx::BufferFormat::RGBA_8888>,
     GLImageSharedMemoryTestDelegate<gfx::BufferFormat::BGRX_8888>,
-#if defined(OS_LINUX) || defined(OS_CHROMEOS)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
     // Fails on Win nVidia and linux android: the test writes nothing (we read
     // back the color used to clear the buffer).
     // TODO(mcasas): enable those paltforms https://crbug.com/803451.
@@ -115,7 +115,7 @@
 };
 
 // Disabled on Windows, see crbug.com/1036138
-#if !defined(OS_WIN)
+#if !BUILDFLAG(IS_WIN)
 INSTANTIATE_TYPED_TEST_SUITE_P(GLImageSharedMemoryPool,
                                GLImageCopyTest,
                                GLImageSharedMemoryPoolTestDelegate);
diff --git a/ui/gl/gl_implementation.cc b/ui/gl/gl_implementation.cc
index 8a2d99f..41d909f 100644
--- a/ui/gl/gl_implementation.cc
+++ b/ui/gl/gl_implementation.cc
@@ -160,7 +160,7 @@
      GLImplementationParts(kGLImplementationDesktopGL)},
     {kGLImplementationSwiftShaderName, kANGLEImplementationNoneName,
      GLImplementationParts(kGLImplementationSwiftShaderGL)},
-#if defined(OS_APPLE)
+#if BUILDFLAG(IS_APPLE)
     {kGLImplementationAppleName, kANGLEImplementationNoneName,
      GLImplementationParts(kGLImplementationAppleGL)},
 #endif
diff --git a/ui/gl/gl_implementation.h b/ui/gl/gl_implementation.h
index 81e0f2d..d6558a7e 100644
--- a/ui/gl/gl_implementation.h
+++ b/ui/gl/gl_implementation.h
@@ -83,7 +83,7 @@
 };
 
 using GLFunctionPointerType = void (*)();
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 typedef GLFunctionPointerType(WINAPI* GLGetProcAddressProc)(const char* name);
 #else
 typedef GLFunctionPointerType (*GLGetProcAddressProc)(const char* name);
diff --git a/ui/gl/gl_share_group.cc b/ui/gl/gl_share_group.cc
index 03e2c57..eb72412 100644
--- a/ui/gl/gl_share_group.cc
+++ b/ui/gl/gl_share_group.cc
@@ -12,7 +12,7 @@
 namespace gl {
 
 GLShareGroup::GLShareGroup()
-#if defined(OS_APPLE)
+#if BUILDFLAG(IS_APPLE)
     : renderer_id_(-1)
 #endif
 {
@@ -50,7 +50,7 @@
   shared_context_ = context;
 }
 
-#if defined(OS_APPLE)
+#if BUILDFLAG(IS_APPLE)
 void GLShareGroup::SetRendererID(int renderer_id) {
   renderer_id_ = renderer_id;
 }
diff --git a/ui/gl/gl_share_group.h b/ui/gl/gl_share_group.h
index b19a7ec7..1091ba7 100644
--- a/ui/gl/gl_share_group.h
+++ b/ui/gl/gl_share_group.h
@@ -41,7 +41,7 @@
   void SetSharedContext(GLContext* context);
   GLContext* shared_context() { return shared_context_; }
 
-#if defined(OS_APPLE)
+#if BUILDFLAG(IS_APPLE)
   // Sets and returns the ID of the renderer that all contexts in this share
   // group should be on.
   void SetRendererID(int renderer_id);
@@ -60,7 +60,7 @@
 
   raw_ptr<GLContext> shared_context_ = nullptr;
 
-#if defined(OS_APPLE)
+#if BUILDFLAG(IS_APPLE)
   int renderer_id_;
 #endif
 };
diff --git a/ui/gl/gl_surface_egl.cc b/ui/gl/gl_surface_egl.cc
index 1b994db..acfd4af 100644
--- a/ui/gl/gl_surface_egl.cc
+++ b/ui/gl/gl_surface_egl.cc
@@ -42,7 +42,7 @@
 #include "ui/gl/scoped_make_current.h"
 #include "ui/gl/sync_control_vsync_provider.h"
 
-#if defined(OS_ANDROID)
+#if BUILDFLAG(IS_ANDROID)
 #include <android/native_window_jni.h>
 #include "base/android/build_info.h"
 #endif
@@ -896,7 +896,7 @@
 
   if (supports_angle_opengl) {
     if (use_angle_default && !supports_angle_d3d) {
-#if defined(OS_ANDROID)
+#if BUILDFLAG(IS_ANDROID)
       // Don't request desktopGL on android
       AddInitDisplay(init_displays, ANGLE_OPENGLES);
 #else
@@ -1065,7 +1065,7 @@
   // because it is emulated with pbuffers if native support is not present. See
   // https://crbug.com/382349.
 
-#if defined(OS_ANDROID)
+#if BUILDFLAG(IS_ANDROID)
   // Use the WebGL compatibility extension for detecting ANGLE. ANGLE always
   // exposes it.
   bool is_angle = g_egl_create_context_webgl_compatability_supported;
@@ -1103,7 +1103,7 @@
   // that version onward.
   g_egl_android_native_fence_sync_supported =
       HasEGLExtension("EGL_ANDROID_native_fence_sync");
-#if defined(OS_ANDROID)
+#if BUILDFLAG(IS_ANDROID)
   if (!g_egl_android_native_fence_sync_supported &&
       base::android::BuildInfo::GetInstance()->sdk_int() >=
           base::android::SDK_VERSION_NOUGAT &&
@@ -1459,12 +1459,12 @@
     EGLNativeWindowType window,
     std::unique_ptr<gfx::VSyncProvider> vsync_provider)
     : window_(window), vsync_provider_external_(std::move(vsync_provider)) {
-#if defined(OS_ANDROID)
+#if BUILDFLAG(IS_ANDROID)
   if (window)
     ANativeWindow_acquire(window);
 #endif
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
   RECT windowRect;
   if (GetClientRect(window_, &windowRect))
     size_ = gfx::Rect(windowRect).size();
@@ -2126,7 +2126,7 @@
 
 NativeViewGLSurfaceEGL::~NativeViewGLSurfaceEGL() {
   Destroy();
-#if defined(OS_ANDROID)
+#if BUILDFLAG(IS_ANDROID)
   if (window_)
     ANativeWindow_release(window_);
 #endif
@@ -2144,7 +2144,7 @@
 bool PbufferGLSurfaceEGL::Initialize(GLSurfaceFormat format) {
   EGLSurface old_surface = surface_;
 
-#if defined(OS_ANDROID)
+#if BUILDFLAG(IS_ANDROID)
   // This is to allow context virtualization which requires on- and offscreen
   // to use a compatible config. We expect the client to request RGB565
   // onscreen surface also for this to work (with the exception of
@@ -2244,7 +2244,7 @@
 }
 
 void* PbufferGLSurfaceEGL::GetShareHandle() {
-#if defined(OS_ANDROID)
+#if BUILDFLAG(IS_ANDROID)
   NOTREACHED();
   return NULL;
 #else
diff --git a/ui/gl/gl_surface_egl.h b/ui/gl/gl_surface_egl.h
index e95d3b6b..61faca3 100644
--- a/ui/gl/gl_surface_egl.h
+++ b/ui/gl/gl_surface_egl.h
@@ -7,7 +7,7 @@
 
 #include "build/build_config.h"
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 #include <windows.h>
 #endif
 
diff --git a/ui/gl/gl_surface_egl_unittest.cc b/ui/gl/gl_surface_egl_unittest.cc
index 07e50a1..30e9fdc 100644
--- a/ui/gl/gl_surface_egl_unittest.cc
+++ b/ui/gl/gl_surface_egl_unittest.cc
@@ -13,7 +13,7 @@
 #include "ui/gl/init/gl_factory.h"
 #include "ui/gl/test/gl_surface_test_support.h"
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 #include "ui/platform_window/platform_window_delegate.h"
 #include "ui/platform_window/win/win_window.h"
 #endif
@@ -31,7 +31,7 @@
 class GLSurfaceEGLTest : public testing::Test {
  protected:
   void SetUp() override {
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
     GLSurfaceTestSupport::InitializeOneOffImplementation(
         GLImplementationParts(kGLImplementationEGLANGLE), true);
 #else
@@ -67,7 +67,7 @@
 }
 #endif
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 
 class TestPlatformDelegate : public ui::PlatformWindowDelegate {
  public:
diff --git a/ui/gl/gl_surface_presentation_helper.cc b/ui/gl/gl_surface_presentation_helper.cc
index dc19d0c..1f62bff6 100644
--- a/ui/gl/gl_surface_presentation_helper.cc
+++ b/ui/gl/gl_surface_presentation_helper.cc
@@ -215,7 +215,7 @@
 
 // https://crbug.com/854298 : disable GLFence on Android as they seem to cause
 // issues on some devices.
-#if !defined(OS_ANDROID)
+#if !BUILDFLAG(IS_ANDROID)
   gl_fence_supported_ = GLFence::IsSupported();
 #endif
 }
diff --git a/ui/gl/gl_switches.cc b/ui/gl/gl_switches.cc
index 7d694056..609e022b 100644
--- a/ui/gl/gl_switches.cc
+++ b/ui/gl/gl_switches.cc
@@ -7,7 +7,7 @@
 #include "base/cxx17_backports.h"
 #include "build/build_config.h"
 
-#if defined(OS_ANDROID)
+#if BUILDFLAG(IS_ANDROID)
 #include "base/android/build_info.h"
 #endif
 
@@ -246,13 +246,13 @@
                                      base::FEATURE_DISABLED_BY_DEFAULT};
 
 bool IsDefaultANGLEVulkan() {
-#if defined(OS_ANDROID)
+#if BUILDFLAG(IS_ANDROID)
   // No support for devices before Q -- exit before checking feature flags
   // so that devices are not counted in finch trials.
   if (base::android::BuildInfo::GetInstance()->sdk_int() <
       base::android::SDK_VERSION_Q)
     return false;
-#endif  // defined(OS_ANDROID)
+#endif  // BUILDFLAG(IS_ANDROID)
   return base::FeatureList::IsEnabled(kDefaultANGLEVulkan);
 }
 
diff --git a/ui/gl/gl_utils.cc b/ui/gl/gl_utils.cc
index 8043d88..ba56ce4 100644
--- a/ui/gl/gl_utils.cc
+++ b/ui/gl/gl_utils.cc
@@ -9,6 +9,7 @@
 #include "base/command_line.h"
 #include "base/debug/alias.h"
 #include "base/logging.h"
+#include "build/build_config.h"
 #include "ui/gl/gl_bindings.h"
 #include "ui/gl/gl_features.h"
 #include "ui/gl/gl_switches.h"
@@ -17,12 +18,12 @@
 #include "ui/gl/gl_surface_egl.h"
 #endif  // defined(USE_EGL)
 
-#if defined(OS_ANDROID)
+#if BUILDFLAG(IS_ANDROID)
 #include "base/posix/eintr_wrapper.h"
 #include "third_party/libsync/src/include/sync/sync.h"
 #endif
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 #include <d3d11_1.h>
 #include "base/strings/stringprintf.h"
 #include "media/base/win/mf_helpers.h"
@@ -67,7 +68,7 @@
   }
 }
 
-#if defined(OS_ANDROID)
+#if BUILDFLAG(IS_ANDROID)
 base::ScopedFD MergeFDs(base::ScopedFD a, base::ScopedFD b) {
   if (!a.is_valid())
     return b;
@@ -112,7 +113,7 @@
 #endif  // defined(USE_EGL)
 }
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 // This function is thread safe.
 bool AreOverlaysSupportedWin() {
   return gl::DirectCompositionSurfaceWin::AreOverlaysSupported();
@@ -193,9 +194,9 @@
   media::SetDebugName(swap_chain, name_prefix);
   LabelSwapChainBuffers(swap_chain, name_prefix);
 }
-#endif  // OS_WIN
+#endif  // BUILDFLAG(IS_WIN)
 
-#if defined(OS_MAC)
+#if BUILDFLAG(IS_MAC)
 
 ScopedEnableTextureRectangleInShaderCompiler::
     ScopedEnableTextureRectangleInShaderCompiler(gl::GLApi* gl_api) {
@@ -214,7 +215,7 @@
     gl_api_->glDisableFn(GL_TEXTURE_RECTANGLE_ANGLE);
 }
 
-#endif  // defined(OS_MAC)
+#endif  // BUILDFLAG(IS_MAC)
 
 ScopedPixelStore::ScopedPixelStore(unsigned int name, int value)
     : name_(name), old_value_(GetIntegerv(name)), value_(value) {
diff --git a/ui/gl/gl_utils.h b/ui/gl/gl_utils.h
index 058cb868..9fedd3c 100644
--- a/ui/gl/gl_utils.h
+++ b/ui/gl/gl_utils.h
@@ -11,11 +11,11 @@
 #include "build/build_config.h"
 #include "ui/gl/gl_export.h"
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 #include <dxgi1_6.h>
 #endif
 
-#if defined(OS_ANDROID)
+#if BUILDFLAG(IS_ANDROID)
 #include "base/files/scoped_file.h"
 #endif
 
@@ -25,7 +25,7 @@
 GL_EXPORT void Crash();
 GL_EXPORT void Hang();
 
-#if defined(OS_ANDROID)
+#if BUILDFLAG(IS_ANDROID)
 GL_EXPORT base::ScopedFD MergeFDs(base::ScopedFD a, base::ScopedFD b);
 #endif
 
@@ -34,7 +34,7 @@
 
 GL_EXPORT bool PassthroughCommandDecoderSupported();
 
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
 GL_EXPORT bool AreOverlaysSupportedWin();
 
 // Calculates present during in 100 ns from number of frames per second.
@@ -72,7 +72,7 @@
       const ScopedEnableTextureRectangleInShaderCompiler&) = delete;
 
   // This class is a no-op except on macOS.
-#if !defined(OS_MAC)
+#if !BUILDFLAG(IS_MAC)
   explicit ScopedEnableTextureRectangleInShaderCompiler(gl::GLApi* gl_api) {}
 
 #else
diff --git a/ui/gl/init/create_gr_gl_interface.cc b/ui/gl/init/create_gr_gl_interface.cc
index dbf0e22..b35f4b0 100644
--- a/ui/gl/init/create_gr_gl_interface.cc
+++ b/ui/gl/init/create_gr_gl_interface.cc
@@ -13,7 +13,7 @@
 #include "ui/gl/gl_version_info.h"
 #include "ui/gl/progress_reporter.h"
 
-#if defined(OS_APPLE)
+#if BUILDFLAG(IS_APPLE)
 #include "base/mac/mac_util.h"
 #endif
 
@@ -93,7 +93,7 @@
   return true;
 }
 
-#if defined(OS_APPLE)
+#if BUILDFLAG(IS_APPLE)
 std::map<GLuint, base::TimeTicks>& GetProgramCreateTimesMap() {
   static base::NoDestructor<std::map<GLuint, base::TimeTicks>> instance;
   return *instance.get();
@@ -140,7 +140,7 @@
 GrGLFunction<R GR_GL_FUNCTION_TYPE(Args...)> bind_slow_on_mac(
     R(GL_BINDING_CALL* func)(Args...),
     gl::ProgressReporter* progress_reporter) {
-#if defined(OS_APPLE)
+#if BUILDFLAG(IS_APPLE)
   if (!progress_reporter) {
     return maybe_drop_call<droppable_call>(func);
   }
@@ -159,7 +159,7 @@
 GrGLFunction<R GR_GL_FUNCTION_TYPE(Args...)> bind_with_flush_on_mac(
     R(GL_BINDING_CALL* func)(Args...),
     bool is_angle) {
-#if defined(OS_APPLE)
+#if BUILDFLAG(IS_APPLE)
   // If running on Apple silicon or ANGLE, regardless of the architecture,
   // disable this workaround.  See https://crbug.com/1131312.
   const bool needs_flush =
@@ -325,7 +325,7 @@
       bind_slow(gl->glCompressedTexSubImage2DFn, progress_reporter);
   functions->fCopyTexSubImage2D =
       bind_slow(gl->glCopyTexSubImage2DFn, progress_reporter);
-#if defined(OS_APPLE)
+#if BUILDFLAG(IS_APPLE)
   functions->fCreateProgram = [func = gl->glCreateProgramFn]() {
     auto& program_create_times = GetProgramCreateTimesMap();
     GLuint program = func();
@@ -339,7 +339,7 @@
   functions->fCullFace = gl->glCullFaceFn;
   functions->fDeleteBuffers =
       bind_slow(gl->glDeleteBuffersARBFn, progress_reporter);
-#if defined(OS_APPLE)
+#if BUILDFLAG(IS_APPLE)
   functions->fDeleteProgram = [func = gl->glDeleteProgramFn](GLuint program) {
     auto& program_create_times = GetProgramCreateTimesMap();
     program_create_times.erase(program);
@@ -409,7 +409,7 @@
   functions->fGetQueryiv = gl->glGetQueryivFn;
   functions->fGetProgramBinary = gl->glGetProgramBinaryFn;
   functions->fGetProgramInfoLog = gl->glGetProgramInfoLogFn;
-#if defined(OS_APPLE)
+#if BUILDFLAG(IS_APPLE)
   functions->fGetProgramiv = [func = gl->glGetProgramivFn](
                                  GLuint program, GLenum pname, GLint* params) {
     func(program, pname, params);
diff --git a/ui/gl/init/gl_factory.cc b/ui/gl/init/gl_factory.cc
index 078e01e..c037bb4 100644
--- a/ui/gl/init/gl_factory.cc
+++ b/ui/gl/init/gl_factory.cc
@@ -171,7 +171,7 @@
 }  // namespace
 
 GLImplementationParts GetSoftwareGLImplementationForPlatform() {
-#if defined(OS_WIN) || defined(OS_LINUX)
+#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX)
   return GetSoftwareGLImplementation();
 #else
   return GetLegacySoftwareGLImplementation();
diff --git a/ui/gl/shader_tracking.cc b/ui/gl/shader_tracking.cc
index a185ebe..32ec5b4 100644
--- a/ui/gl/shader_tracking.cc
+++ b/ui/gl/shader_tracking.cc
@@ -6,13 +6,14 @@
 
 #include "base/check.h"
 #include "base/no_destructor.h"
+#include "build/build_config.h"
 #include "ui/gl/gl_switches.h"
 
 namespace gl {
 
 // static
 ShaderTracking* ShaderTracking::GetInstance() {
-#if defined(OS_WIN)
+#if BUILDFLAG(IS_WIN)
   // Shaders can only be reliably retrieved with ANGLE backend. Therefore,
   // limit to Windows platform only.
   static bool enabled =
@@ -21,7 +22,7 @@
     static base::NoDestructor<ShaderTracking> instance;
     return instance.get();
   }
-#endif  // OS_WIN
+#endif  // BUILDFLAG(IS_WIN)
   return nullptr;
 }
 
diff --git a/ui/gl/sync_control_vsync_provider.cc b/ui/gl/sync_control_vsync_provider.cc
index d035fca..a61f011d 100644
--- a/ui/gl/sync_control_vsync_provider.cc
+++ b/ui/gl/sync_control_vsync_provider.cc
@@ -11,7 +11,7 @@
 #include "base/trace_event/trace_event.h"
 #include "build/build_config.h"
 
-#if defined(OS_LINUX) || defined(OS_CHROMEOS)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
 // These constants define a reasonable range for a calculated refresh interval.
 // Calculating refreshes out of this range will be considered a fatal error.
 const int64_t kMinVsyncIntervalUs = base::Time::kMicrosecondsPerSecond / 400;
@@ -26,7 +26,7 @@
 namespace gl {
 
 SyncControlVSyncProvider::SyncControlVSyncProvider() : gfx::VSyncProvider() {
-#if defined(OS_LINUX) || defined(OS_CHROMEOS)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
   // On platforms where we can't get an accurate reading on the refresh
   // rate we fall back to the assumption that we're displaying 60 frames
   // per second.
@@ -48,7 +48,7 @@
     base::TimeTicks* timebase_out,
     base::TimeDelta* interval_out) {
   TRACE_EVENT0("gpu", "SyncControlVSyncProvider::GetVSyncParameters");
-#if defined(OS_LINUX) || defined(OS_CHROMEOS)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
   // The actual clock used for the system time returned by glXGetSyncValuesOML
   // is unspecified. In practice, the clock used is likely to be either
   // CLOCK_REALTIME or CLOCK_MONOTONIC, so we compare the returned time to the
@@ -155,11 +155,11 @@
   return true;
 #else
   return false;
-#endif  // defined(OS_LINUX) || defined(OS_CHROMEOS)
+#endif  // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
 }
 
 bool SyncControlVSyncProvider::SupportGetVSyncParametersIfAvailable() const {
-#if defined(OS_LINUX) || defined(OS_CHROMEOS)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
   return true;
 #else
   return false;
diff --git a/ui/gl/sync_control_vsync_provider.h b/ui/gl/sync_control_vsync_provider.h
index 17675773..57604c90 100644
--- a/ui/gl/sync_control_vsync_provider.h
+++ b/ui/gl/sync_control_vsync_provider.h
@@ -30,11 +30,11 @@
   bool SupportGetVSyncParametersIfAvailable() const override;
 
   static constexpr bool IsSupported() {
-#if defined(OS_LINUX) || defined(OS_CHROMEOS)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
     return true;
 #else
     return false;
-#endif  // defined(OS_LINUX) || defined(OS_CHROMEOS)
+#endif  // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
   }
 
  protected:
@@ -45,7 +45,7 @@
   virtual bool GetMscRate(int32_t* numerator, int32_t* denominator) = 0;
 
  private:
-#if defined(OS_LINUX) || defined(OS_CHROMEOS)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
   base::TimeTicks last_timebase_;
   uint64_t last_media_stream_counter_ = 0;
   base::TimeDelta last_good_interval_;
@@ -56,7 +56,7 @@
   // from configuration change (monitor reconfiguration, moving windows
   // between monitors, suspend and resume, etc.).
   base::queue<base::TimeDelta> last_computed_intervals_;
-#endif  // defined(OS_LINUX) || defined(OS_CHROMEOS)
+#endif  // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
 };
 
 }  // namespace gl
diff --git a/ui/gl/test/gl_image_test_template.h b/ui/gl/test/gl_image_test_template.h
index 6ca32e4..8012637 100644
--- a/ui/gl/test/gl_image_test_template.h
+++ b/ui/gl/test/gl_image_test_template.h
@@ -28,7 +28,7 @@
 #include "ui/gl/test/gl_image_test_support.h"
 #include "ui/gl/test/gl_test_helper.h"
 
-#if defined(OS_APPLE)
+#if BUILDFLAG(IS_APPLE)
 #include "base/mac/mac_util.h"
 #endif
 
diff --git a/ui/gl/test/gl_surface_test_support.cc b/ui/gl/test/gl_surface_test_support.cc
index 119e758..1512a66 100644
--- a/ui/gl/test/gl_surface_test_support.cc
+++ b/ui/gl/test/gl_surface_test_support.cc
@@ -14,7 +14,7 @@
 #include "ui/gl/gl_switches.h"
 #include "ui/gl/init/gl_factory.h"
 
-#if defined(OS_LINUX) || defined(OS_CHROMEOS)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
 #include "ui/platform_window/common/platform_window_defaults.h"  // nogncheck
 #endif
 
@@ -34,7 +34,7 @@
   ui::OzonePlatform::InitializeForGPU(params);
 #endif
 
-#if defined(OS_LINUX) || defined(OS_CHROMEOS)
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
   ui::test::EnableTestConfigForPlatformWindows();
 #endif
 
@@ -47,7 +47,7 @@
     use_software_gl = false;
   }
 
-#if defined(OS_ANDROID)
+#if BUILDFLAG(IS_ANDROID)
   // On Android we always use hardware GL.
   use_software_gl = false;
 #endif
diff --git a/ui/gl/test/run_all_unittests.cc b/ui/gl/test/run_all_unittests.cc
index 14fd4e4..80ed29c 100644
--- a/ui/gl/test/run_all_unittests.cc
+++ b/ui/gl/test/run_all_unittests.cc
@@ -10,7 +10,7 @@
 #include "base/test/test_suite.h"
 #include "build/build_config.h"
 
-#if defined(OS_MAC)
+#if BUILDFLAG(IS_MAC)
 #include "base/test/mock_chrome_application_mac.h"
 #endif
 
@@ -34,7 +34,7 @@
   void Initialize() override {
     base::TestSuite::Initialize();
 
-#if defined(OS_MAC)
+#if BUILDFLAG(IS_MAC)
     // This registers a custom NSApplication. It must be done before
     // TaskEnvironment registers a regular NSApplication.
     mock_cr_app::RegisterMockCrApp();