flamegraphCanvas.tsx 1.1 KB

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