1/* 2 * Copyright 2018 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8in fragmentProcessor src; 9layout(ctype=SkIRect) in int4 bounds; 10uniform float4 boundsUniform; 11layout(ctype=SkRect) in float4 srcRect; 12in uniform float xInvZoom; 13in uniform float yInvZoom; 14in uniform float xInvInset; 15in uniform float yInvInset; 16 17uniform half2 offset; 18 19half4 main(float2 coord) { 20 float2 zoom_coord = offset + coord * float2(xInvZoom, yInvZoom); 21 float2 delta = (coord - boundsUniform.xy) * boundsUniform.zw; 22 delta = min(delta, float2(1.0) - delta); 23 delta *= float2(xInvInset, yInvInset); 24 25 float weight = 0.0; 26 if (delta.s < 2.0 && delta.t < 2.0) { 27 delta = float2(2.0) - delta; 28 float dist = length(delta); 29 dist = max(2.0 - dist, 0.0); 30 weight = min(dist * dist, 1.0); 31 } else { 32 float2 delta_squared = delta * delta; 33 weight = min(min(delta_squared.x, delta_squared.y), 1.0); 34 } 35 36 return sample(src, mix(coord, zoom_coord, weight)); 37} 38 39@setData(pdman) { 40 pdman.set2f(offset, srcRect.x(), srcRect.y()); 41 pdman.set4f(boundsUniform, bounds.x(), bounds.y(), 1.f/ bounds.width(), 1.f / bounds.height()); 42} 43 44@test(d) { 45 const int kMaxWidth = 200; 46 const int kMaxHeight = 200; 47 const SkScalar kMaxInset = 20.0f; 48 uint32_t width = d->fRandom->nextULessThan(kMaxWidth); 49 uint32_t height = d->fRandom->nextULessThan(kMaxHeight); 50 SkScalar inset = d->fRandom->nextRangeScalar(1.0f, kMaxInset); 51 52 SkIRect bounds = SkIRect::MakeWH(SkIntToScalar(kMaxWidth), SkIntToScalar(kMaxHeight)); 53 SkRect srcRect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)); 54 55 auto src = GrProcessorUnitTest::MakeChildFP(d); 56 auto effect = GrMagnifierEffect::Make(std::move(src), 57 bounds, 58 srcRect, 59 srcRect.width() / bounds.width(), 60 srcRect.height() / bounds.height(), 61 bounds.width() / inset, 62 bounds.height() / inset); 63 SkASSERT(effect); 64 return effect; 65} 66