OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/public/common/dwrite_font_platform_win.h" | 5 #include "content/public/common/dwrite_font_platform_win.h" |
6 | 6 |
7 #include <dwrite.h> | 7 #include <dwrite.h> |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 struct CacheRegion { | 274 struct CacheRegion { |
275 UINT64 start_offset; | 275 UINT64 start_offset; |
276 UINT64 length; | 276 UINT64 length; |
277 const BYTE* ptr; | 277 const BYTE* ptr; |
278 /* BYTE blob_[]; // Place holder for the blob that follows. */ | 278 /* BYTE blob_[]; // Place holder for the blob that follows. */ |
279 }; | 279 }; |
280 | 280 |
281 // Function to create static font cache file. | 281 // Function to create static font cache file. |
282 bool Create(const wchar_t* file_name) { | 282 bool Create(const wchar_t* file_name) { |
283 static_cache_.reset(new base::File(base::FilePath(file_name), | 283 static_cache_.reset(new base::File(base::FilePath(file_name), |
284 base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_WRITE)); | 284 base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_WRITE | |
| 285 base::File::FLAG_EXCLUSIVE_WRITE)); |
285 if (!static_cache_->IsValid()) { | 286 if (!static_cache_->IsValid()) { |
286 static_cache_.reset(); | 287 static_cache_.reset(); |
287 // TODO(shrikant): Convert this CHECK to DCHECK post canary. | |
288 // We have all fallbacks built in, so if we are not able to create | |
289 // static cache, browser can still run with old way of loading all fonts. | |
290 CHECK(FALSE); | |
291 return false; | 288 return false; |
292 } | 289 } |
293 CacheFileHeader header; | 290 CacheFileHeader header; |
294 | 291 |
295 // At offset 0 write cache version | 292 // At offset 0 write cache version |
296 static_cache_->Write(0, | 293 static_cache_->Write(0, |
297 reinterpret_cast<const char*>(&header), | 294 reinterpret_cast<const char*>(&header), |
298 sizeof(header)); | 295 sizeof(header)); |
299 | 296 |
300 static_cache_->Flush(); | 297 static_cache_->Flush(); |
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 if (!ValidateAndLoadCacheMap()) { | 901 if (!ValidateAndLoadCacheMap()) { |
905 cache_.reset(); | 902 cache_.reset(); |
906 return false; | 903 return false; |
907 } | 904 } |
908 | 905 |
909 return true; | 906 return true; |
910 } | 907 } |
911 | 908 |
912 void FontCollectionLoader::EnterStaticCacheMode(const WCHAR* file_name) { | 909 void FontCollectionLoader::EnterStaticCacheMode(const WCHAR* file_name) { |
913 cache_writer_.reset(new FontCacheWriter()); | 910 cache_writer_.reset(new FontCacheWriter()); |
914 cache_writer_->Create(file_name); | 911 if (cache_writer_->Create(file_name)) |
915 create_static_cache_ = true; | 912 create_static_cache_ = true; |
916 } | 913 } |
917 | 914 |
918 void FontCollectionLoader::LeaveStaticCacheMode() { | 915 void FontCollectionLoader::LeaveStaticCacheMode() { |
919 cache_writer_->Close(); | 916 cache_writer_->Close(); |
920 cache_writer_.reset(NULL); | 917 cache_writer_.reset(NULL); |
921 create_static_cache_ = false; | 918 create_static_cache_ = false; |
922 } | 919 } |
923 | 920 |
924 bool FontCollectionLoader::IsBuildStaticCacheMode() { | 921 bool FontCollectionLoader::IsBuildStaticCacheMode() { |
925 return create_static_cache_; | 922 return create_static_cache_; |
(...skipping 23 matching lines...) Expand all Loading... |
949 _TRUNCATE); | 946 _TRUNCATE); |
950 CacheTableEntry* table_entry = NULL; | 947 CacheTableEntry* table_entry = NULL; |
951 CacheMap::iterator iter = cache_map_.find(file_name); | 948 CacheMap::iterator iter = cache_map_.find(file_name); |
952 if (iter == cache_map_.end()) { | 949 if (iter == cache_map_.end()) { |
953 table_entry = new CacheTableEntry(); | 950 table_entry = new CacheTableEntry(); |
954 cache_map_[file_name] = table_entry; | 951 cache_map_[file_name] = table_entry; |
955 } else { | 952 } else { |
956 table_entry = iter->second; | 953 table_entry = iter->second; |
957 } | 954 } |
958 table_entry->file_size = entry->file_size; | 955 table_entry->file_size = entry->file_size; |
959 for (DWORD idx = 0; current_ptr < mem_file_end && idx < entry->entry_count; | 956 for (DWORD idx = 0; |
| 957 (current_ptr + sizeof(CacheFileOffsetEntry)) < mem_file_end && |
| 958 idx < entry->entry_count; |
960 idx++) { | 959 idx++) { |
961 CacheFileOffsetEntry* offset_entry = | 960 CacheFileOffsetEntry* offset_entry = |
962 reinterpret_cast<CacheFileOffsetEntry*>(current_ptr); | 961 reinterpret_cast<CacheFileOffsetEntry*>(current_ptr); |
963 CacheTableOffsetEntry table_offset_entry; | 962 CacheTableOffsetEntry table_offset_entry; |
964 table_offset_entry.start_offset = offset_entry->start_offset; | 963 table_offset_entry.start_offset = offset_entry->start_offset; |
965 table_offset_entry.length = offset_entry->length; | 964 table_offset_entry.length = offset_entry->length; |
966 table_offset_entry.inside_file_ptr = | 965 table_offset_entry.inside_file_ptr = |
967 current_ptr + sizeof(CacheFileOffsetEntry); | 966 current_ptr + sizeof(CacheFileOffsetEntry); |
968 table_entry->offset_entries.push_back(table_offset_entry); | 967 table_entry->offset_entries.push_back(table_offset_entry); |
969 current_ptr += sizeof(CacheFileOffsetEntry); | 968 current_ptr += sizeof(CacheFileOffsetEntry); |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1184 g_shared_font_cache.Set(mapping); | 1183 g_shared_font_cache.Set(mapping); |
1185 | 1184 |
1186 return true; | 1185 return true; |
1187 } | 1186 } |
1188 | 1187 |
1189 bool BuildFontCache(const base::FilePath& file) { | 1188 bool BuildFontCache(const base::FilePath& file) { |
1190 return BuildFontCacheInternal(file.value().c_str()); | 1189 return BuildFontCacheInternal(file.value().c_str()); |
1191 } | 1190 } |
1192 | 1191 |
1193 } // namespace content | 1192 } // namespace content |
OLD | NEW |