ARTRenderable.m 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #import <React/ARTRenderable.h>
  8. @implementation ARTRenderable
  9. - (void)setFill:(ARTBrush *)fill
  10. {
  11. [self invalidate];
  12. _fill = fill;
  13. }
  14. - (void)setStroke:(CGColorRef)stroke
  15. {
  16. if (stroke == _stroke) {
  17. return;
  18. }
  19. [self invalidate];
  20. CGColorRelease(_stroke);
  21. _stroke = CGColorRetain(stroke);
  22. }
  23. - (void)setStrokeWidth:(CGFloat)strokeWidth
  24. {
  25. [self invalidate];
  26. _strokeWidth = strokeWidth;
  27. }
  28. - (void)setStrokeCap:(CGLineCap)strokeCap
  29. {
  30. [self invalidate];
  31. _strokeCap = strokeCap;
  32. }
  33. - (void)setStrokeJoin:(CGLineJoin)strokeJoin
  34. {
  35. [self invalidate];
  36. _strokeJoin = strokeJoin;
  37. }
  38. - (void)setStrokeDash:(ARTCGFloatArray)strokeDash
  39. {
  40. if (strokeDash.array == _strokeDash.array) {
  41. return;
  42. }
  43. if (_strokeDash.array) {
  44. free(_strokeDash.array);
  45. }
  46. [self invalidate];
  47. _strokeDash = strokeDash;
  48. }
  49. - (void)dealloc
  50. {
  51. CGColorRelease(_stroke);
  52. if (_strokeDash.array) {
  53. free(_strokeDash.array);
  54. }
  55. }
  56. - (void)renderTo:(CGContextRef)context
  57. {
  58. if (self.opacity <= 0 || self.opacity >= 1 || (self.fill && self.stroke)) {
  59. // If we have both fill and stroke, we will need to paint this using normal compositing
  60. [super renderTo: context];
  61. return;
  62. }
  63. // This is a terminal with only one painting. Therefore we don't need to paint this
  64. // off-screen. We can just composite it straight onto the buffer.
  65. CGContextSaveGState(context);
  66. CGContextConcatCTM(context, self.transform);
  67. CGContextSetAlpha(context, self.opacity);
  68. [self renderLayerTo:context];
  69. CGContextRestoreGState(context);
  70. }
  71. - (void)renderLayerTo:(CGContextRef)context
  72. {
  73. // abstract
  74. }
  75. @end