Flutter Engine
MinikinInternal.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 // Definitions internal to Minikin
18 
19 #ifndef MINIKIN_INTERNAL_H
20 #define MINIKIN_INTERNAL_H
21 
22 #include <mutex>
23 
24 #include <hb.h>
25 
26 #include <minikin/MinikinFont.h>
27 
28 namespace minikin {
29 
30 // All external Minikin interfaces are designed to be thread-safe.
31 // Presently, that's implemented by through a global lock, and having
32 // all external interfaces take that lock.
33 
34 extern std::recursive_mutex gMinikinLock;
35 
36 // Aborts if gMinikinLock is not acquired. Do nothing on the release build.
37 void assertMinikinLocked();
38 
39 hb_blob_t* getFontTable(const MinikinFont* minikinFont, uint32_t tag);
40 
41 constexpr uint32_t MAX_UNICODE_CODE_POINT = 0x10FFFF;
42 
43 // An RAII wrapper for hb_blob_t
44 class HbBlob {
45  public:
46  // Takes ownership of hb_blob_t object, caller is no longer
47  // responsible for calling hb_blob_destroy().
48  explicit HbBlob(hb_blob_t* blob) : mBlob(blob) {}
49 
50  ~HbBlob() { hb_blob_destroy(mBlob); }
51 
52  const uint8_t* get() const {
53  const char* data = hb_blob_get_data(mBlob, nullptr);
54  return reinterpret_cast<const uint8_t*>(data);
55  }
56 
57  size_t size() const { return (size_t)hb_blob_get_length(mBlob); }
58 
59  private:
60  hb_blob_t* mBlob;
61 };
62 
63 } // namespace minikin
64 
65 #endif // MINIKIN_INTERNAL_H
std::recursive_mutex gMinikinLock
void assertMinikinLocked()
constexpr uint32_t MAX_UNICODE_CODE_POINT
size_t size() const
HbBlob(hb_blob_t *blob)
hb_blob_t * getFontTable(const MinikinFont *minikinFont, uint32_t tag)