/src/mozilla-central/dom/canvas/WebGLExtensionSRGB.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | | |
6 | | #include "WebGLExtensions.h" |
7 | | |
8 | | #include "GLContext.h" |
9 | | #include "mozilla/dom/WebGLRenderingContextBinding.h" |
10 | | #include "WebGLContext.h" |
11 | | #include "WebGLFormats.h" |
12 | | |
13 | | namespace mozilla { |
14 | | |
15 | | WebGLExtensionSRGB::WebGLExtensionSRGB(WebGLContext* webgl) |
16 | | : WebGLExtensionBase(webgl) |
17 | 0 | { |
18 | 0 | MOZ_ASSERT(IsSupported(webgl), "Don't construct extension if unsupported."); |
19 | 0 |
|
20 | 0 | gl::GLContext* gl = webgl->GL(); |
21 | 0 | if (!gl->IsGLES()) { |
22 | 0 | // Desktop OpenGL requires the following to be enabled in order to |
23 | 0 | // support sRGB operations on framebuffers. |
24 | 0 | gl->fEnable(LOCAL_GL_FRAMEBUFFER_SRGB_EXT); |
25 | 0 | } |
26 | 0 |
|
27 | 0 | auto& fua = webgl->mFormatUsage; |
28 | 0 |
|
29 | 0 | RefPtr<gl::GLContext> gl_ = gl; // Bug 1201275 |
30 | 0 | const auto fnAdd = [&fua, &gl_](webgl::EffectiveFormat effFormat, GLenum format, |
31 | 0 | GLenum desktopUnpackFormat) |
32 | 0 | { |
33 | 0 | auto usage = fua->EditUsage(effFormat); |
34 | 0 | usage->isFilterable = true; |
35 | 0 |
|
36 | 0 | webgl::DriverUnpackInfo dui = {format, format, LOCAL_GL_UNSIGNED_BYTE}; |
37 | 0 | const auto pi = dui.ToPacking(); |
38 | 0 |
|
39 | 0 | if (!gl_->IsGLES()) |
40 | 0 | dui.unpackFormat = desktopUnpackFormat; |
41 | 0 |
|
42 | 0 | fua->AddTexUnpack(usage, pi, dui); |
43 | 0 |
|
44 | 0 | fua->AllowUnsizedTexFormat(pi, usage); |
45 | 0 | }; |
46 | 0 |
|
47 | 0 | fnAdd(webgl::EffectiveFormat::SRGB8, LOCAL_GL_SRGB, LOCAL_GL_RGB); |
48 | 0 | fnAdd(webgl::EffectiveFormat::SRGB8_ALPHA8, LOCAL_GL_SRGB_ALPHA, LOCAL_GL_RGBA); |
49 | 0 |
|
50 | 0 | auto usage = fua->EditUsage(webgl::EffectiveFormat::SRGB8_ALPHA8); |
51 | 0 | usage->SetRenderable(); |
52 | 0 | fua->AllowRBFormat(LOCAL_GL_SRGB8_ALPHA8, usage); |
53 | 0 | } |
54 | | |
55 | | WebGLExtensionSRGB::~WebGLExtensionSRGB() |
56 | 0 | { |
57 | 0 | } |
58 | | |
59 | | bool |
60 | | WebGLExtensionSRGB::IsSupported(const WebGLContext* const webgl) |
61 | 0 | { |
62 | 0 | return webgl->gl->IsSupported(gl::GLFeature::sRGB); |
63 | 0 | } |
64 | | |
65 | | |
66 | | IMPL_WEBGL_EXTENSION_GOOP(WebGLExtensionSRGB, EXT_sRGB) |
67 | | |
68 | | } // namespace mozilla |