Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import <AppKit/AppKit.h>
- #include "Mac/PluginWindowMac.h"
- #include "Mac/PluginWindowMacCA.h"
- #include "Mac/PluginWindowMacICA.h"
- #include "SPlayerPluginMac.h"
- GLuint LoadTexture( const char * filename, int width, int height );
- @interface SPCALayer : CALayer {
- GLfloat m_angle;
- GLuint texture;
- int loaded;
- }
- @end
- @implementation SPCALayer
- - (id) init {
- if ([super init]) {
- m_angle = 0;
- loaded = 0;
- }
- return self;
- }
- - (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)context {
- CGColorRef bgColor = CGColorCreateGenericRGB(0.952, 0.95, 0.91, 0.9);
- CGContextSetFillColorWithColor(context, bgColor);
- CGContextFillRect(context, layer.bounds);
- static const size_t kComponentsPerPixel = 4;
- static const size_t kBitsPerComponent = sizeof(unsigned char) * 8;
- NSInteger layerHeight = layer.bounds.size.height;
- NSInteger layerWidth = layer.bounds.size.width;
- NSLog(@"\n\nw: %d \t h: %d\n\n", (int)layerWidth, (int)layerHeight);
- CGContextSaveGState(context);
- CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
- size_t bufferLength = layerWidth * layerHeight * kComponentsPerPixel;
- unsigned char *buffer = (unsigned char *)malloc(bufferLength);
- NSInteger r = random() % 255;
- for (NSInteger i = 0; i < bufferLength; i += 4)
- {
- NSInteger x = (i / 4) % (NSInteger)layer.bounds.size.width;
- NSInteger y = (NSInteger)(i / 4) / (NSInteger)layer.bounds.size.width;
- buffer[i] = (x % 255) ^ (y % 255) + random() % 16;
- buffer[i+1] = r;
- buffer[i+2] = 255-r;
- buffer[i+3] = 255;
- }
- CGDataProviderRef provider =
- CGDataProviderCreateWithData(NULL, buffer, bufferLength, NULL);
- CGImageRef imageRef =
- CGImageCreate(layerWidth, layerHeight, kBitsPerComponent,
- kBitsPerComponent * kComponentsPerPixel,
- kComponentsPerPixel * layerWidth,
- rgb,
- kCGBitmapByteOrderDefault | kCGImageAlphaLast,
- provider, NULL, false, kCGRenderingIntentDefault);
- CGContextDrawImage(context, layer.bounds, imageRef);
- CGImageRelease(imageRef);
- [super setNeedsDisplay];
- }
- @end
- SPlayerPluginMac::SPlayerPluginMac() : m_layer(NULL) {}
- SPlayerPluginMac::~SPlayerPluginMac()
- {
- if (m_layer) {
- [(CALayer*)m_layer removeFromSuperlayer];
- [(CALayer*)m_layer release];
- m_layer = NULL;
- }
- }
- bool SPlayerPluginMac::onWindowAttached(FB::AttachedEvent* evt, FB::PluginWindowMac* wnd)
- {
- if (FB::PluginWindowMac::DrawingModelCoreAnimation == wnd->getDrawingModel() || FB::PluginWindowMac::DrawingModelInvalidatingCoreAnimation == wnd->getDrawingModel()) {
- SPCALayer* layer = [SPCALayer new];
- layer.autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable;
- layer.needsDisplayOnBoundsChange = YES;
- m_layer = layer;
- layer.backgroundColor=CGColorCreateGenericRGB(0.5, 0.5, 0.3, 1);
- if (FB::PluginWindowMac::DrawingModelInvalidatingCoreAnimation == wnd->getDrawingModel())
- wnd->StartAutoInvalidate(1.0/30.0);
- [(CALayer*) wnd->getDrawingPrimitive() addSublayer:layer];
- // Draw Label
- CATextLayer* txtlayer = [CATextLayer layer];
- txtlayer.string = (FB::PluginWindowMac::DrawingModelInvalidatingCoreAnimation == wnd->getDrawingModel()) ? @"STREAMER (CA Invalidating) " : [NSString stringWithFormat: @"STREAMER (CA)" ];
- txtlayer.fontSize = 24;
- txtlayer.foregroundColor = CGColorCreateGenericRGB(0,0,0,1.0);
- txtlayer.autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable;
- txtlayer.needsDisplayOnBoundsChange = YES;
- [(CALayer*) wnd->getDrawingPrimitive() addSublayer:txtlayer];
- CALayer *customDrawn = [CALayer layer];
- customDrawn.autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable;
- customDrawn.needsDisplayOnBoundsChange = YES;
- customDrawn.delegate = (id)layer;
- customDrawn.masksToBounds = YES;
- [layer addSublayer:customDrawn];
- [customDrawn setNeedsDisplay];
- }
- return SPlayerPlugin::onWindowAttached(evt,wnd);
- }
- bool SPlayerPluginMac::onWindowDetached(FB::DetachedEvent* evt, FB::PluginWindowMac* wnd)
- {
- return SPlayerPlugin::onWindowDetached(evt,wnd);
- }
Add Comment
Please, Sign In to add comment