提交 1a07d29d 编写于 作者: M Matt Perry

Sky: Add a DrawLooper interface to the painting API to be used for shadows.

R=abarth@chromium.org

Review URL: https://codereview.chromium.org/1144193006
上级 f8919855
......@@ -42,10 +42,6 @@ Constructor
ConstructorCallWith=ExecutionContext|Document
Custom=|Getter|Setter|VisitDOMWrapper|Wrap|PropertyGetter|PropertyEnumerator|PropertyQuery
CustomConstructor
# Sky addition: if present, the IDL compiler will generate a private Dart
# interface to be extended by an auxilary file <Interface>.dart next to
# <Interface>.idl.
CustomDart
CustomElementCallbacks
Default=Undefined
DependentLifetime
......
......@@ -837,6 +837,14 @@ sky_core_files = [
"painting/Canvas.h",
"painting/CanvasPath.cpp",
"painting/CanvasPath.h",
"painting/DrawLooper.cpp",
"painting/DrawLooper.h",
"painting/DrawLooperAddLayerCallback.cpp",
"painting/DrawLooperAddLayerCallback.h",
"painting/DrawLooperLayerInfo.cpp",
"painting/DrawLooperLayerInfo.h",
"painting/LayerDrawLooperBuilder.cpp",
"painting/LayerDrawLooperBuilder.h",
"painting/LayoutRoot.cpp",
"painting/LayoutRoot.h",
"painting/Paint.cpp",
......@@ -1112,6 +1120,10 @@ core_idl_files = get_path_info([
"html/VoidCallback.idl",
"layout/LayoutCallback.idl",
"painting/Canvas.idl",
"painting/DrawLooper.idl",
"painting/DrawLooperAddLayerCallback.idl",
"painting/DrawLooperLayerInfo.idl",
"painting/LayerDrawLooperBuilder.idl",
"painting/LayoutRoot.idl",
"painting/Paint.idl",
"painting/PaintingCallback.idl",
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/engine/config.h"
#include "sky/engine/core/painting/DrawLooper.h"
namespace blink {
DrawLooper::DrawLooper(PassRefPtr<SkDrawLooper> looper)
: looper_(looper) {
}
DrawLooper::~DrawLooper() {
}
} // namespace blink
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SKY_ENGINE_CORE_PAINTING_DRAWLOOPER_H_
#define SKY_ENGINE_CORE_PAINTING_DRAWLOOPER_H_
#include "sky/engine/tonic/dart_wrappable.h"
#include "sky/engine/wtf/PassRefPtr.h"
#include "sky/engine/wtf/RefCounted.h"
#include "third_party/skia/include/core/SkDrawLooper.h"
namespace blink {
class DrawLooper : public RefCounted<DrawLooper>, public DartWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
~DrawLooper() override;
static PassRefPtr<DrawLooper> create(PassRefPtr<SkDrawLooper> looper) {
return adoptRef(new DrawLooper(looper));
}
SkDrawLooper* looper() { return looper_.get(); }
private:
DrawLooper(PassRefPtr<SkDrawLooper> looper);
RefPtr<SkDrawLooper> looper_;
};
} // namespace blink
#endif // SKY_ENGINE_CORE_PAINTING_DRAWLOOPER_H_
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
interface DrawLooper {
};
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/engine/config.h"
#include "sky/engine/core/painting/DrawLooperAddLayerCallback.h"
namespace blink {
DrawLooperAddLayerCallback::~DrawLooperAddLayerCallback() {
}
} // namespace blink
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SKY_ENGINE_CORE_PAINTING_DRAWLOOPERADDLAYERCALLBACK_H_
#define SKY_ENGINE_CORE_PAINTING_DRAWLOOPERADDLAYERCALLBACK_H_
namespace blink {
class Paint;
class DrawLooperAddLayerCallback {
public:
virtual ~DrawLooperAddLayerCallback();
virtual void handleEvent(Paint* context) = 0;
};
} // namespace blink
#endif // SKY_ENGINE_CORE_PAINTING_DRAWLOOPERADDLAYERCALLBACK_H_
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
callback interface DrawLooperAddLayerCallback {
void handleEvent(Paint paint);
};
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/engine/config.h"
#include "sky/engine/core/painting/DrawLooperLayerInfo.h"
namespace blink {
DrawLooperLayerInfo::DrawLooperLayerInfo() {
}
DrawLooperLayerInfo::~DrawLooperLayerInfo() {
}
} // namespace blink
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SKY_ENGINE_CORE_PAINTING_DRAWLOOPERLAYERINFO_H_
#define SKY_ENGINE_CORE_PAINTING_DRAWLOOPERLAYERINFO_H_
#include "dart/runtime/include/dart_api.h"
#include "sky/engine/tonic/dart_wrappable.h"
#include "third_party/skia/include/effects/SkLayerDrawLooper.h"
namespace blink {
class DrawLooperLayerInfo : public RefCounted<DrawLooperLayerInfo>,
public DartWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
static PassRefPtr<DrawLooperLayerInfo> create()
{
return adoptRef(new DrawLooperLayerInfo);
}
~DrawLooperLayerInfo() override;
void setPaintBits(unsigned bits) { layer_info_.fPaintBits = bits; }
void setColorMode(unsigned mode) {
layer_info_.fColorMode = static_cast<SkXfermode::Mode>(mode);
}
void setOffset(float x, float y) { layer_info_.fOffset.set(x, y); }
void setPostTranslate(bool val) { layer_info_.fPostTranslate = val; }
const SkLayerDrawLooper::LayerInfo& layer_info() const { return layer_info_; }
private:
DrawLooperLayerInfo();
SkLayerDrawLooper::LayerInfo layer_info_;
};
} // namespace blink
#endif // SKY_ENGINE_CORE_PAINTING_DRAWLOOPERLAYERINFO_H_
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
[
Constructor(),
] interface DrawLooperLayerInfo {
// Bits specifies which aspects of the layer's paint should replace the
// corresponding aspects on the draw's paint.
// ENTIRE_PAINT_BITS means use the layer's paint completely.
// 0 means ignore the layer's paint... except for colorMode, which is
// always applied.
// TODO(mpcomplete): maybe these should each be functions (e.g. useStyle()).
// TODO(mpcomplete): the IDL compiler doesn't use these for anything?
const unsigned long STYLE_BIT = 0x1;
const unsigned long TEXT_SKEWX_BIT = 0x2;
const unsigned long PATH_EFFECT_BIT = 0x4;
const unsigned long MASK_FILTER_BIT = 0x8;
const unsigned long SHADER_BIT = 0x10;
const unsigned long COLOR_FILTER_BIT = 0x20;
const unsigned long XFERMODE_BIT = 0x40;
const unsigned long ENTIRE_PAINT_BITS = -1;
void setPaintBits(unsigned long bits);
// TODO(mpcomplete): use SkXfermode::Mode.
void setColorMode(unsigned long mode);
// TODO(mpcomplete): use Point.
void setOffset(float x, float y);
void setPostTranslate(boolean postTranslate);
};
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/engine/config.h"
#include "sky/engine/core/painting/LayerDrawLooperBuilder.h"
#include "sky/engine/core/painting/DrawLooper.h"
#include "sky/engine/core/painting/DrawLooperAddLayerCallback.h"
#include "sky/engine/core/painting/DrawLooperLayerInfo.h"
#include "sky/engine/core/painting/Paint.h"
#include "third_party/skia/include/core/SkColorFilter.h"
namespace blink {
LayerDrawLooperBuilder::LayerDrawLooperBuilder() {
}
LayerDrawLooperBuilder::~LayerDrawLooperBuilder() {
}
PassRefPtr<DrawLooper> LayerDrawLooperBuilder::build() {
return DrawLooper::create(adoptRef(draw_looper_builder_.detachLooper()));
}
void LayerDrawLooperBuilder::addLayerOnTop(
DrawLooperLayerInfo* layer_info,
PassOwnPtr<DrawLooperAddLayerCallback> callback) {
SkPaint* sk_paint =
draw_looper_builder_.addLayerOnTop(layer_info->layer_info());
RefPtr<Paint> paint = Paint::create();
paint->setPaint(*sk_paint);
callback->handleEvent(paint.get());
*sk_paint = paint->paint();
// TODO(mpcomplete): Remove this when we add color filter support to Paint's
// API.
SkColor skColor = sk_paint->getColor();
RefPtr<SkColorFilter> cf = adoptRef(
SkColorFilter::CreateModeFilter(skColor, SkXfermode::kSrcIn_Mode));
sk_paint->setColorFilter(cf.get());
}
} // namespace blink
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SKY_ENGINE_CORE_PAINTING_LAYERDRAWLOOPERBUILDER_H_
#define SKY_ENGINE_CORE_PAINTING_LAYERDRAWLOOPERBUILDER_H_
#include "sky/engine/tonic/dart_wrappable.h"
#include "sky/engine/wtf/PassRefPtr.h"
#include "sky/engine/wtf/RefCounted.h"
#include "third_party/skia/include/effects/SkLayerDrawLooper.h"
namespace blink {
class DrawLooper;
class DrawLooperAddLayerCallback;
class DrawLooperLayerInfo;
class LayerDrawLooperBuilder : public RefCounted<LayerDrawLooperBuilder>,
public DartWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
~LayerDrawLooperBuilder() override;
static PassRefPtr<LayerDrawLooperBuilder> create() {
return adoptRef(new LayerDrawLooperBuilder);
}
PassRefPtr<DrawLooper> build();
void addLayerOnTop(DrawLooperLayerInfo* layer_info,
PassOwnPtr<DrawLooperAddLayerCallback>);
private:
LayerDrawLooperBuilder();
SkLayerDrawLooper::Builder draw_looper_builder_;
};
} // namespace blink
#endif // SKY_ENGINE_CORE_PAINTING_LAYERDRAWLOOPERBUILDER_H_
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
[
Constructor()
] interface LayerDrawLooperBuilder {
// Returns a DrawLooper based on the construction operations, and resets the
// builder back to a default state.
DrawLooper build();
void addLayerOnTop(DrawLooperLayerInfo info, DrawLooperAddLayerCallback callback);
};
......@@ -5,6 +5,8 @@
#include "sky/engine/config.h"
#include "sky/engine/core/painting/Paint.h"
#include "sky/engine/core/painting/DrawLooper.h"
namespace blink {
Paint::Paint()
......@@ -15,4 +17,10 @@ Paint::~Paint()
{
}
void Paint::setDrawLooper(DrawLooper* looper)
{
ASSERT(looper);
m_paint.setLooper(looper->looper());
}
} // namespace blink
......@@ -12,6 +12,8 @@
namespace blink {
class DrawLooper;
class Paint : public RefCounted<Paint>, public DartWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
......@@ -31,8 +33,10 @@ public:
{
m_paint.setARGB(a, r, g, b);
}
void setDrawLooper(DrawLooper* looper);
const SkPaint& paint() const { return m_paint; }
void setPaint(const SkPaint& paint) { m_paint = paint; }
private:
Paint();
......
......@@ -9,4 +9,5 @@
attribute unsigned long color;
void setARGB(unsigned long a, unsigned long r, unsigned long g, unsigned long b);
void setDrawLooper(DrawLooper looper);
};
......@@ -40,6 +40,20 @@ void main() {
context.restore();
var builder = new LayerDrawLooperBuilder()
..addLayerOnTop(
new DrawLooperLayerInfo()..setOffset(150.0, 0.0)..setPaintBits(-1),
(Paint layerPaint) {
// TODO(mpcomplete): This won't do anything until we add support for
// setting the color filter.
layerPaint.setARGB(128, 0, 0, 255);
})
..addLayerOnTop(
new DrawLooperLayerInfo()..setOffset(75.0, 75.0)..setPaintBits(0),
(Paint layerPaint) {
layerPaint.setARGB(128, 255, 0, 0);
});
paint.setDrawLooper(builder.build());
context.drawCircle(0.0, 0.0, radius, paint);
context.commit();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册