Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 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 #ifndef PPAPI_SHARED_IMPL_FONT_IMPL_H_ | |
| 6 #define PPAPI_SHARED_IMPL_FONT_IMPL_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/scoped_ptr.h" | |
| 13 #include "ppapi/c/pp_bool.h" | |
| 14 #include "ppapi/c/pp_stdint.h" | |
| 15 | |
| 16 struct PP_FontDescription_Dev; | |
| 17 struct PP_FontMetrics_Dev; | |
| 18 struct PP_Point; | |
| 19 struct PP_Rect; | |
| 20 | |
| 21 namespace base { | |
| 22 class WaitableEvent; | |
| 23 } | |
| 24 | |
| 25 namespace skia { | |
| 26 class PlatformCanvas; | |
| 27 } // namespace skia | |
| 28 | |
| 29 namespace WebKit { | |
| 30 class WebFont; | |
| 31 } // namespace WebKit | |
| 32 | |
| 33 namespace pp { | |
| 34 namespace shared_impl { | |
| 35 | |
| 36 // This class is a bit subtle. It's designed to be used in two contexts: | |
| 37 // - In the renderer in the same thread as WebKit. | |
| 38 // - On a special WebKit thread in the plugin process. | |
| 39 // As a result, the actual implementation is provided in terms of functions | |
| 40 // prefixed by "Do" that don't depend on any global Pepper state, and that | |
| 41 // supply the return values via output parameters (for the other-thread case). | |
| 42 // Each implementation is then in charge of setting up the call appropriately. | |
| 43 // | |
| 44 // The Do* functions take an optional waitable event. If provided, this | |
| 45 // event will be signaled when the function completes. This allows the | |
| 46 // cross-thread implementation to know when the function completes. | |
| 47 class FontImpl { | |
| 48 public: | |
| 49 // C++ version of PP_TextRun_Dev. Since the Do* functions will be called on | |
| 50 // an alternate thread in the proxy, and since there are different methods | |
| 51 // of converting PP_Var -> strings in the plugin and the proxy, we can't | |
| 52 // use PP_Vars in the Do* funcitons below. | |
|
piman
2011/05/09 20:13:44
funcitons->functions
| |
| 53 struct TextRun { | |
| 54 std::string text; | |
| 55 bool rtl; | |
| 56 bool override_direction; | |
| 57 }; | |
| 58 | |
| 59 FontImpl(); | |
| 60 virtual ~FontImpl(); | |
| 61 | |
| 62 // Validates the parameters in thee description. Can be called on any thread. | |
| 63 static bool IsPPFontDescriptionValid(const PP_FontDescription_Dev& desc); | |
| 64 | |
| 65 protected: | |
| 66 // DoDrawText takes too many arguments to be used with base::Bind, so we | |
| 67 // use this struct to hold them. | |
| 68 struct DrawTextParams { | |
| 69 DrawTextParams(skia::PlatformCanvas* destination_arg, | |
| 70 const TextRun& text_arg, | |
| 71 const PP_Point* position_arg, | |
|
piman
2011/05/09 20:13:44
Can we make position a const & as well, for consis
brettw
2011/05/09 21:00:35
My internal functions match the PPAPI functions, w
| |
| 72 uint32_t color_arg, | |
| 73 const PP_Rect* clip_arg, | |
| 74 bool image_data_is_opaque_arg); | |
| 75 ~DrawTextParams(); | |
| 76 | |
| 77 skia::PlatformCanvas* destination; | |
| 78 const TextRun& text; | |
| 79 const PP_Point* position; | |
| 80 uint32_t color; | |
| 81 const PP_Rect* clip; | |
| 82 bool image_data_is_opaque; | |
| 83 }; | |
| 84 | |
| 85 // The face name from the description is given in desc_face so we can avoid | |
| 86 // a dependency on var conversion. See class description for waitable_event | |
| 87 // documentation. | |
| 88 void DoCreate(base::WaitableEvent* event, | |
| 89 const PP_FontDescription_Dev& desc, | |
| 90 const std::string& desc_face); | |
| 91 | |
| 92 // The face name in the description is not filled in to avoid a dependency | |
| 93 // on creating vars. Instead, the face name is placed into the given string. | |
| 94 // See class description for waitable_event documentation. | |
| 95 void DoDescribe(base::WaitableEvent* event, | |
| 96 PP_FontDescription_Dev* description, | |
| 97 std::string* face, | |
| 98 PP_FontMetrics_Dev* metrics, | |
| 99 PP_Bool* result); | |
| 100 void DoDrawTextAt(base::WaitableEvent* event, | |
| 101 const DrawTextParams& params); | |
| 102 void DoMeasureText(base::WaitableEvent* event, | |
| 103 const TextRun& text, int32_t* result); | |
| 104 void DoCharacterOffsetForPixel(base::WaitableEvent* event, | |
| 105 const TextRun& text, | |
| 106 int32_t pixel_position, | |
| 107 uint32_t* result); | |
| 108 void DoPixelOffsetForCharacter(base::WaitableEvent* event, | |
| 109 const TextRun& text, | |
| 110 uint32_t char_offset, | |
| 111 int32_t* result); | |
| 112 | |
| 113 // Access only on the WebKit thread. | |
| 114 scoped_ptr<WebKit::WebFont> font_; | |
| 115 | |
| 116 private: | |
| 117 DISALLOW_COPY_AND_ASSIGN(FontImpl); | |
| 118 }; | |
| 119 | |
| 120 } // namespace shared_impl | |
| 121 } // namespace pp | |
| 122 | |
| 123 #endif // PPAPI_SHARED_IMPL_FONT_IMPL_H_ | |
| OLD | NEW |