• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 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 "config.h"
6 #include "platform/graphics/gpu/Extensions3DUtil.h"
7 
8 #include "public/platform/WebGraphicsContext3D.h"
9 #include "wtf/text/CString.h"
10 #include "wtf/text/StringHash.h"
11 
12 namespace WebCore {
13 
14 namespace {
15 
splitStringHelper(const String & str,HashSet<String> & set)16 void splitStringHelper(const String& str, HashSet<String>& set)
17 {
18     Vector<String> substrings;
19     str.split(" ", substrings);
20     for (size_t i = 0; i < substrings.size(); ++i)
21         set.add(substrings[i]);
22 }
23 
24 } // anonymous namespace
25 
create(blink::WebGraphicsContext3D * context)26 PassOwnPtr<Extensions3DUtil> Extensions3DUtil::create(blink::WebGraphicsContext3D* context)
27 {
28     OwnPtr<Extensions3DUtil> out = adoptPtr(new Extensions3DUtil(context));
29     if (!out->initializeExtensions())
30         return nullptr;
31     return out.release();
32 }
33 
Extensions3DUtil(blink::WebGraphicsContext3D * context)34 Extensions3DUtil::Extensions3DUtil(blink::WebGraphicsContext3D* context)
35     : m_context(context)
36 {
37 }
38 
~Extensions3DUtil()39 Extensions3DUtil::~Extensions3DUtil()
40 {
41 }
42 
initializeExtensions()43 bool Extensions3DUtil::initializeExtensions()
44 {
45     if (!m_context->makeContextCurrent()) {
46         // Most likely the GPU process exited and the attempt to reconnect to it failed.
47         // Need to try to restore the context again later.
48         return false;
49     }
50 
51     if (m_context->isContextLost()) {
52         // Need to try to restore the context again later.
53         return false;
54     }
55 
56     String extensionsString = m_context->getString(GL_EXTENSIONS);
57     splitStringHelper(extensionsString, m_enabledExtensions);
58 
59     String requestableExtensionsString = m_context->getRequestableExtensionsCHROMIUM();
60     splitStringHelper(requestableExtensionsString, m_requestableExtensions);
61 
62     return true;
63 }
64 
65 
supportsExtension(const String & name)66 bool Extensions3DUtil::supportsExtension(const String& name)
67 {
68     return m_enabledExtensions.contains(name) || m_requestableExtensions.contains(name);
69 }
70 
ensureExtensionEnabled(const String & name)71 bool Extensions3DUtil::ensureExtensionEnabled(const String& name)
72 {
73     if (m_enabledExtensions.contains(name))
74         return true;
75 
76     if (m_requestableExtensions.contains(name)) {
77         m_context->requestExtensionCHROMIUM(name.ascii().data());
78         m_enabledExtensions.clear();
79         m_requestableExtensions.clear();
80         initializeExtensions();
81     }
82     return m_enabledExtensions.contains(name);
83 }
84 
isExtensionEnabled(const String & name)85 bool Extensions3DUtil::isExtensionEnabled(const String& name)
86 {
87     return m_enabledExtensions.contains(name);
88 }
89 
canUseCopyTextureCHROMIUM(GLenum destFormat,GLenum destType,GLint level)90 bool Extensions3DUtil::canUseCopyTextureCHROMIUM(GLenum destFormat, GLenum destType, GLint level)
91 {
92     // FIXME: restriction of (RGB || RGBA)/UNSIGNED_BYTE/(Level 0) should be lifted when
93     // WebGraphicsContext3D::copyTextureCHROMIUM(...) are fully functional.
94     if ((destFormat == GL_RGB || destFormat == GL_RGBA)
95         && destType == GL_UNSIGNED_BYTE
96         && !level)
97         return true;
98     return false;
99 }
100 
101 } // namespace WebCore
102