OLD | NEW |
| (Empty) |
1 // Copyright 2015 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 "components/font_service/public/cpp/mapped_font_file.h" | |
6 | |
7 #include "base/files/file_util.h" | |
8 #include "base/threading/thread_restrictions.h" | |
9 #include "skia/ext/refptr.h" | |
10 #include "skia/ext/skia_utils_base.h" | |
11 #include "third_party/skia/include/core/SkData.h" | |
12 #include "third_party/skia/include/core/SkStream.h" | |
13 | |
14 namespace font_service { | |
15 namespace internal { | |
16 | |
17 MappedFontFile::MappedFontFile(uint32_t font_id) | |
18 : font_id_(font_id), observer_(nullptr) {} | |
19 | |
20 bool MappedFontFile::Initialize(base::File file) { | |
21 base::ThreadRestrictions::ScopedAllowIO allow_mmap; | |
22 return mapped_font_file_.Initialize(file.Pass()); | |
23 } | |
24 | |
25 SkMemoryStream* MappedFontFile::CreateMemoryStream() { | |
26 DCHECK(mapped_font_file_.IsValid()); | |
27 auto data = skia::AdoptRef( | |
28 SkData::NewWithProc(mapped_font_file_.data(), mapped_font_file_.length(), | |
29 &MappedFontFile::ReleaseProc, this)); | |
30 if (!data) | |
31 return nullptr; | |
32 AddRef(); | |
33 return new SkMemoryStream(data.get()); | |
34 } | |
35 | |
36 MappedFontFile::~MappedFontFile() { | |
37 if (observer_) | |
38 observer_->OnMappedFontFileDestroyed(this); | |
39 } | |
40 | |
41 // static | |
42 void MappedFontFile::ReleaseProc(const void* ptr, void* context) { | |
43 base::ThreadRestrictions::ScopedAllowIO allow_munmap; | |
44 static_cast<MappedFontFile*>(context)->Release(); | |
45 } | |
46 | |
47 } // namespace internal | |
48 } // namespace font_service | |
OLD | NEW |