| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef PPAPI_PROXY_PPB_FONT_PROXY_H_ | 5 #ifndef PPAPI_PROXY_PPB_FONT_PROXY_H_ |
| 6 #define PPAPI_PROXY_PPB_FONT_PROXY_H_ | 6 #define PPAPI_PROXY_PPB_FONT_PROXY_H_ |
| 7 | 7 |
| 8 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
| 9 #include "base/synchronization/waitable_event.h" | |
| 10 #include "ppapi/proxy/interface_proxy.h" | 9 #include "ppapi/proxy/interface_proxy.h" |
| 11 #include "ppapi/shared_impl/function_group_base.h" | 10 #include "ppapi/shared_impl/function_group_base.h" |
| 12 #include "ppapi/shared_impl/host_resource.h" | 11 #include "ppapi/shared_impl/host_resource.h" |
| 13 #include "ppapi/shared_impl/resource.h" | 12 #include "ppapi/shared_impl/resource.h" |
| 14 #include "ppapi/shared_impl/webkit_forwarding.h" | |
| 15 #include "ppapi/thunk/ppb_font_api.h" | 13 #include "ppapi/thunk/ppb_font_api.h" |
| 16 | 14 |
| 17 namespace ppapi { | 15 namespace ppapi { |
| 18 namespace proxy { | 16 namespace proxy { |
| 19 | 17 |
| 20 class PPB_Font_Proxy : public InterfaceProxy, | 18 class PPB_Font_Proxy : public InterfaceProxy, |
| 21 public ppapi::thunk::PPB_Font_FunctionAPI { | 19 public ppapi::thunk::PPB_Font_FunctionAPI { |
| 22 public: | 20 public: |
| 23 explicit PPB_Font_Proxy(Dispatcher* dispatcher); | 21 explicit PPB_Font_Proxy(Dispatcher* dispatcher); |
| 24 virtual ~PPB_Font_Proxy(); | 22 virtual ~PPB_Font_Proxy(); |
| 25 | 23 |
| 26 // FunctionGroupBase overrides. | 24 // FunctionGroupBase overrides. |
| 27 virtual ppapi::thunk::PPB_Font_FunctionAPI* AsPPB_Font_FunctionAPI() OVERRIDE; | 25 virtual ppapi::thunk::PPB_Font_FunctionAPI* AsPPB_Font_FunctionAPI() OVERRIDE; |
| 28 | 26 |
| 29 // PPB_Font_FunctionAPI implementation. | 27 // PPB_Font_FunctionAPI implementation. |
| 30 virtual PP_Var GetFontFamilies(PP_Instance instance) OVERRIDE; | 28 virtual PP_Var GetFontFamilies(PP_Instance instance) OVERRIDE; |
| 31 | 29 |
| 32 // InterfaceProxy implementation. | 30 // InterfaceProxy implementation. |
| 33 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; | 31 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; |
| 34 | 32 |
| 35 static const ApiID kApiID = API_ID_PPB_FONT; | 33 static const ApiID kApiID = API_ID_PPB_FONT; |
| 36 | 34 |
| 37 private: | 35 private: |
| 38 DISALLOW_COPY_AND_ASSIGN(PPB_Font_Proxy); | 36 DISALLOW_COPY_AND_ASSIGN(PPB_Font_Proxy); |
| 39 }; | 37 }; |
| 40 | 38 |
| 41 class Font : public ppapi::Resource, | |
| 42 public ppapi::thunk::PPB_Font_API { | |
| 43 public: | |
| 44 // Note that there isn't a "real" resource in the renderer backing a font, | |
| 45 // it lives entirely in the plugin process. So the resource ID in the host | |
| 46 // resource should be 0. However, various code assumes the instance in the | |
| 47 // host resource is valid (this is how resources are associated with | |
| 48 // instances), so that should be set. | |
| 49 Font(const ppapi::HostResource& resource, const PP_FontDescription_Dev& desc); | |
| 50 virtual ~Font(); | |
| 51 | |
| 52 // Resource. | |
| 53 virtual ppapi::thunk::PPB_Font_API* AsPPB_Font_API() OVERRIDE; | |
| 54 | |
| 55 // PPB_Font_API implementation. | |
| 56 virtual PP_Bool Describe(PP_FontDescription_Dev* description, | |
| 57 PP_FontMetrics_Dev* metrics) OVERRIDE; | |
| 58 virtual PP_Bool DrawTextAt(PP_Resource image_data, | |
| 59 const PP_TextRun_Dev* text, | |
| 60 const PP_Point* position, | |
| 61 uint32_t color, | |
| 62 const PP_Rect* clip, | |
| 63 PP_Bool image_data_is_opaque) OVERRIDE; | |
| 64 virtual int32_t MeasureText(const PP_TextRun_Dev* text) OVERRIDE; | |
| 65 virtual uint32_t CharacterOffsetForPixel(const PP_TextRun_Dev* text, | |
| 66 int32_t pixel_position) OVERRIDE; | |
| 67 virtual int32_t PixelOffsetForCharacter(const PP_TextRun_Dev* text, | |
| 68 uint32_t char_offset) OVERRIDE; | |
| 69 | |
| 70 private: | |
| 71 // Posts the given closure to the WebKit thread. | |
| 72 // If |blocking| is true, the method waits on |webkit_event_| for the task to | |
| 73 // continue. | |
| 74 void RunOnWebKitThread(bool blocking, const base::Closure& task); | |
| 75 | |
| 76 static void DeleteFontForwarding( | |
| 77 ppapi::WebKitForwarding::Font* font_forwarding); | |
| 78 | |
| 79 base::WaitableEvent webkit_event_; | |
| 80 | |
| 81 // This class owns |font_forwarding_|. | |
| 82 // |font_forwarding_| should always be used on the WebKit thread (including | |
| 83 // destruction). | |
| 84 ppapi::WebKitForwarding::Font* font_forwarding_; | |
| 85 | |
| 86 DISALLOW_COPY_AND_ASSIGN(Font); | |
| 87 }; | |
| 88 | |
| 89 } // namespace proxy | 39 } // namespace proxy |
| 90 } // namespace ppapi | 40 } // namespace ppapi |
| 91 | 41 |
| 92 #endif // PPAPI_PROXY_PPB_FONT_PROXY_H_ | 42 #endif // PPAPI_PROXY_PPB_FONT_PROXY_H_ |
| OLD | NEW |