| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "cc/resources/picture.h" | 5 #include "cc/resources/picture.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 | 73 |
| 74 // Try JPEG. | 74 // Try JPEG. |
| 75 scoped_ptr<SkBitmap> decoded_jpeg(gfx::JPEGCodec::Decode(data, size)); | 75 scoped_ptr<SkBitmap> decoded_jpeg(gfx::JPEGCodec::Decode(data, size)); |
| 76 if (decoded_jpeg) { | 76 if (decoded_jpeg) { |
| 77 *bm = *decoded_jpeg; | 77 *bm = *decoded_jpeg; |
| 78 return true; | 78 return true; |
| 79 } | 79 } |
| 80 return false; | 80 return false; |
| 81 } | 81 } |
| 82 | 82 |
| 83 class DisableLCDTextFilter : public SkDrawFilter { | |
| 84 public: | |
| 85 // SkDrawFilter interface. | |
| 86 virtual bool filter(SkPaint* paint, SkDrawFilter::Type type) OVERRIDE { | |
| 87 if (type != SkDrawFilter::kText_Type) | |
| 88 return true; | |
| 89 | |
| 90 paint->setLCDRenderText(false); | |
| 91 return true; | |
| 92 } | |
| 93 }; | |
| 94 | |
| 95 } // namespace | 83 } // namespace |
| 96 | 84 |
| 97 scoped_refptr<Picture> Picture::Create(gfx::Rect layer_rect) { | 85 scoped_refptr<Picture> Picture::Create(gfx::Rect layer_rect) { |
| 98 return make_scoped_refptr(new Picture(layer_rect)); | 86 return make_scoped_refptr(new Picture(layer_rect)); |
| 99 } | 87 } |
| 100 | 88 |
| 101 scoped_refptr<Picture> Picture::CreateFromValue(const base::Value* value) { | 89 scoped_refptr<Picture> Picture::CreateFromValue(const base::Value* value) { |
| 102 bool success; | 90 bool success; |
| 103 scoped_refptr<Picture> picture = | 91 scoped_refptr<Picture> picture = |
| 104 make_scoped_refptr(new Picture(value, &success)); | 92 make_scoped_refptr(new Picture(value, &success)); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 } | 293 } |
| 306 | 294 |
| 307 min_pixel_cell_ = gfx::Point(min_x, min_y); | 295 min_pixel_cell_ = gfx::Point(min_x, min_y); |
| 308 max_pixel_cell_ = gfx::Point(max_x, max_y); | 296 max_pixel_cell_ = gfx::Point(max_x, max_y); |
| 309 } | 297 } |
| 310 | 298 |
| 311 void Picture::Raster( | 299 void Picture::Raster( |
| 312 SkCanvas* canvas, | 300 SkCanvas* canvas, |
| 313 SkDrawPictureCallback* callback, | 301 SkDrawPictureCallback* callback, |
| 314 gfx::Rect content_rect, | 302 gfx::Rect content_rect, |
| 315 float contents_scale, | 303 float contents_scale) { |
| 316 bool enable_lcd_text) { | |
| 317 TRACE_EVENT_BEGIN1("cc", "Picture::Raster", | 304 TRACE_EVENT_BEGIN1("cc", "Picture::Raster", |
| 318 "data", AsTraceableRasterData(content_rect, contents_scale)); | 305 "data", AsTraceableRasterData(content_rect, contents_scale)); |
| 319 | 306 |
| 320 DCHECK(picture_); | 307 DCHECK(picture_); |
| 321 | 308 |
| 322 skia::RefPtr<DisableLCDTextFilter> disable_lcd_text_filter; | |
| 323 | |
| 324 canvas->save(); | 309 canvas->save(); |
| 325 canvas->clipRect(gfx::RectToSkRect(content_rect)); | 310 canvas->clipRect(gfx::RectToSkRect(content_rect)); |
| 326 canvas->scale(contents_scale, contents_scale); | 311 canvas->scale(contents_scale, contents_scale); |
| 327 canvas->translate(layer_rect_.x(), layer_rect_.y()); | 312 canvas->translate(layer_rect_.x(), layer_rect_.y()); |
| 328 // Pictures by default have LCD text enabled. | |
| 329 if (!enable_lcd_text) { | |
| 330 disable_lcd_text_filter = skia::AdoptRef(new DisableLCDTextFilter); | |
| 331 canvas->setDrawFilter(disable_lcd_text_filter.get()); | |
| 332 } | |
| 333 picture_->draw(canvas, callback); | 313 picture_->draw(canvas, callback); |
| 334 SkIRect bounds; | 314 SkIRect bounds; |
| 335 canvas->getClipDeviceBounds(&bounds); | 315 canvas->getClipDeviceBounds(&bounds); |
| 336 canvas->restore(); | 316 canvas->restore(); |
| 337 TRACE_EVENT_END1("cc", "Picture::Raster", | 317 TRACE_EVENT_END1("cc", "Picture::Raster", |
| 338 "num_pixels_rasterized", bounds.width() * bounds.height()); | 318 "num_pixels_rasterized", bounds.width() * bounds.height()); |
| 339 } | 319 } |
| 340 | 320 |
| 341 scoped_ptr<Value> Picture::AsValue() const { | 321 scoped_ptr<Value> Picture::AsValue() const { |
| 342 SkDynamicMemoryWStream stream; | 322 SkDynamicMemoryWStream stream; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 raster_data->Set("picture_id", TracedValue::CreateIDRef(this).release()); | 448 raster_data->Set("picture_id", TracedValue::CreateIDRef(this).release()); |
| 469 raster_data->SetDouble("scale", scale); | 449 raster_data->SetDouble("scale", scale); |
| 470 raster_data->SetDouble("rect_x", rect.x()); | 450 raster_data->SetDouble("rect_x", rect.x()); |
| 471 raster_data->SetDouble("rect_y", rect.y()); | 451 raster_data->SetDouble("rect_y", rect.y()); |
| 472 raster_data->SetDouble("rect_width", rect.width()); | 452 raster_data->SetDouble("rect_width", rect.width()); |
| 473 raster_data->SetDouble("rect_height", rect.height()); | 453 raster_data->SetDouble("rect_height", rect.height()); |
| 474 return TracedValue::FromValue(raster_data.release()); | 454 return TracedValue::FromValue(raster_data.release()); |
| 475 } | 455 } |
| 476 | 456 |
| 477 } // namespace cc | 457 } // namespace cc |
| OLD | NEW |