• 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 blink {
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(WebGraphicsContext3D * context)26 PassOwnPtr<Extensions3DUtil> Extensions3DUtil::create(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(WebGraphicsContext3D * context)34 Extensions3DUtil::Extensions3DUtil(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->isContextLost()) {
46         // Need to try to restore the context again later.
47         return false;
48     }
49 
50     String extensionsString = m_context->getString(GL_EXTENSIONS);
51     splitStringHelper(extensionsString, m_enabledExtensions);
52 
53     String requestableExtensionsString = m_context->getRequestableExtensionsCHROMIUM();
54     splitStringHelper(requestableExtensionsString, m_requestableExtensions);
55 
56     return true;
57 }
58 
59 
supportsExtension(const String & name)60 bool Extensions3DUtil::supportsExtension(const String& name)
61 {
62     return m_enabledExtensions.contains(name) || m_requestableExtensions.contains(name);
63 }
64 
ensureExtensionEnabled(const String & name)65 bool Extensions3DUtil::ensureExtensionEnabled(const String& name)
66 {
67     if (m_enabledExtensions.contains(name))
68         return true;
69 
70     if (m_requestableExtensions.contains(name)) {
71         m_context->requestExtensionCHROMIUM(name.ascii().data());
72         m_enabledExtensions.clear();
73         m_requestableExtensions.clear();
74         initializeExtensions();
75     }
76     return m_enabledExtensions.contains(name);
77 }
78 
isExtensionEnabled(const String & name)79 bool Extensions3DUtil::isExtensionEnabled(const String& name)
80 {
81     return m_enabledExtensions.contains(name);
82 }
83 
canUseCopyTextureCHROMIUM(GLenum destFormat,GLenum destType,GLint level)84 bool Extensions3DUtil::canUseCopyTextureCHROMIUM(GLenum destFormat, GLenum destType, GLint level)
85 {
86     // FIXME: restriction of (RGB || RGBA)/UNSIGNED_BYTE/(Level 0) should be lifted when
87     // WebGraphicsContext3D::copyTextureCHROMIUM(...) are fully functional.
88     if ((destFormat == GL_RGB || destFormat == GL_RGBA)
89         && destType == GL_UNSIGNED_BYTE
90         && !level)
91         return true;
92     return false;
93 }
94 
95 } // namespace blink
96