| Index: ppapi/proxy/ppb_font_proxy.cc
|
| ===================================================================
|
| --- ppapi/proxy/ppb_font_proxy.cc (revision 72517)
|
| +++ ppapi/proxy/ppb_font_proxy.cc (working copy)
|
| @@ -1,10 +1,11 @@
|
| -// Copyright (c) 2010 The Chromium Authors. All rights reserved.
|
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| #include "ppapi/proxy/ppb_font_proxy.h"
|
|
|
| #include "ppapi/c/dev/ppb_font_dev.h"
|
| +#include "ppapi/proxy/image_data.h"
|
| #include "ppapi/proxy/plugin_dispatcher.h"
|
| #include "ppapi/proxy/plugin_resource.h"
|
| #include "ppapi/proxy/ppapi_messages.h"
|
| @@ -14,7 +15,7 @@
|
|
|
| class Font : public PluginResource {
|
| public:
|
| - Font(PP_Instance instance);
|
| + Font(PP_Instance instance, SerializedResource resource);
|
| virtual ~Font();
|
|
|
| // PluginResource overrides.
|
| @@ -31,7 +32,8 @@
|
| DISALLOW_COPY_AND_ASSIGN(Font);
|
| };
|
|
|
| -Font::Font(PP_Instance instance) : PluginResource(instance) {
|
| +Font::Font(PP_Instance instance, SerializedResource resource)
|
| + : PluginResource(instance, resource) {
|
| memset(&desc_, 0, sizeof(PP_FontDescription_Dev));
|
| desc_.face.type = PP_VARTYPE_UNDEFINED;
|
| memset(&metrics_, 0, sizeof(PP_FontMetrics_Dev));
|
| @@ -52,17 +54,17 @@
|
| SerializedFontDescription in_description;
|
| in_description.SetFromPPFontDescription(dispatcher, *description, true);
|
|
|
| - PP_Resource result;
|
| + SerializedResource result;
|
| SerializedFontDescription out_description;
|
| std::string out_metrics;
|
| dispatcher->Send(new PpapiHostMsg_PPBFont_Create(
|
| INTERFACE_ID_PPB_FONT,
|
| instance, in_description, &result, &out_description, &out_metrics));
|
|
|
| - if (!result)
|
| + if (result.is_null())
|
| return 0; // Failure creating font.
|
|
|
| - linked_ptr<Font> object(new Font(instance));
|
| + linked_ptr<Font> object(new Font(instance, result));
|
| out_description.SetToPPFontDescription(dispatcher, object->desc_ptr(), true);
|
|
|
| // Convert the metrics, this is just serialized as a string of bytes.
|
| @@ -70,8 +72,7 @@
|
| return 0;
|
| memcpy(&object->metrics(), out_metrics.data(), sizeof(PP_FontMetrics_Dev));
|
|
|
| - PluginResourceTracker::GetInstance()->AddResource(result, object);
|
| - return result;
|
| + return PluginResourceTracker::GetInstance()->AddResource(object);
|
| }
|
|
|
| PP_Bool IsFont(PP_Resource resource) {
|
| @@ -102,13 +103,18 @@
|
| uint32_t color,
|
| const PP_Rect* clip,
|
| PP_Bool image_data_is_opaque) {
|
| - Font* object = PluginResource::GetAs<Font>(font_id);
|
| - if (!object)
|
| + Font* font_object = PluginResource::GetAs<Font>(font_id);
|
| + if (!font_object)
|
| return PP_FALSE;
|
| + ImageData* image_object = PluginResource::GetAs<ImageData>(image_data);
|
| + if (!image_object)
|
| + return PP_FALSE;
|
| + if (font_object->instance() != image_object->instance())
|
| + return PP_FALSE;
|
|
|
| PPBFont_DrawTextAt_Params params;
|
| - params.font = font_id;
|
| - params.image_data = image_data;
|
| + params.font = font_object->host_resource();
|
| + params.image_data = image_object->host_resource();
|
| params.text_is_rtl = text->rtl;
|
| params.override_direction = text->override_direction;
|
| params.position = *position;
|
| @@ -122,7 +128,8 @@
|
| }
|
| params.image_data_is_opaque = image_data_is_opaque;
|
|
|
| - Dispatcher* dispatcher = PluginDispatcher::GetForInstance(object->instance());
|
| + Dispatcher* dispatcher = PluginDispatcher::GetForInstance(
|
| + image_object->instance());
|
| PP_Bool result = PP_FALSE;
|
| if (dispatcher) {
|
| dispatcher->Send(new PpapiHostMsg_PPBFont_DrawTextAt(
|
| @@ -141,7 +148,7 @@
|
| Dispatcher* dispatcher = PluginDispatcher::GetForInstance(object->instance());
|
| int32_t result = 0;
|
| dispatcher->Send(new PpapiHostMsg_PPBFont_MeasureText(
|
| - INTERFACE_ID_PPB_FONT, font_id,
|
| + INTERFACE_ID_PPB_FONT, object->host_resource(),
|
| SerializedVarSendInput(dispatcher, text->text),
|
| text->rtl, text->override_direction, &result));
|
| return result;
|
| @@ -157,7 +164,7 @@
|
| Dispatcher* dispatcher = PluginDispatcher::GetForInstance(object->instance());
|
| uint32_t result = 0;
|
| dispatcher->Send(new PpapiHostMsg_PPBFont_CharacterOffsetForPixel(
|
| - INTERFACE_ID_PPB_FONT, font_id,
|
| + INTERFACE_ID_PPB_FONT, object->host_resource(),
|
| SerializedVarSendInput(dispatcher, text->text),
|
| text->rtl, text->override_direction, pixel_position, &result));
|
| return result;
|
| @@ -173,7 +180,7 @@
|
| Dispatcher* dispatcher = PluginDispatcher::GetForInstance(object->instance());
|
| int32_t result = 0;
|
| dispatcher->Send(new PpapiHostMsg_PPBFont_PixelOffsetForCharacter(
|
| - INTERFACE_ID_PPB_FONT, font_id,
|
| + INTERFACE_ID_PPB_FONT, object->host_resource(),
|
| SerializedVarSendInput(dispatcher, text->text),
|
| text->rtl, text->override_direction, char_offset, &result));
|
| return result;
|
| @@ -228,7 +235,7 @@
|
| void PPB_Font_Proxy::OnMsgCreate(
|
| PP_Instance instance,
|
| const SerializedFontDescription& in_description,
|
| - PP_Resource* result,
|
| + SerializedResource* result,
|
| SerializedFontDescription* out_description,
|
| std::string* out_metrics) {
|
| // Convert the face name in the input description.
|
| @@ -241,11 +248,12 @@
|
| memset(&out_pp_desc, 0, sizeof(PP_FontDescription_Dev));
|
| out_pp_desc.face = PP_MakeUndefined();
|
|
|
| - *result = ppb_font_target()->Create(instance, &in_pp_desc);
|
| - if (*result) {
|
| + result->set_host_resource(ppb_font_target()->Create(instance, &in_pp_desc));
|
| + if (result->is_null()) {
|
| // Get the metrics and resulting description to return to the browser.
|
| PP_FontMetrics_Dev metrics;
|
| - if (ppb_font_target()->Describe(*result, &out_pp_desc, &metrics)) {
|
| + if (ppb_font_target()->Describe(result->host_resource(), &out_pp_desc,
|
| + &metrics)) {
|
| out_metrics->assign(reinterpret_cast<const char*>(&metrics),
|
| sizeof(PP_FontMetrics_Dev));
|
| }
|
| @@ -264,12 +272,12 @@
|
| run.rtl = params.text_is_rtl;
|
| run.override_direction = params.override_direction;
|
|
|
| - *result = ppb_font_target()->DrawTextAt(params.font, params.image_data,
|
| - &run, ¶ms.position, params.color,
|
| + *result = ppb_font_target()->DrawTextAt(params.font.host_resource(),
|
| + params.image_data.host_resource(), &run, ¶ms.position, params.color,
|
| params.clip_is_null ? NULL : ¶ms.clip, params.image_data_is_opaque);
|
| }
|
|
|
| -void PPB_Font_Proxy::OnMsgMeasureText(PP_Resource font,
|
| +void PPB_Font_Proxy::OnMsgMeasureText(SerializedResource font,
|
| SerializedVarReceiveInput text,
|
| PP_Bool text_is_rtl,
|
| PP_Bool override_direction,
|
| @@ -279,11 +287,11 @@
|
| run.rtl = text_is_rtl;
|
| run.override_direction = override_direction;
|
|
|
| - *result = ppb_font_target()->MeasureText(font, &run);
|
| + *result = ppb_font_target()->MeasureText(font.host_resource(), &run);
|
| }
|
|
|
| void PPB_Font_Proxy::OnMsgCharacterOffsetForPixel(
|
| - PP_Resource font,
|
| + SerializedResource font,
|
| SerializedVarReceiveInput text,
|
| PP_Bool text_is_rtl,
|
| PP_Bool override_direction,
|
| @@ -294,11 +302,12 @@
|
| run.rtl = text_is_rtl;
|
| run.override_direction = override_direction;
|
|
|
| - *result = ppb_font_target()->CharacterOffsetForPixel(font, &run, pixel_pos);
|
| + *result = ppb_font_target()->CharacterOffsetForPixel(font.host_resource(),
|
| + &run, pixel_pos);
|
| }
|
|
|
| void PPB_Font_Proxy::OnMsgPixelOffsetForCharacter(
|
| - PP_Resource font,
|
| + SerializedResource font,
|
| SerializedVarReceiveInput text,
|
| PP_Bool text_is_rtl,
|
| PP_Bool override_direction,
|
| @@ -309,7 +318,8 @@
|
| run.rtl = text_is_rtl;
|
| run.override_direction = override_direction;
|
|
|
| - *result = ppb_font_target()->PixelOffsetForCharacter(font, &run, char_offset);
|
| + *result = ppb_font_target()->PixelOffsetForCharacter(font.host_resource(),
|
| + &run, char_offset);
|
| }
|
|
|
| } // namespace proxy
|
|
|