OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 #include "cc/output/buffer_to_texture_target_map.h" |
| 5 |
| 6 #include <vector> |
| 7 |
| 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/string_split.h" |
| 10 #include "gpu/GLES2/gl2extchromium.h" |
| 11 |
| 12 namespace cc { |
| 13 |
| 14 BufferToTextureTargetMap StringToBufferToTextureTargetMap( |
| 15 const std::string& str) { |
| 16 BufferToTextureTargetMap map; |
| 17 std::vector<std::string> entries = |
| 18 base::SplitString(str, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 19 for (const auto& entry : entries) { |
| 20 std::vector<std::string> fields = base::SplitString( |
| 21 entry, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 22 CHECK_EQ(fields.size(), 3u); |
| 23 uint32_t usage = 0; |
| 24 uint32_t format = 0; |
| 25 uint32_t target = 0; |
| 26 bool succeeded = base::StringToUint(fields[0], &usage) && |
| 27 base::StringToUint(fields[1], &format) && |
| 28 base::StringToUint(fields[2], &target); |
| 29 CHECK(succeeded); |
| 30 CHECK_LE(usage, static_cast<uint32_t>(gfx::BufferUsage::LAST)); |
| 31 CHECK_LE(format, static_cast<uint32_t>(gfx::BufferFormat::LAST)); |
| 32 map.insert(BufferToTextureTargetMap::value_type( |
| 33 BufferToTextureTargetKey(static_cast<gfx::BufferUsage>(usage), |
| 34 static_cast<gfx::BufferFormat>(format)), |
| 35 target)); |
| 36 } |
| 37 return map; |
| 38 } |
| 39 |
| 40 std::string BufferToTextureTargetMapToString( |
| 41 const BufferToTextureTargetMap& map) { |
| 42 std::string str; |
| 43 for (const auto& entry : map) { |
| 44 if (!str.empty()) |
| 45 str += ";"; |
| 46 str += base::UintToString(static_cast<uint32_t>(entry.first.first)); |
| 47 str += ","; |
| 48 str += base::UintToString(static_cast<uint32_t>(entry.first.second)); |
| 49 str += ","; |
| 50 str += base::UintToString(entry.second); |
| 51 } |
| 52 return str; |
| 53 } |
| 54 |
| 55 BufferToTextureTargetMap DefaultBufferToTextureTargetMapForTesting() { |
| 56 BufferToTextureTargetMap image_targets; |
| 57 for (int usage_idx = 0; usage_idx <= static_cast<int>(gfx::BufferUsage::LAST); |
| 58 ++usage_idx) { |
| 59 gfx::BufferUsage usage = static_cast<gfx::BufferUsage>(usage_idx); |
| 60 for (int format_idx = 0; |
| 61 format_idx <= static_cast<int>(gfx::BufferFormat::LAST); |
| 62 ++format_idx) { |
| 63 gfx::BufferFormat format = static_cast<gfx::BufferFormat>(format_idx); |
| 64 image_targets.insert(BufferToTextureTargetMap::value_type( |
| 65 BufferToTextureTargetKey(usage, format), GL_TEXTURE_2D)); |
| 66 } |
| 67 } |
| 68 |
| 69 return image_targets; |
| 70 } |
| 71 |
| 72 } // namespace cc |
OLD | NEW |