Adds bindings to Skia for VertexMode and drawVertices

This commit is contained in:
Viktor Lidholt 2015-09-08 11:09:45 -07:00
parent d60244d4ee
commit 1d6cd4bc01
7 changed files with 102 additions and 0 deletions

View File

@ -126,6 +126,7 @@ CPP_SPECIAL_CONVERSION_RULES = {
'MojoDataPipeConsumer': 'mojo::ScopedDataPipeConsumerHandle',
'TileMode': 'SkShader::TileMode',
'TransferMode': 'SkXfermode::Mode',
'VertexMode': 'SkCanvas::VertexMode',
'FilterQuality': 'SkFilterQuality',
'PaintingStyle': 'SkPaint::Style',
# TODO(abarth): Give these better C++ types.
@ -386,6 +387,7 @@ DART_TO_CPP_VALUE = {
'Size': pass_by_value_format('Size'),
'TileMode': pass_by_value_format('TileMode', ''),
'TransferMode': pass_by_value_format('TransferMode', ''),
'VertexMode': pass_by_value_format('VertexMode', ''),
'FilterQuality': pass_by_value_format('FilterQuality', ''),
'PaintingStyle': pass_by_value_format('PaintingStyle', ''),
'FontStyle': pass_by_value_format('FontStyle', ''),

View File

@ -440,6 +440,7 @@ sky_core_files = [
"painting/Size.cpp",
"painting/Size.h",
"painting/TransferMode.h",
"painting/VertexMode.h",
"rendering/BidiRun.h",
"rendering/BidiRunForLine.cpp",
"rendering/BidiRunForLine.h",
@ -687,6 +688,7 @@ core_dart_files = get_path_info([
"painting/RSTransform.dart",
"painting/Size.dart",
"painting/TransferMode.dart",
"painting/VertexMode.dart",
"text/FontStyle.dart",
"text/FontWeight.dart",
"text/TextAlign.dart",

View File

@ -231,6 +231,61 @@ void Canvas::drawDrawable(Drawable* drawable)
m_canvas->drawDrawable(drawable->toSkia());
}
void Canvas::drawVertices(SkCanvas::VertexMode vmode,
const Vector<Point>& vertices,
const Vector<Point>& texs,
const Vector<SkColor>& colors,
SkXfermode::Mode mode,
const Vector<int>& indices,
const Paint& paint,
ExceptionState& es)
{
if (!m_canvas)
return;
size_t vertexCount = vertices.size();
if (texs.size() && texs.size() != vertexCount)
return es.ThrowRangeError("vertices and texs lengths must match");
if (colors.size() && colors.size() != vertexCount)
return es.ThrowRangeError("vertices and colors lengths must match");
Vector<SkPoint> skVertices;
for (size_t x = 0; x < vertices.size(); x++) {
const Point& point = vertices[x];
if (point.is_null)
return es.ThrowRangeError("vertices contained a null");
skVertices.append(point.sk_point);
}
Vector<SkPoint> skTexs;
for (size_t x = 0; x < texs.size(); x++) {
const Point& point = texs[x];
if (point.is_null)
return es.ThrowRangeError("texs contained a null");
skTexs.append(point.sk_point);
}
Vector<uint16_t> skIndices;
for (size_t x = 0; x < indices.size(); x++) {
uint16_t i = indices[x];
skIndices.append(i);
}
RefPtr<SkXfermode> modePtr = adoptRef(SkXfermode::Create(mode));
m_canvas->drawVertices(
vmode,
skVertices.size(),
skVertices.data(),
skTexs.isEmpty() ? nullptr : skTexs.data(),
colors.isEmpty() ? nullptr : colors.data(),
modePtr.get(),
skIndices.isEmpty() ? nullptr : skIndices.data(),
skIndices.size(),
*paint.paint()
);
}
void Canvas::drawAtlas(CanvasImage* atlas,
const Vector<RSTransform>& transforms, const Vector<Rect>& rects,
const Vector<SkColor>& colors, SkXfermode::Mode mode,

View File

@ -17,6 +17,7 @@
#include "sky/engine/core/painting/Rect.h"
#include "sky/engine/core/painting/Size.h"
#include "sky/engine/core/painting/RSTransform.h"
#include "sky/engine/core/painting/VertexMode.h"
#include "sky/engine/platform/graphics/DisplayList.h"
#include "sky/engine/tonic/dart_wrappable.h"
#include "sky/engine/tonic/float32_list.h"
@ -91,6 +92,15 @@ public:
void drawPicture(Picture* picture);
void drawDrawable(Drawable* drawable);
void drawVertices(SkCanvas::VertexMode vmode,
const Vector<Point>& vertices,
const Vector<Point>& texs,
const Vector<SkColor>& colors,
SkXfermode::Mode mode,
const Vector<int>& indices,
const Paint& paint,
ExceptionState& es);
void drawAtlas(CanvasImage* atlas,
const Vector<RSTransform>& transforms, const Vector<Rect>& rects,
const Vector<SkColor>& colors, SkXfermode::Mode mode,

View File

@ -39,6 +39,7 @@
void drawImageRect(Image image, Rect src, Rect dst, Paint paint);
void drawPicture(Picture picture);
void drawDrawable(Drawable drawable);
[RaisesException] void drawVertices(VertexMode vmode, sequence<Point> vertices, sequence<Point> texs, sequence<Color> colors, TransferMode mode, sequence<long> indicies, Paint paint);
// TODO(eseidel): Paint should be optional, but optional doesn't work.
[RaisesException] void drawAtlas(Image image,

View File

@ -0,0 +1,11 @@
// 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;
enum VertexMode {
triangles,
triangleStrip,
triangleFan,
}

View File

@ -0,0 +1,21 @@
// 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_VERTEXMODE_H_
#define SKY_ENGINE_CORE_PAINTING_VERTEXMODE_H_
#include "sky/engine/tonic/dart_converter.h"
#include "third_party/skia/include/core/SkCanvas.h"
namespace blink {
class VertexMode {};
template <>
struct DartConverter<VertexMode>
: public DartConverterEnum<SkCanvas::VertexMode> {};
} // namespace blink
#endif // SKY_ENGINE_CORE_PAINTING_VERTEXMODE_H_