2014 snapchat source code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
2.2 KiB

  1. //
  2. // SCProcessingPipelineBuilder.m
  3. // Snapchat
  4. //
  5. // Created by Yu-Kuan (Anthony) Lai on 6/1/17.
  6. // Copyright © 2017 Snapchat, Inc. All rights reserved.
  7. //
  8. #import "SCProcessingPipelineBuilder.h"
  9. #import "SCCameraTweaks.h"
  10. #import "SCDepthBlurMetalRenderCommand.h"
  11. #import "SCDepthToGrayscaleMetalRenderCommand.h"
  12. #import "SCDigitalExposureHandler.h"
  13. #import "SCExposureAdjustMetalRenderCommand.h"
  14. #import "SCMetalUtils.h"
  15. #import "SCNightModeEnhancementMetalRenderCommand.h"
  16. #import "SCProcessingPipeline.h"
  17. @implementation SCProcessingPipelineBuilder
  18. - (SCProcessingPipeline *)build
  19. {
  20. if (!_useExposureAdjust && !_portraitModeEnabled && !_enhancedNightMode) { // in the future: && !useA && !useB ...
  21. return nil;
  22. }
  23. SCProcessingPipeline *processingPipeline = [[SCProcessingPipeline alloc] init];
  24. NSMutableArray<id<SCProcessingModule>> *processingModules = [NSMutableArray array];
  25. // order of adding module matters!
  26. if (_useExposureAdjust && SCDeviceSupportsMetal()) {
  27. // this check looks redundant right now, but when we have more modules it will be necessary
  28. SCMetalModule *exposureAdjustMetalModule =
  29. [[SCMetalModule alloc] initWithMetalRenderCommand:[SCExposureAdjustMetalRenderCommand new]];
  30. [processingModules addObject:exposureAdjustMetalModule];
  31. }
  32. if (_portraitModeEnabled) {
  33. id<SCMetalRenderCommand> renderCommand = SCCameraTweaksDepthToGrayscaleOverride()
  34. ? [SCDepthToGrayscaleMetalRenderCommand new]
  35. : [SCDepthBlurMetalRenderCommand new];
  36. SCMetalModule *depthBlurMetalModule = [[SCMetalModule alloc] initWithMetalRenderCommand:renderCommand];
  37. [processingModules addObject:depthBlurMetalModule];
  38. }
  39. if (_enhancedNightMode && SCDeviceSupportsMetal()) {
  40. SCMetalModule *nightModeEnhancementModule =
  41. [[SCMetalModule alloc] initWithMetalRenderCommand:[SCNightModeEnhancementMetalRenderCommand new]];
  42. [processingModules addObject:nightModeEnhancementModule];
  43. }
  44. processingPipeline.processingModules = processingModules;
  45. return processingPipeline;
  46. }
  47. @end