| OLD | NEW |
| (Empty) |
| 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 "sky/engine/platform/graphics/gpu/Extensions3DUtil.h" | |
| 6 | |
| 7 #include "sky/engine/public/platform/WebGraphicsContext3D.h" | |
| 8 #include "sky/engine/wtf/PassOwnPtr.h" | |
| 9 #include "sky/engine/wtf/text/CString.h" | |
| 10 #include "sky/engine/wtf/text/StringHash.h" | |
| 11 | |
| 12 namespace blink { | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 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 | |
| 26 PassOwnPtr<Extensions3DUtil> Extensions3DUtil::create(WebGraphicsContext3D* cont
ext) | |
| 27 { | |
| 28 OwnPtr<Extensions3DUtil> out = adoptPtr(new Extensions3DUtil(context)); | |
| 29 if (!out->initializeExtensions()) | |
| 30 return nullptr; | |
| 31 return out.release(); | |
| 32 } | |
| 33 | |
| 34 Extensions3DUtil::Extensions3DUtil(WebGraphicsContext3D* context) | |
| 35 : m_context(context) | |
| 36 { | |
| 37 } | |
| 38 | |
| 39 Extensions3DUtil::~Extensions3DUtil() | |
| 40 { | |
| 41 } | |
| 42 | |
| 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->getRequestableExtensionsCHRO
MIUM(); | |
| 54 splitStringHelper(requestableExtensionsString, m_requestableExtensions); | |
| 55 | |
| 56 return true; | |
| 57 } | |
| 58 | |
| 59 | |
| 60 bool Extensions3DUtil::supportsExtension(const String& name) | |
| 61 { | |
| 62 return m_enabledExtensions.contains(name) || m_requestableExtensions.contain
s(name); | |
| 63 } | |
| 64 | |
| 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 | |
| 79 bool Extensions3DUtil::isExtensionEnabled(const String& name) | |
| 80 { | |
| 81 return m_enabledExtensions.contains(name); | |
| 82 } | |
| 83 | |
| 84 bool Extensions3DUtil::canUseCopyTextureCHROMIUM(GLenum destFormat, GLenum destT
ype, GLint level) | |
| 85 { | |
| 86 // FIXME: restriction of (RGB || RGBA)/UNSIGNED_BYTE/(Level 0) should be lif
ted 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 | |
| OLD | NEW |