From baabf090f0d66f3add5026aef19e55558eb9b596 Mon Sep 17 00:00:00 2001 From: Viktor Lidholt Date: Fri, 4 Sep 2015 16:03:14 -0700 Subject: [PATCH] Adds bindings for ImageShader to SkShader::CreateBitmapShader --- sky/engine/core/core.gni | 4 +++ sky/engine/core/painting/ImageShader.cpp | 36 +++++++++++++++++++++ sky/engine/core/painting/ImageShader.dart | 20 ++++++++++++ sky/engine/core/painting/ImageShader.h | 38 +++++++++++++++++++++++ sky/engine/core/painting/ImageShader.idl | 10 ++++++ 5 files changed, 108 insertions(+) create mode 100644 sky/engine/core/painting/ImageShader.cpp create mode 100644 sky/engine/core/painting/ImageShader.dart create mode 100644 sky/engine/core/painting/ImageShader.h create mode 100644 sky/engine/core/painting/ImageShader.idl diff --git a/sky/engine/core/core.gni b/sky/engine/core/core.gni index 5f3a877f5ca..4aec360a375 100644 --- a/sky/engine/core/core.gni +++ b/sky/engine/core/core.gni @@ -408,6 +408,8 @@ sky_core_files = [ "painting/DrawLooperLayerInfo.cpp", "painting/DrawLooperLayerInfo.h", "painting/FilterQuality.h", + "painting/ImageShader.cpp", + "painting/ImageShader.h", "painting/LayerDrawLooperBuilder.cpp", "painting/LayerDrawLooperBuilder.h", "painting/LayoutRoot.cpp", @@ -649,6 +651,7 @@ core_idl_files = get_path_info([ "painting/DrawLooperLayerInfo.idl", "painting/Gradient.idl", "painting/Image.idl", + "painting/ImageShader.idl", "painting/LayerDrawLooperBuilder.idl", "painting/LayoutRoot.idl", "painting/MaskFilter.idl", @@ -673,6 +676,7 @@ core_dart_files = get_path_info([ "painting/DrawLooperLayerInfo.dart", "painting/FilterQuality.dart", "painting/Gradient.dart", + "painting/ImageShader.dart", "painting/MaskFilter.dart", "painting/Offset.dart", "painting/OffsetBase.dart", diff --git a/sky/engine/core/painting/ImageShader.cpp b/sky/engine/core/painting/ImageShader.cpp new file mode 100644 index 00000000000..95cb0cb636d --- /dev/null +++ b/sky/engine/core/painting/ImageShader.cpp @@ -0,0 +1,36 @@ +// 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/core/painting/ImageShader.h" + +namespace blink { + +PassRefPtr ImageShader::create() { + return adoptRef(new ImageShader()); +} + +void ImageShader::initWithImage(CanvasImage* image, + SkShader::TileMode tmx, + SkShader::TileMode tmy, + const Float32List& matrix4, + ExceptionState& es) { + ASSERT(image != NULL); + + SkMatrix sk_matrix = toSkMatrix(matrix4, es); + if (es.had_exception()) + return; + + SkBitmap bitmap; + image->image()->asLegacyBitmap(&bitmap, SkImage::kRO_LegacyBitmapMode); + + set_shader(adoptRef(SkShader::CreateBitmapShader(bitmap, tmx, tmy, &sk_matrix))); +} + +ImageShader::ImageShader() : Shader(nullptr) { +} + +ImageShader::~ImageShader() { +} + +} // namespace blink diff --git a/sky/engine/core/painting/ImageShader.dart b/sky/engine/core/painting/ImageShader.dart new file mode 100644 index 00000000000..a31b8680d10 --- /dev/null +++ b/sky/engine/core/painting/ImageShader.dart @@ -0,0 +1,20 @@ +// 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. + +part of dart.sky; + +class ImageShader extends _ImageShader { + ImageShader(Image image, TileMode tmx, TileMode tmy, Float32List matrix4) { + if (image == null) + throw new ArgumentError("[image] argument cannot be null"); + if (tmx == null) + throw new ArgumentError("[tmx] argument cannot be null"); + if (tmy == null) + throw new ArgumentError("[tmy] argument cannot be null"); + if (matrix4 == null) + throw new ArgumentError("[matrix4] argument cannot be null"); + + this._initWithImage(image, tmx, tmy, matrix4); + } +} diff --git a/sky/engine/core/painting/ImageShader.h b/sky/engine/core/painting/ImageShader.h new file mode 100644 index 00000000000..a67318202f6 --- /dev/null +++ b/sky/engine/core/painting/ImageShader.h @@ -0,0 +1,38 @@ +// 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_IMAGESHADER_H_ +#define SKY_ENGINE_CORE_PAINTING_IMAGESHADER_H_ + +#include "sky/engine/bindings/exception_state.h" +#include "sky/engine/core/painting/CanvasGradient.h" +#include "sky/engine/core/painting/CanvasImage.h" +#include "sky/engine/core/painting/Shader.h" +#include "sky/engine/tonic/dart_wrappable.h" +#include "sky/engine/core/painting/Matrix.h" +#include "sky/engine/tonic/float32_list.h" +#include "third_party/skia/include/core/SkShader.h" +#include "third_party/skia/include/core/SkMatrix.h" + +namespace blink { + +class ImageShader : public Shader { + DEFINE_WRAPPERTYPEINFO(); + public: + ~ImageShader() override; + static PassRefPtr create(); + + void initWithImage(CanvasImage* image, + SkShader::TileMode tmx, + SkShader::TileMode tmy, + const Float32List& matrix4, + ExceptionState& es); + + private: + ImageShader(); +}; + +} // namespace blink + +#endif // SKY_ENGINE_CORE_PAINTING_IMAGESHADER_H_ diff --git a/sky/engine/core/painting/ImageShader.idl b/sky/engine/core/painting/ImageShader.idl new file mode 100644 index 00000000000..9cbb2c26269 --- /dev/null +++ b/sky/engine/core/painting/ImageShader.idl @@ -0,0 +1,10 @@ +// 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. + +[ + PrivateDart, + Constructor() +] interface ImageShader : Shader { + [RaisesException] void initWithImage(Image image, TileMode tmx, TileMode tmy, Float32List matrix4); +};