Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright 2013 Google Inc. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 5 | * found in the LICENSE file. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | #include "SkDrawLooper.h" |
michael@0 | 9 | #include "SkCanvas.h" |
michael@0 | 10 | #include "SkMatrix.h" |
michael@0 | 11 | #include "SkPaint.h" |
michael@0 | 12 | #include "SkRect.h" |
michael@0 | 13 | #include "SkSmallAllocator.h" |
michael@0 | 14 | |
michael@0 | 15 | bool SkDrawLooper::canComputeFastBounds(const SkPaint& paint) const { |
michael@0 | 16 | SkCanvas canvas; |
michael@0 | 17 | SkSmallAllocator<1, 32> allocator; |
michael@0 | 18 | void* buffer = allocator.reserveT<SkDrawLooper::Context>(this->contextSize()); |
michael@0 | 19 | |
michael@0 | 20 | SkDrawLooper::Context* context = this->createContext(&canvas, buffer); |
michael@0 | 21 | for (;;) { |
michael@0 | 22 | SkPaint p(paint); |
michael@0 | 23 | if (context->next(&canvas, &p)) { |
michael@0 | 24 | p.setLooper(NULL); |
michael@0 | 25 | if (!p.canComputeFastBounds()) { |
michael@0 | 26 | return false; |
michael@0 | 27 | } |
michael@0 | 28 | } else { |
michael@0 | 29 | break; |
michael@0 | 30 | } |
michael@0 | 31 | } |
michael@0 | 32 | return true; |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | void SkDrawLooper::computeFastBounds(const SkPaint& paint, const SkRect& src, |
michael@0 | 36 | SkRect* dst) const { |
michael@0 | 37 | SkCanvas canvas; |
michael@0 | 38 | SkSmallAllocator<1, 32> allocator; |
michael@0 | 39 | void* buffer = allocator.reserveT<SkDrawLooper::Context>(this->contextSize()); |
michael@0 | 40 | |
michael@0 | 41 | *dst = src; // catch case where there are no loops |
michael@0 | 42 | SkDrawLooper::Context* context = this->createContext(&canvas, buffer); |
michael@0 | 43 | for (bool firstTime = true;; firstTime = false) { |
michael@0 | 44 | SkPaint p(paint); |
michael@0 | 45 | if (context->next(&canvas, &p)) { |
michael@0 | 46 | SkRect r(src); |
michael@0 | 47 | |
michael@0 | 48 | p.setLooper(NULL); |
michael@0 | 49 | p.computeFastBounds(r, &r); |
michael@0 | 50 | canvas.getTotalMatrix().mapRect(&r); |
michael@0 | 51 | |
michael@0 | 52 | if (firstTime) { |
michael@0 | 53 | *dst = r; |
michael@0 | 54 | } else { |
michael@0 | 55 | dst->join(r); |
michael@0 | 56 | } |
michael@0 | 57 | } else { |
michael@0 | 58 | break; |
michael@0 | 59 | } |
michael@0 | 60 | } |
michael@0 | 61 | } |