Skip to content

Commit

Permalink
Move more parts to libs. Move bitmap/dom canvas to /html (flutter#26072)
Browse files Browse the repository at this point in the history
  • Loading branch information
ferhatb authored May 12, 2021
1 parent d7229e9 commit a339374
Show file tree
Hide file tree
Showing 9 changed files with 243 additions and 171 deletions.
5 changes: 3 additions & 2 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,6 @@ FILE: ../../../flutter/lib/ui/window/window.h
FILE: ../../../flutter/lib/web_ui/lib/src/engine.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/alarm_clock.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/assets.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/bitmap_canvas.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/browser_detection.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/canvas_pool.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/canvaskit/canvas.dart
Expand Down Expand Up @@ -482,16 +481,17 @@ FILE: ../../../flutter/lib/web_ui/lib/src/engine/canvaskit/vertices.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/canvaskit/viewport_metrics.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/clipboard.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/color_filter.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/dom_canvas.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/dom_renderer.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/engine_canvas.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/font_change_util.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/frame_reference.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/backdrop_filter.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/bitmap_canvas.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/canvas.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/clip.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/color_filter.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/debug_canvas_reuse_overlay.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/dom_canvas.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/image_filter.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/offscreen_canvas.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/offset.dart
Expand All @@ -515,6 +515,7 @@ FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/render_vertices.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/scene.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/scene_builder.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/shader_mask.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/shaders/image_shader.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/shaders/normalized_gradient.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/shaders/shader.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/shaders/shader_builder.dart
Expand Down
36 changes: 17 additions & 19 deletions lib/web_ui/lib/src/engine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export 'engine/browser_detection.dart';
import 'engine/html_image_codec.dart';
export 'engine/html_image_codec.dart';

import 'engine/html/offscreen_canvas.dart';
export 'engine/html/offscreen_canvas.dart';

import 'engine/html/painting.dart';
Expand Down Expand Up @@ -77,16 +76,21 @@ export 'engine/html/path/path_windings.dart';
import 'engine/html/path/tangent.dart';
export 'engine/html/path/tangent.dart';

import 'engine/html/shaders/normalized_gradient.dart';
import 'engine/html/render_vertices.dart';
export 'engine/html/render_vertices.dart';

import 'engine/html/shaders/image_shader.dart';
export 'engine/html/shaders/image_shader.dart';

export 'engine/html/shaders/normalized_gradient.dart';

import 'engine/html/shaders/shader_builder.dart';
import 'engine/html/shaders/shader.dart';
export 'engine/html/shaders/shader.dart';

export 'engine/html/shaders/shader_builder.dart';

import 'engine/html/shaders/vertex_shaders.dart';
export 'engine/html/shaders/vertex_shaders.dart';

import 'engine/html/shaders/webgl_context.dart';
export 'engine/html/shaders/webgl_context.dart';

import 'engine/mouse_cursor.dart';
Expand Down Expand Up @@ -131,9 +135,6 @@ export 'engine/shadow.dart';
import 'engine/test_embedding.dart';
export 'engine/test_embedding.dart';

import 'engine/ulps.dart';
export 'engine/ulps.dart';

import 'engine/util.dart';
export 'engine/util.dart';

Expand All @@ -147,7 +148,7 @@ import 'engine/web_experiments.dart';
export 'engine/web_experiments.dart';

part 'engine/assets.dart';
part 'engine/bitmap_canvas.dart';
part 'engine/html/bitmap_canvas.dart';
part 'engine/canvaskit/canvas.dart';
part 'engine/canvaskit/canvaskit_canvas.dart';
part 'engine/canvaskit/canvaskit_api.dart';
Expand Down Expand Up @@ -182,7 +183,7 @@ part 'engine/canvaskit/viewport_metrics.dart';
part 'engine/canvas_pool.dart';
part 'engine/clipboard.dart';
part 'engine/color_filter.dart';
part 'engine/dom_canvas.dart';
part 'engine/html/dom_canvas.dart';
part 'engine/dom_renderer.dart';
part 'engine/engine_canvas.dart';
part 'engine/font_change_util.dart';
Expand All @@ -199,11 +200,9 @@ part 'engine/html/path/path.dart';
part 'engine/html/picture.dart';
part 'engine/html/platform_view.dart';
part 'engine/html/recording_canvas.dart';
part 'engine/html/render_vertices.dart';
part 'engine/html/scene.dart';
part 'engine/html/scene_builder.dart';
part 'engine/html/shader_mask.dart';
part 'engine/html/shaders/shader.dart';
part 'engine/html/surface.dart';
part 'engine/html/surface_stats.dart';
part 'engine/html/transform.dart';
Expand Down Expand Up @@ -247,14 +246,13 @@ part 'engine/window.dart';

// The mode the app is running in.
// Keep these in sync with the same constants on the framework-side under foundation/constants.dart.
const bool kReleaseMode = bool.fromEnvironment('dart.vm.product', defaultValue: false);
const bool kProfileMode = bool.fromEnvironment('dart.vm.profile', defaultValue: false);
const bool kReleaseMode =
bool.fromEnvironment('dart.vm.product', defaultValue: false);
const bool kProfileMode =
bool.fromEnvironment('dart.vm.profile', defaultValue: false);
const bool kDebugMode = !kReleaseMode && !kProfileMode;
String get buildMode => kReleaseMode
? 'release'
: kProfileMode
? 'profile'
: 'debug';
String get buildMode =>
kReleaseMode ? 'release' : kProfileMode ? 'profile' : 'debug';

/// A benchmark metric that includes frame-related computations prior to
/// submitting layer and picture operations to the underlying renderer, such as
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -965,25 +965,25 @@ class BitmapCanvas extends EngineCanvas {
// as well.
assert(paint.shader == null || paint.shader is EngineImageShader,
'Linear/Radial/SweepGradient not supported yet');
final Int32List? colors = vertices._colors;
final ui.VertexMode mode = vertices._mode;
final Int32List? colors = vertices.colors;
final ui.VertexMode mode = vertices.mode;
html.CanvasRenderingContext2D? ctx = _canvasPool.context;
if (colors == null && paint.style != ui.PaintingStyle.fill &&
paint.shader == null) {
final Float32List positions = mode == ui.VertexMode.triangles
? vertices._positions
: _convertVertexPositions(mode, vertices._positions);
? vertices.positions
: convertVertexPositions(mode, vertices.positions);
// Draw hairline for vertices if no vertex colors are specified.
save();
final ui.Color color = paint.color ?? ui.Color(0xFF000000);
_canvasPool.contextHandle
..fillStyle = null
..strokeStyle = colorToCssString(color);
_glRenderer!.drawHairline(ctx, positions);
glRenderer!.drawHairline(ctx, positions);
restore();
return;
}
_glRenderer!.drawVertices(ctx, _widthInBitmapPixels, _heightInBitmapPixels,
glRenderer!.drawVertices(ctx, _widthInBitmapPixels, _heightInBitmapPixels,
_canvasPool.currentTransform, vertices, blendMode, paint);
}

Expand Down
File renamed without changes.
32 changes: 21 additions & 11 deletions lib/web_ui/lib/src/engine/html/recording_canvas.dart
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ class RecordingCanvas {

void drawLine(ui.Offset p1, ui.Offset p2, SurfacePaint paint) {
assert(!_recordingEnded);
assert(paint.shader == null || paint.shader is! EngineImageShader, 'ImageShader not supported yet');
assert(paint.shader == null || paint.shader is! EngineImageShader,
'ImageShader not supported yet');
final double paintSpread = math.max(_getPaintSpread(paint), 1.0);
final PaintDrawLine command = PaintDrawLine(p1, p2, paint.paintData);
// TODO(yjbanov): This can be optimized. Currently we create a box around
Expand All @@ -345,7 +346,8 @@ class RecordingCanvas {

void drawPaint(SurfacePaint paint) {
assert(!_recordingEnded);
assert(paint.shader == null || paint.shader is! EngineImageShader, 'ImageShader not supported yet');
assert(paint.shader == null || paint.shader is! EngineImageShader,
'ImageShader not supported yet');
renderStrategy.hasArbitraryPaint = true;
_didDraw = true;
final PaintDrawPaint command = PaintDrawPaint(paint.paintData);
Expand All @@ -355,7 +357,8 @@ class RecordingCanvas {

void drawRect(ui.Rect rect, SurfacePaint paint) {
assert(!_recordingEnded);
assert(paint.shader == null || paint.shader is! EngineImageShader, 'ImageShader not supported yet');
assert(paint.shader == null || paint.shader is! EngineImageShader,
'ImageShader not supported yet');
if (paint.shader != null) {
renderStrategy.hasArbitraryPaint = true;
}
Expand All @@ -372,7 +375,8 @@ class RecordingCanvas {

void drawRRect(ui.RRect rrect, SurfacePaint paint) {
assert(!_recordingEnded);
assert(paint.shader == null || paint.shader is! EngineImageShader, 'ImageShader not supported yet');
assert(paint.shader == null || paint.shader is! EngineImageShader,
'ImageShader not supported yet');
if (paint.shader != null || !rrect.webOnlyUniformRadii) {
renderStrategy.hasArbitraryPaint = true;
}
Expand All @@ -389,7 +393,8 @@ class RecordingCanvas {

void drawDRRect(ui.RRect outer, ui.RRect inner, SurfacePaint paint) {
assert(!_recordingEnded);
assert(paint.shader == null || paint.shader is! EngineImageShader, 'ImageShader not supported yet');
assert(paint.shader == null || paint.shader is! EngineImageShader,
'ImageShader not supported yet');
// Check the inner bounds are contained within the outer bounds
// see: https://cs.chromium.org/chromium/src/third_party/skia/src/core/SkCanvas.cpp?l=1787-1789
ui.Rect innerRect = inner.outerRect;
Expand Down Expand Up @@ -448,7 +453,8 @@ class RecordingCanvas {

void drawOval(ui.Rect rect, SurfacePaint paint) {
assert(!_recordingEnded);
assert(paint.shader == null || paint.shader is! EngineImageShader, 'ImageShader not supported yet');
assert(paint.shader == null || paint.shader is! EngineImageShader,
'ImageShader not supported yet');
renderStrategy.hasArbitraryPaint = true;
_didDraw = true;
final double paintSpread = _getPaintSpread(paint);
Expand All @@ -463,7 +469,8 @@ class RecordingCanvas {

void drawCircle(ui.Offset c, double radius, SurfacePaint paint) {
assert(!_recordingEnded);
assert(paint.shader == null || paint.shader is! EngineImageShader, 'ImageShader not supported yet');
assert(paint.shader == null || paint.shader is! EngineImageShader,
'ImageShader not supported yet');
renderStrategy.hasArbitraryPaint = true;
_didDraw = true;
final double paintSpread = _getPaintSpread(paint);
Expand All @@ -481,7 +488,8 @@ class RecordingCanvas {

void drawPath(ui.Path path, SurfacePaint paint) {
assert(!_recordingEnded);
assert(paint.shader == null || paint.shader is! EngineImageShader, 'ImageShader not supported yet');
assert(paint.shader == null || paint.shader is! EngineImageShader,
'ImageShader not supported yet');
if (paint.shader == null) {
// For Rect/RoundedRect paths use drawRect/drawRRect code paths for
// DomCanvas optimization.
Expand Down Expand Up @@ -518,7 +526,8 @@ class RecordingCanvas {

void drawImage(ui.Image image, ui.Offset offset, SurfacePaint paint) {
assert(!_recordingEnded);
assert(paint.shader == null || paint.shader is! EngineImageShader, 'ImageShader not supported yet');
assert(paint.shader == null || paint.shader is! EngineImageShader,
'ImageShader not supported yet');
renderStrategy.hasArbitraryPaint = true;
renderStrategy.hasImageElements = true;
_didDraw = true;
Expand Down Expand Up @@ -556,7 +565,8 @@ class RecordingCanvas {
void drawImageRect(
ui.Image image, ui.Rect src, ui.Rect dst, SurfacePaint paint) {
assert(!_recordingEnded);
assert(paint.shader == null || paint.shader is! EngineImageShader, 'ImageShader not supported yet');
assert(paint.shader == null || paint.shader is! EngineImageShader,
'ImageShader not supported yet');
renderStrategy.hasArbitraryPaint = true;
renderStrategy.hasImageElements = true;
_didDraw = true;
Expand Down Expand Up @@ -613,7 +623,7 @@ class RecordingCanvas {
_didDraw = true;
final PaintDrawVertices command =
PaintDrawVertices(vertices, blendMode, paint.paintData);
_growPaintBoundsByPoints(vertices._positions, 0, paint, command);
_growPaintBoundsByPoints(vertices.positions, 0, paint, command);
_commands.add(command);
}

Expand Down
Loading

0 comments on commit a339374

Please sign in to comment.