1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/core/SkDrawLooper.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,61 @@ 1.4 +/* 1.5 + * Copyright 2013 Google Inc. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license that can be 1.8 + * found in the LICENSE file. 1.9 + */ 1.10 + 1.11 +#include "SkDrawLooper.h" 1.12 +#include "SkCanvas.h" 1.13 +#include "SkMatrix.h" 1.14 +#include "SkPaint.h" 1.15 +#include "SkRect.h" 1.16 +#include "SkSmallAllocator.h" 1.17 + 1.18 +bool SkDrawLooper::canComputeFastBounds(const SkPaint& paint) const { 1.19 + SkCanvas canvas; 1.20 + SkSmallAllocator<1, 32> allocator; 1.21 + void* buffer = allocator.reserveT<SkDrawLooper::Context>(this->contextSize()); 1.22 + 1.23 + SkDrawLooper::Context* context = this->createContext(&canvas, buffer); 1.24 + for (;;) { 1.25 + SkPaint p(paint); 1.26 + if (context->next(&canvas, &p)) { 1.27 + p.setLooper(NULL); 1.28 + if (!p.canComputeFastBounds()) { 1.29 + return false; 1.30 + } 1.31 + } else { 1.32 + break; 1.33 + } 1.34 + } 1.35 + return true; 1.36 +} 1.37 + 1.38 +void SkDrawLooper::computeFastBounds(const SkPaint& paint, const SkRect& src, 1.39 + SkRect* dst) const { 1.40 + SkCanvas canvas; 1.41 + SkSmallAllocator<1, 32> allocator; 1.42 + void* buffer = allocator.reserveT<SkDrawLooper::Context>(this->contextSize()); 1.43 + 1.44 + *dst = src; // catch case where there are no loops 1.45 + SkDrawLooper::Context* context = this->createContext(&canvas, buffer); 1.46 + for (bool firstTime = true;; firstTime = false) { 1.47 + SkPaint p(paint); 1.48 + if (context->next(&canvas, &p)) { 1.49 + SkRect r(src); 1.50 + 1.51 + p.setLooper(NULL); 1.52 + p.computeFastBounds(r, &r); 1.53 + canvas.getTotalMatrix().mapRect(&r); 1.54 + 1.55 + if (firstTime) { 1.56 + *dst = r; 1.57 + } else { 1.58 + dst->join(r); 1.59 + } 1.60 + } else { 1.61 + break; 1.62 + } 1.63 + } 1.64 +}