ericrk | 41a1579e | 2017-02-10 20:56:28 | [diff] [blame] | 1 | // Copyright (c) 2017 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "gpu/config/gpu_feature_info.h" |
| 6 | |
Zhenyao Mo | 08c9149 | 2017-08-24 22:57:57 | [diff] [blame] | 7 | #include <algorithm> |
| 8 | |
| 9 | #include "gpu/config/gpu_driver_bug_workaround_type.h" |
| 10 | #include "ui/gl/gl_context.h" |
| 11 | |
ericrk | 41a1579e | 2017-02-10 20:56:28 | [diff] [blame] | 12 | namespace gpu { |
| 13 | |
| 14 | GpuFeatureInfo::GpuFeatureInfo() { |
| 15 | for (auto& status : status_values) |
| 16 | status = kGpuFeatureStatusUndefined; |
| 17 | } |
| 18 | |
Zhenyao Mo | d4dba105 | 2017-07-27 23:02:39 | [diff] [blame] | 19 | GpuFeatureInfo::GpuFeatureInfo(const GpuFeatureInfo&) = default; |
| 20 | |
| 21 | GpuFeatureInfo::GpuFeatureInfo(GpuFeatureInfo&&) = default; |
| 22 | |
Chris Watkins | 8103077 | 2017-12-07 01:20:56 | [diff] [blame] | 23 | GpuFeatureInfo::~GpuFeatureInfo() = default; |
Zhenyao Mo | d4dba105 | 2017-07-27 23:02:39 | [diff] [blame] | 24 | |
| 25 | GpuFeatureInfo& GpuFeatureInfo::operator=(const GpuFeatureInfo&) = default; |
| 26 | |
| 27 | GpuFeatureInfo& GpuFeatureInfo::operator=(GpuFeatureInfo&&) = default; |
| 28 | |
Zhenyao Mo | 08c9149 | 2017-08-24 22:57:57 | [diff] [blame] | 29 | void GpuFeatureInfo::ApplyToGLContext(gl::GLContext* gl_context) const { |
| 30 | DCHECK(gl_context); |
| 31 | gl::GLWorkarounds gl_workarounds; |
| 32 | if (IsWorkaroundEnabled(gpu::CLEAR_TO_ZERO_OR_ONE_BROKEN)) { |
| 33 | gl_workarounds.clear_to_zero_or_one_broken = true; |
| 34 | } |
| 35 | if (IsWorkaroundEnabled(RESET_TEXIMAGE2D_BASE_LEVEL)) { |
| 36 | gl_workarounds.reset_teximage2d_base_level = true; |
| 37 | } |
| 38 | gl_context->SetGLWorkarounds(gl_workarounds); |
| 39 | gl_context->SetDisabledGLExtensions(this->disabled_extensions); |
| 40 | } |
| 41 | |
| 42 | bool GpuFeatureInfo::IsWorkaroundEnabled(int32_t workaround) const { |
| 43 | return std::find(this->enabled_gpu_driver_bug_workarounds.begin(), |
| 44 | this->enabled_gpu_driver_bug_workarounds.end(), |
| 45 | workaround) != |
| 46 | this->enabled_gpu_driver_bug_workarounds.end(); |
| 47 | } |
| 48 | |
Zhenyao Mo | f920e13 | 2017-12-19 20:16:50 | [diff] [blame^] | 49 | bool GpuFeatureInfo::IsValid() const { |
| 50 | // Check if any feature status is undefined. |
| 51 | return status_values[GPU_FEATURE_TYPE_GPU_COMPOSITING] != |
| 52 | kGpuFeatureStatusUndefined; |
| 53 | } |
| 54 | |
ericrk | 41a1579e | 2017-02-10 20:56:28 | [diff] [blame] | 55 | } // namespace gpu |