mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Canvas.drawShadow API based on SkShadowUtils::drawShadow (flutter/engine#3486)
This commit is contained in:
parent
7143d8d1d9
commit
6daf9aeefd
@ -50,16 +50,8 @@ void PhysicalModelLayer::Paint(PaintContext& context) {
|
||||
path.addRRect(rrect_);
|
||||
|
||||
if (elevation_ != 0) {
|
||||
SkShadowFlags flags = SkColorGetA(color_) == 0xff ?
|
||||
SkShadowFlags::kNone_ShadowFlag :
|
||||
SkShadowFlags::kTransparentOccluder_ShadowFlag;
|
||||
SkShadowUtils::DrawShadow(&context.canvas, path,
|
||||
elevation_ * 4,
|
||||
SkPoint3::Make(0.0f, -700.0f, 2800.0f),
|
||||
2800.0f,
|
||||
0.25f, 0.25f,
|
||||
SK_ColorBLACK,
|
||||
flags);
|
||||
DrawShadow(&context.canvas, path, SK_ColorBLACK, elevation_,
|
||||
SkColorGetA(color_) != 0xff);
|
||||
}
|
||||
|
||||
if (needs_system_composite())
|
||||
@ -79,4 +71,19 @@ void PhysicalModelLayer::Paint(PaintContext& context) {
|
||||
PaintChildren(context);
|
||||
}
|
||||
|
||||
void PhysicalModelLayer::DrawShadow(SkCanvas* canvas, const SkPath& path,
|
||||
SkColor color, int elevation,
|
||||
bool transparentOccluder) {
|
||||
SkShadowFlags flags = transparentOccluder ?
|
||||
SkShadowFlags::kTransparentOccluder_ShadowFlag :
|
||||
SkShadowFlags::kNone_ShadowFlag;
|
||||
SkShadowUtils::DrawShadow(canvas, path,
|
||||
elevation * 4,
|
||||
SkPoint3::Make(0.0f, -700.0f, 2800.0f),
|
||||
2800.0f,
|
||||
0.25f, 0.25f,
|
||||
color,
|
||||
flags);
|
||||
}
|
||||
|
||||
} // namespace flow
|
||||
|
||||
@ -18,6 +18,9 @@ class PhysicalModelLayer : public ContainerLayer {
|
||||
void set_elevation(int elevation) { elevation_ = elevation; }
|
||||
void set_color(SkColor color) { color_ = color; }
|
||||
|
||||
static void DrawShadow(SkCanvas* canvas, const SkPath& path,
|
||||
SkColor color, int elevation, bool transparentOccluder);
|
||||
|
||||
protected:
|
||||
void Preroll(PrerollContext* context, const SkMatrix& matrix) override;
|
||||
void Paint(PaintContext& context) override;
|
||||
|
||||
@ -1548,6 +1548,18 @@ class Canvas extends NativeFieldWrapperClass2 {
|
||||
Int32List colors,
|
||||
int blendMode,
|
||||
Float32List cullRect) native "Canvas_drawAtlas";
|
||||
|
||||
/// Draws a shadow for a [Path] representing the given material elevation.
|
||||
///
|
||||
/// transparentOccluder should be true if the occluding object is not opaque.
|
||||
void drawShadow(Path path, Color color, int elevation, bool transparentOccluder) {
|
||||
_drawShadow(path, color.value, elevation, transparentOccluder);
|
||||
}
|
||||
|
||||
void _drawShadow(Path path,
|
||||
int color,
|
||||
int elevation,
|
||||
bool transparentOccluder) native "Canvas_drawShadow";
|
||||
}
|
||||
|
||||
/// An object representing a sequence of recorded graphical operations.
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "flutter/flow/layers/physical_model_layer.h"
|
||||
#include "flutter/lib/ui/painting/image.h"
|
||||
#include "flutter/lib/ui/painting/matrix.h"
|
||||
#include "lib/tonic/converter/dart_converter.h"
|
||||
@ -53,7 +54,8 @@ IMPLEMENT_WRAPPERTYPEINFO(ui, Canvas);
|
||||
V(Canvas, drawPicture) \
|
||||
V(Canvas, drawPoints) \
|
||||
V(Canvas, drawVertices) \
|
||||
V(Canvas, drawAtlas)
|
||||
V(Canvas, drawAtlas) \
|
||||
V(Canvas, drawShadow)
|
||||
|
||||
FOR_EACH_BINDING(DART_NATIVE_CALLBACK)
|
||||
|
||||
@ -395,6 +397,17 @@ void Canvas::drawAtlas(const Paint& paint,
|
||||
paint.paint());
|
||||
}
|
||||
|
||||
void Canvas::drawShadow(const CanvasPath* path,
|
||||
SkColor color,
|
||||
int elevation,
|
||||
bool transparentOccluder) {
|
||||
flow::PhysicalModelLayer::DrawShadow(canvas_,
|
||||
path->path(),
|
||||
color,
|
||||
elevation,
|
||||
transparentOccluder);
|
||||
}
|
||||
|
||||
void Canvas::Clear() {
|
||||
canvas_ = nullptr;
|
||||
}
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
#include "lib/tonic/typed_data/float64_list.h"
|
||||
#include "lib/tonic/typed_data/int32_list.h"
|
||||
#include "third_party/skia/include/core/SkCanvas.h"
|
||||
#include "third_party/skia/include/utils/SkShadowUtils.h"
|
||||
|
||||
namespace tonic {
|
||||
class DartLibraryNatives;
|
||||
@ -159,6 +160,11 @@ class Canvas : public ftl::RefCountedThreadSafe<Canvas>,
|
||||
SkBlendMode blend_mode,
|
||||
const tonic::Float32List& cull_rect);
|
||||
|
||||
void drawShadow(const CanvasPath* path,
|
||||
SkColor color,
|
||||
int elevation,
|
||||
bool transparentOccluder);
|
||||
|
||||
SkCanvas* canvas() const { return canvas_; }
|
||||
void Clear();
|
||||
bool IsRecording() const;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user