flamegraphCanvas.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import {mat3, vec2} from 'gl-matrix';
  2. import {Rect, transformMatrixBetweenRect} from 'sentry/utils/profiling/gl/utils';
  3. export class FlamegraphCanvas {
  4. canvas: HTMLCanvasElement;
  5. origin: vec2;
  6. physicalSpace: Rect = Rect.Empty();
  7. logicalSpace: Rect = Rect.Empty();
  8. physicalToLogicalSpace: mat3 = mat3.create();
  9. logicalToPhysicalSpace: mat3 = mat3.create();
  10. constructor(canvas: HTMLCanvasElement, origin: vec2) {
  11. this.canvas = canvas;
  12. this.origin = origin;
  13. this.initPhysicalSpace();
  14. }
  15. initPhysicalSpace() {
  16. this.physicalSpace = new Rect(
  17. this.origin[0],
  18. this.origin[1],
  19. this.canvas.width - this.origin[0],
  20. this.canvas.height - this.origin[1]
  21. );
  22. this.logicalSpace = this.physicalSpace.scale(
  23. 1 / window.devicePixelRatio,
  24. 1 / window.devicePixelRatio
  25. );
  26. this.logicalToPhysicalSpace = transformMatrixBetweenRect(
  27. this.logicalSpace,
  28. this.physicalSpace
  29. );
  30. this.physicalToLogicalSpace = transformMatrixBetweenRect(
  31. this.physicalSpace,
  32. this.logicalSpace
  33. );
  34. }
  35. }