Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit d51635f

Browse files
committed
[[ RefactorGraphics ]] Added in pass through of 'spread' control to graphics library.
[[ RefactorGraphics ]] Added computation of spread from radii to blur routine.
1 parent 166fe75 commit d51635f

5 files changed

Lines changed: 23 additions & 26 deletions

File tree

engine/src/graphicscontext.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ bool MCGraphicsContext::begin_with_effects(MCBitmapEffectsRef p_effects, const M
207207
t_effects . inner_glow . color = p_effects -> effects[kMCBitmapEffectTypeInnerGlow] . glow . color;
208208
t_effects . inner_glow . blend_mode = MCBitmapEffectBlendModeToMCGBlendMode((MCBitmapEffectBlendMode) p_effects -> effects[kMCBitmapEffectTypeInnerGlow] . glow . blend_mode);
209209
t_effects . inner_glow . size = (MCGFloat) p_effects -> effects[kMCBitmapEffectTypeInnerGlow] . glow . size;
210+
t_effects . inner_glow . spread = (MCGFloat) p_effects -> effects[kMCBitmapEffectTypeInnerGlow] . glow . spread / 255.0f;
210211
t_effects . inner_glow . inverted = p_effects -> effects[kMCBitmapEffectTypeInnerGlow] . glow . source == kMCBitmapEffectSourceEdge;
211212
}
212213
else
@@ -218,6 +219,7 @@ bool MCGraphicsContext::begin_with_effects(MCBitmapEffectsRef p_effects, const M
218219
t_effects . inner_shadow . color = p_effects -> effects[kMCBitmapEffectTypeInnerShadow] . shadow . color;
219220
t_effects . inner_shadow . blend_mode = MCBitmapEffectBlendModeToMCGBlendMode((MCBitmapEffectBlendMode) p_effects -> effects[kMCBitmapEffectTypeInnerShadow] . shadow . blend_mode);
220221
t_effects . inner_shadow . size = (MCGFloat) p_effects -> effects[kMCBitmapEffectTypeInnerShadow] . shadow . size;
222+
t_effects . inner_shadow . spread = (MCGFloat) p_effects -> effects[kMCBitmapEffectTypeInnerShadow] . shadow . spread / 255.0f;
221223

222224
MCGFloat t_x_offset, t_y_offset;
223225
MCGraphicsContextAngleAndDistanceToXYOffset(p_effects -> effects[kMCBitmapEffectTypeInnerShadow] . shadow . angle, p_effects -> effects[kMCBitmapEffectTypeInnerShadow] . shadow . distance,
@@ -234,6 +236,7 @@ bool MCGraphicsContext::begin_with_effects(MCBitmapEffectsRef p_effects, const M
234236
t_effects . outer_glow . color = p_effects -> effects[kMCBitmapEffectTypeOuterGlow] . glow . color;
235237
t_effects . outer_glow . blend_mode = MCBitmapEffectBlendModeToMCGBlendMode((MCBitmapEffectBlendMode) p_effects -> effects[kMCBitmapEffectTypeOuterGlow] . glow . blend_mode);
236238
t_effects . outer_glow . size = (MCGFloat) p_effects -> effects[kMCBitmapEffectTypeOuterGlow] . glow . size;
239+
t_effects . outer_glow . spread = (MCGFloat) p_effects -> effects[kMCBitmapEffectTypeOuterGlow] . glow . spread / 255.0f;
237240
}
238241
else
239242
t_effects . has_outer_glow = false;
@@ -244,6 +247,7 @@ bool MCGraphicsContext::begin_with_effects(MCBitmapEffectsRef p_effects, const M
244247
t_effects . drop_shadow . color = p_effects -> effects[kMCBitmapEffectTypeDropShadow] . shadow . color;
245248
t_effects . drop_shadow . blend_mode = MCBitmapEffectBlendModeToMCGBlendMode((MCBitmapEffectBlendMode) p_effects -> effects[kMCBitmapEffectTypeDropShadow] . shadow . blend_mode);
246249
t_effects . drop_shadow . size = (MCGFloat) p_effects -> effects[kMCBitmapEffectTypeDropShadow] . shadow . size;
250+
t_effects . drop_shadow . spread = (MCGFloat) p_effects -> effects[kMCBitmapEffectTypeDropShadow] . shadow . spread / 255.0f;
247251

248252
MCGFloat t_x_offset, t_y_offset;
249253
MCGraphicsContextAngleAndDistanceToXYOffset(p_effects -> effects[kMCBitmapEffectTypeDropShadow] . shadow . angle, p_effects -> effects[kMCBitmapEffectTypeDropShadow] . shadow . distance,

libgraphics/include/graphics.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ struct MCGShadowEffect
248248
MCGColor color;
249249
MCGBlendMode blend_mode;
250250
MCGFloat size;
251+
MCGFloat spread;
251252
MCGFloat x_offset;
252253
MCGFloat y_offset;
253254
bool knockout : 1;
@@ -258,6 +259,7 @@ struct MCGGlowEffect
258259
MCGColor color;
259260
MCGBlendMode blend_mode;
260261
MCGFloat size;
262+
MCGFloat spread;
261263
bool inverted : 1;
262264
};
263265

libgraphics/src/blur.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,14 +356,14 @@ static void get_adjusted_radii(SkScalar passRadius, int *loRadius, int *hiRadius
356356
// radius -= p1_radius
357357
// pass 2 is (radius + (3 - 2 - 1)) / (3 - 2) = (radius + 0) / 1 (3)
358358

359-
bool MCGBlurBox(const SkMask& p_src, SkScalar p_x_radius, SkScalar p_y_radius, SkScalar p_spread, SkMask& r_dst)
359+
bool MCGBlurBox(const SkMask& p_src, SkScalar p_x_radius, SkScalar p_y_radius, SkScalar p_x_spread, SkScalar p_y_spread, SkMask& r_dst)
360360
{
361361
int t_pass_count;
362362
t_pass_count = 3;
363363

364364
int x_spread, y_spread;
365-
x_spread = SkScalarFloor(p_x_radius * p_spread);
366-
y_spread = SkScalarFloor(p_y_radius * p_spread);
365+
x_spread = SkScalarFloor(p_x_radius * p_x_spread);
366+
y_spread = SkScalarFloor(p_y_radius * p_y_spread);
367367

368368
p_x_radius -= x_spread;
369369
p_y_radius -= y_spread;

libgraphics/src/context.cpp

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,7 @@ void MCGContextBegin(MCGContextRef self, bool p_need_layer)
680680
self -> layer = t_new_layer;
681681
}
682682

683+
#if 0
683684
static MCGIRectangle compute_glow_clip(const MCGGlowEffect& self, const MCGIRectangle& p_shape, const MCGIRectangle& p_clip, const MCGAffineTransform& p_transform)
684685
{
685686
MCGSize t_radii;
@@ -716,6 +717,7 @@ static MCGIRectangle compute_shadow_clip(const MCGShadowEffect& self, const MCGI
716717
MCGIRectangleOffset(p_clip, -ceil(t_transformed_offset . width), -ceil(t_transformed_offset . height)))),
717718
ceil(t_transformed_radii . width), ceil(t_transformed_radii . height));
718719
}
720+
#endif
719721

720722
// The 'shape' parameter is the rectangle in user-space of the area to which the effect
721723
// is to be applied.
@@ -806,8 +808,8 @@ void MCGContextBeginWithEffects(MCGContextRef self, MCGRectangle p_shape, const
806808
}
807809

808810
// Next process outer glow.
809-
// We expand the shape by the radii.
810-
// We then intersect with the device clip to see what is needed.
811+
// We intersect the shape with the clip to determine visible pixels
812+
// We then expand by the radii.
811813
// We then intersect with the device shape to restrict to renderable pixels.
812814
// Finally we add this rectangle to the layer clip (union).
813815
if (p_effects . has_outer_glow)
@@ -819,11 +821,9 @@ void MCGContextBeginWithEffects(MCGContextRef self, MCGRectangle p_shape, const
819821
t_layer_clip,
820822
MCGIRectangleIntersect(
821823
t_device_shape,
822-
MCGIRectangleIntersect(
823-
t_device_clip,
824-
MCGIRectangleExpand(
825-
t_device_shape,
826-
ceil(t_radii . width), ceil(t_radii . height)))));
824+
MCGIRectangleExpand(
825+
MCGIRectangleIntersect(t_device_shape, t_device_clip),
826+
ceil(t_radii . width), ceil(t_radii . height))));
827827
}
828828

829829
// Next process inner glow.
@@ -844,16 +844,7 @@ void MCGContextBeginWithEffects(MCGContextRef self, MCGRectangle p_shape, const
844844
MCGIRectangleIntersect(t_device_clip, t_device_shape),
845845
ceil(t_radii . width), ceil(t_radii . height))));
846846
}
847-
848-
/*if (p_effects . has_drop_shadow)
849-
t_layer_clip = MCGIRectangleUnion(t_layer_clip, compute_shadow_clip(p_effects . drop_shadow, t_device_shape, t_device_clip, t_device_transform));
850-
if (p_effects . has_inner_shadow)
851-
t_layer_clip = MCGIRectangleUnion(t_layer_clip, compute_shadow_clip(p_effects . inner_shadow, t_device_shape, t_device_clip, t_device_transform));
852-
if (p_effects . has_outer_glow)
853-
t_layer_clip = MCGIRectangleUnion(t_layer_clip, compute_glow_clip(p_effects . outer_glow, t_device_shape, t_device_clip, t_device_transform));
854-
if (p_effects . has_inner_glow)
855-
t_layer_clip = MCGIRectangleUnion(t_layer_clip, compute_glow_clip(p_effects . inner_glow, t_device_shape, t_device_clip, t_device_transform));*/
856-
847+
857848
t_layer_clip = MCGIRectangleIntersect(t_layer_clip, t_device_shape);
858849

859850
// Create a suitable bitmap.
@@ -1057,7 +1048,7 @@ static void MCGContextRenderEffect(MCGContextRef self, const SkMask& p_mask, MCG
10571048

10581049
// Now blur the mask.
10591050
SkMask t_blurred_mask;
1060-
if (!MCGBlurBox(p_mask, t_transformed_radii . width, t_transformed_radii . height, 1.0, t_blurred_mask))
1051+
if (!MCGBlurBox(p_mask, t_transformed_radii . width, t_transformed_radii . height, p_spread, p_spread, t_blurred_mask))
10611052
return;
10621053

10631054
// Offset the blur mask appropriately.
@@ -1218,7 +1209,7 @@ static void MCGContextRenderEffects(MCGContextRef self, MCGContextLayerRef p_chi
12181209
t_child_mask,
12191210
MCGSizeMake(p_effects . drop_shadow . size, p_effects . drop_shadow . size),
12201211
MCGSizeMake(p_effects . drop_shadow . x_offset, p_effects . drop_shadow . y_offset),
1221-
/*p_effects . outer_glow . spread*/ 0.0,
1212+
p_effects . drop_shadow . spread,
12221213
p_effects . drop_shadow . knockout ? kMCGBlurTypeOuter : kMCGBlurTypeNormal,
12231214
p_effects . drop_shadow . color,
12241215
p_effects . drop_shadow . blend_mode);
@@ -1228,7 +1219,7 @@ static void MCGContextRenderEffects(MCGContextRef self, MCGContextLayerRef p_chi
12281219
t_child_mask,
12291220
MCGSizeMake(p_effects . outer_glow . size, p_effects . outer_glow . size),
12301221
MCGSizeMake(0.0, 0.0),
1231-
/*p_effects . outer_glow . spread*/ 0.0,
1222+
p_effects . outer_glow . spread,
12321223
kMCGBlurTypeNormal,
12331224
p_effects . outer_glow . color,
12341225
p_effects . outer_glow . blend_mode);
@@ -1243,7 +1234,7 @@ static void MCGContextRenderEffects(MCGContextRef self, MCGContextLayerRef p_chi
12431234
t_child_mask,
12441235
MCGSizeMake(p_effects . inner_shadow . size, p_effects . inner_shadow . size),
12451236
MCGSizeMake(p_effects . inner_shadow . x_offset, p_effects . inner_shadow . y_offset),
1246-
/*p_effects . inner_shadow . spread*/ 0.0,
1237+
p_effects . inner_shadow . spread,
12471238
kMCGBlurTypeInvertedInner,
12481239
p_effects . inner_shadow . color,
12491240
p_effects . inner_shadow . blend_mode);
@@ -1253,7 +1244,7 @@ static void MCGContextRenderEffects(MCGContextRef self, MCGContextLayerRef p_chi
12531244
t_child_mask,
12541245
MCGSizeMake(p_effects . inner_glow . size, p_effects . inner_glow . size),
12551246
MCGSizeMake(0.0, 0.0),
1256-
/*p_effects . inner_shadow . spread*/ 0.0,
1247+
p_effects . inner_glow . spread,
12571248
p_effects . inner_glow . inverted ? kMCGBlurTypeInvertedInner : kMCGBlurTypeInner,
12581249
p_effects . inner_glow . color,
12591250
p_effects . inner_glow . blend_mode);

libgraphics/src/graphics-internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ enum MCGBlurType
420420
kMCGBlurTypeOuter,
421421
};
422422

423-
bool MCGBlurBox(const SkMask& p_src, SkScalar p_x_radius, SkScalar p_y_radius, SkScalar p_spread, SkMask& r_dst);
423+
bool MCGBlurBox(const SkMask& p_src, SkScalar p_x_radius, SkScalar p_y_radius, SkScalar p_x_spread, SkScalar p_y_spread, SkMask& r_dst);
424424

425425
////////////////////////////////////////////////////////////////////////////////
426426

0 commit comments

Comments
 (0)