| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "content/child/browser_font_resource_trusted.h" | 5 #include "content/child/browser_font_resource_trusted.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 const PP_Rect* clip, | 308 const PP_Rect* clip, |
| 309 PP_Bool image_data_is_opaque) { | 309 PP_Bool image_data_is_opaque) { |
| 310 PP_Bool result = PP_FALSE; | 310 PP_Bool result = PP_FALSE; |
| 311 // Get and map the image data we're painting to. | 311 // Get and map the image data we're painting to. |
| 312 EnterResourceNoLock<PPB_ImageData_API> enter(image_data, true); | 312 EnterResourceNoLock<PPB_ImageData_API> enter(image_data, true); |
| 313 if (enter.failed()) | 313 if (enter.failed()) |
| 314 return result; | 314 return result; |
| 315 | 315 |
| 316 PPB_ImageData_API* image = static_cast<PPB_ImageData_API*>( | 316 PPB_ImageData_API* image = static_cast<PPB_ImageData_API*>( |
| 317 enter.object()); | 317 enter.object()); |
| 318 SkCanvas* canvas = image->GetPlatformCanvas(); | 318 CdlCanvas* canvas = image->GetPlatformCanvas(); |
| 319 bool needs_unmapping = false; | 319 bool needs_unmapping = false; |
| 320 if (!canvas) { | 320 if (!canvas) { |
| 321 needs_unmapping = true; | 321 needs_unmapping = true; |
| 322 image->Map(); | 322 image->Map(); |
| 323 canvas = image->GetPlatformCanvas(); | 323 canvas = image->GetPlatformCanvas(); |
| 324 if (!canvas) | 324 if (!canvas) |
| 325 return result; // Failure mapping. | 325 return result; // Failure mapping. |
| 326 } | 326 } |
| 327 | 327 |
| 328 if (!PP_ToBool(image_data_is_opaque)) { | 328 if (!PP_ToBool(image_data_is_opaque)) { |
| 329 // Ideally, LCD text should be configured at canvas creation time using | 329 // Ideally, LCD text should be configured at canvas creation time using |
| 330 // SkSurfaceProps. But because the API exposes image_data_is_opaque per | 330 // SkSurfaceProps. But because the API exposes image_data_is_opaque per |
| 331 // draw text call (allowing clients to essentially change their mind), | 331 // draw text call (allowing clients to essentially change their mind), |
| 332 // we have to handle it here. | 332 // we have to handle it here. |
| 333 SkImageInfo info; | 333 SkImageInfo info; |
| 334 size_t row_bytes; | 334 size_t row_bytes; |
| 335 void* pixels = canvas->accessTopLayerPixels(&info, &row_bytes); | 335 void* pixels = GetSkCanvas(canvas)->accessTopLayerPixels(&info, &row_bytes); |
| 336 if (!pixels) | 336 if (!pixels) |
| 337 return result; | 337 return result; |
| 338 | 338 |
| 339 SkBitmap bm; | 339 SkBitmap bm; |
| 340 if (!bm.installPixels(info, pixels, row_bytes)) | 340 if (!bm.installPixels(info, pixels, row_bytes)) |
| 341 return result; | 341 return result; |
| 342 | 342 |
| 343 SkSurfaceProps props(0, kUnknown_SkPixelGeometry); | 343 SkSurfaceProps props(0, kUnknown_SkPixelGeometry); |
| 344 SkCanvas temp_canvas(bm, props); | 344 CdlCanvas temp_canvas(bm, props); |
| 345 | 345 |
| 346 DrawTextToCanvas(&temp_canvas, *text, position, color, clip); | 346 DrawTextToCanvas(&temp_canvas, *text, position, color, clip); |
| 347 } else { | 347 } else { |
| 348 DrawTextToCanvas(canvas, *text, position, color, clip); | 348 DrawTextToCanvas(canvas, *text, position, color, clip); |
| 349 } | 349 } |
| 350 | 350 |
| 351 if (needs_unmapping) | 351 if (needs_unmapping) |
| 352 image->Unmap(); | 352 image->Unmap(); |
| 353 return PP_TRUE; | 353 return PP_TRUE; |
| 354 } | 354 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 } else { | 407 } else { |
| 408 // Character is past this run, account for the pixels and continue | 408 // Character is past this run, account for the pixels and continue |
| 409 // looking. | 409 // looking. |
| 410 cur_pixel_offset += font_->calculateWidth(run); | 410 cur_pixel_offset += font_->calculateWidth(run); |
| 411 } | 411 } |
| 412 } | 412 } |
| 413 return -1; // Requested a char beyond the end. | 413 return -1; // Requested a char beyond the end. |
| 414 } | 414 } |
| 415 | 415 |
| 416 void BrowserFontResource_Trusted::DrawTextToCanvas( | 416 void BrowserFontResource_Trusted::DrawTextToCanvas( |
| 417 SkCanvas* destination, | 417 CdlCanvas* destination, |
| 418 const PP_BrowserFont_Trusted_TextRun& text, | 418 const PP_BrowserFont_Trusted_TextRun& text, |
| 419 const PP_Point* position, | 419 const PP_Point* position, |
| 420 uint32_t color, | 420 uint32_t color, |
| 421 const PP_Rect* clip) { | 421 const PP_Rect* clip) { |
| 422 // Convert position and clip. | 422 // Convert position and clip. |
| 423 WebFloatPoint web_position(static_cast<float>(position->x), | 423 WebFloatPoint web_position(static_cast<float>(position->x), |
| 424 static_cast<float>(position->y)); | 424 static_cast<float>(position->y)); |
| 425 WebRect web_clip; | 425 WebRect web_clip; |
| 426 if (!clip) { | 426 if (!clip) { |
| 427 // Use entire canvas. SkCanvas doesn't have a size on it, so we just use | 427 // Use entire canvas. SkCanvas doesn't have a size on it, so we just use |
| (...skipping 16 matching lines...) Expand all Loading... |
| 444 | 444 |
| 445 // Advance to the next run. Note that we avoid doing this for the last run | 445 // Advance to the next run. Note that we avoid doing this for the last run |
| 446 // since it's unnecessary, measuring text is slow, and most of the time | 446 // since it's unnecessary, measuring text is slow, and most of the time |
| 447 // there will be only one run anyway. | 447 // there will be only one run anyway. |
| 448 if (i != runs.num_runs() - 1) | 448 if (i != runs.num_runs() - 1) |
| 449 web_position.x += font_->calculateWidth(run); | 449 web_position.x += font_->calculateWidth(run); |
| 450 } | 450 } |
| 451 } | 451 } |
| 452 | 452 |
| 453 } // namespace content | 453 } // namespace content |
| OLD | NEW |