OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "skia/ext/pixel_ref_utils.h" | 5 #include "skia/ext/pixel_ref_utils.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "third_party/skia/include/core/SkBitmapDevice.h" | 9 #include "third_party/skia/include/core/SkBitmapDevice.h" |
10 #include "third_party/skia/include/core/SkCanvas.h" | 10 #include "third_party/skia/include/core/SkCanvas.h" |
11 #include "third_party/skia/include/core/SkData.h" | 11 #include "third_party/skia/include/core/SkData.h" |
12 #include "third_party/skia/include/core/SkDraw.h" | 12 #include "third_party/skia/include/core/SkDraw.h" |
13 #include "third_party/skia/include/core/SkPixelRef.h" | 13 #include "third_party/skia/include/core/SkPixelRef.h" |
14 #include "third_party/skia/include/core/SkRRect.h" | 14 #include "third_party/skia/include/core/SkRRect.h" |
15 #include "third_party/skia/include/core/SkRect.h" | 15 #include "third_party/skia/include/core/SkRect.h" |
16 #include "third_party/skia/include/core/SkShader.h" | 16 #include "third_party/skia/include/core/SkShader.h" |
| 17 #include "third_party/skia/include/utils/SkNoSaveLayerCanvas.h" |
17 #include "third_party/skia/src/core/SkRasterClip.h" | 18 #include "third_party/skia/src/core/SkRasterClip.h" |
18 | 19 |
19 namespace skia { | 20 namespace skia { |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 // URI label for a discardable SkPixelRef. | 24 // URI label for a discardable SkPixelRef. |
24 const char kLabelDiscardable[] = "discardable"; | 25 const char kLabelDiscardable[] = "discardable"; |
25 | 26 |
26 class DiscardablePixelRefSet { | 27 class DiscardablePixelRefSet { |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 if (shader) { | 343 if (shader) { |
343 // Check whether the shader is a gradient in order to prevent generation | 344 // Check whether the shader is a gradient in order to prevent generation |
344 // of bitmaps from gradient shaders, which implement asABitmap. | 345 // of bitmaps from gradient shaders, which implement asABitmap. |
345 if (SkShader::kNone_GradientType == shader->asAGradient(NULL)) | 346 if (SkShader::kNone_GradientType == shader->asAGradient(NULL)) |
346 return shader->asABitmap(bm, NULL, NULL); | 347 return shader->asABitmap(bm, NULL, NULL); |
347 } | 348 } |
348 return false; | 349 return false; |
349 } | 350 } |
350 }; | 351 }; |
351 | 352 |
352 class NoSaveLayerCanvas : public SkCanvas { | |
353 public: | |
354 NoSaveLayerCanvas(SkBaseDevice* device) : INHERITED(device) {} | |
355 | |
356 protected: | |
357 // Turn saveLayer() into save() for speed, should not affect correctness. | |
358 virtual SaveLayerStrategy willSaveLayer(const SkRect* bounds, | |
359 const SkPaint* paint, | |
360 SaveFlags flags) SK_OVERRIDE { | |
361 this->INHERITED::willSaveLayer(bounds, paint, flags); | |
362 return kNoLayer_SaveLayerStrategy; | |
363 } | |
364 | |
365 // Disable aa for speed. | |
366 virtual void onClipRect(const SkRect& rect, | |
367 SkRegion::Op op, | |
368 ClipEdgeStyle edge_style) SK_OVERRIDE { | |
369 this->INHERITED::onClipRect(rect, op, kHard_ClipEdgeStyle); | |
370 } | |
371 | |
372 virtual void onClipPath(const SkPath& path, | |
373 SkRegion::Op op, | |
374 ClipEdgeStyle edge_style) SK_OVERRIDE { | |
375 this->updateClipConservativelyUsingBounds(path.getBounds(), op, | |
376 path.isInverseFillType()); | |
377 } | |
378 virtual void onClipRRect(const SkRRect& rrect, | |
379 SkRegion::Op op, | |
380 ClipEdgeStyle edge_style) SK_OVERRIDE { | |
381 this->updateClipConservativelyUsingBounds(rrect.getBounds(), op, false); | |
382 } | |
383 | |
384 private: | |
385 typedef SkCanvas INHERITED; | |
386 }; | |
387 | |
388 } // namespace | 353 } // namespace |
389 | 354 |
390 void PixelRefUtils::GatherDiscardablePixelRefs( | 355 void PixelRefUtils::GatherDiscardablePixelRefs( |
391 SkPicture* picture, | 356 SkPicture* picture, |
392 std::vector<PositionPixelRef>* pixel_refs) { | 357 std::vector<PositionPixelRef>* pixel_refs) { |
393 pixel_refs->clear(); | 358 pixel_refs->clear(); |
394 DiscardablePixelRefSet pixel_ref_set(pixel_refs); | 359 DiscardablePixelRefSet pixel_ref_set(pixel_refs); |
395 | 360 |
396 SkBitmap empty_bitmap; | 361 SkBitmap empty_bitmap; |
397 empty_bitmap.setConfig( | 362 empty_bitmap.setConfig( |
398 SkBitmap::kNo_Config, picture->width(), picture->height()); | 363 SkBitmap::kNo_Config, picture->width(), picture->height()); |
399 | 364 |
400 GatherPixelRefDevice device(empty_bitmap, &pixel_ref_set); | 365 GatherPixelRefDevice device(empty_bitmap, &pixel_ref_set); |
401 NoSaveLayerCanvas canvas(&device); | 366 SkNoSaveLayerCanvas canvas(&device); |
402 | 367 |
403 canvas.clipRect(SkRect::MakeWH(picture->width(), picture->height()), | 368 canvas.clipRect(SkRect::MakeWH(picture->width(), picture->height()), |
404 SkRegion::kIntersect_Op, | 369 SkRegion::kIntersect_Op, |
405 false); | 370 false); |
406 canvas.drawPicture(*picture); | 371 canvas.drawPicture(*picture); |
407 } | 372 } |
408 | 373 |
409 } // namespace skia | 374 } // namespace skia |
OLD | NEW |