<commit_before>//******************************************************************************
//
// Copyright (c) 2015 Microsoft Corporation. All rights reserved.
//
// This code is licensed under the MIT License (MIT).
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
//******************************************************************************

#include "Starboard.h"
#include "UIKit/UIKit.h"
#include "CGContextInternal.h"

#define MAX_CONTEXT_DEPTH 16
__declspec(thread) CGContextRef _currentCGContext[MAX_CONTEXT_DEPTH];
__declspec(thread) int _currentCGContextDepth;

/**
 @Status Interoperable
*/
void UIGraphicsPushContext(CGContextRef context) {
    if (_currentCGContextDepth >= MAX_CONTEXT_DEPTH - 1) {
        assert(0);
        return;
    }

    CGContextRetain(context);
    _currentCGContext[++(_currentCGContextDepth)] = context;
}

/**
 @Status Interoperable
*/
void UIGraphicsPopContext() {
    if (_currentCGContextDepth <= 0) {
        assert(0);
        return;
    }
    CGContextRelease(_currentCGContext[_currentCGContextDepth]);
    _currentCGContext[_currentCGContextDepth] = nil;
    _currentCGContextDepth--;
}

/**
 @Status Interoperable
*/
CGContextRef UIGraphicsGetCurrentContext() {
    return _currentCGContext[_currentCGContextDepth];
}

/**
 @Status Caveat
 @Notes opaque parameter not supported
*/
void UIGraphicsBeginImageContextWithOptions(CGSize size, BOOL opaque, float scale) {
    if (scale == 0.0f) {
        scale = GetCACompositor()->screenScale();
    }
    CGContextRef newCtx = CGBitmapContextCreate32((int)(size.width * scale), (int)(size.height * scale));
    newCtx->scale = scale;
    CGContextTranslateCTM(newCtx, 0.0f, size.height * scale);
    CGContextScaleCTM(newCtx, scale, scale);
    CGContextScaleCTM(newCtx, 1.0f, -1.0f);

    UIGraphicsPushContext(newCtx);
}

/**
 @Status Interoperable
*/
void UIGraphicsBeginImageContext(CGSize size) {
    UIGraphicsBeginImageContextWithOptions(size, FALSE, 1.0f);
}

/**
 @Status Interoperable
*/
UIImage* UIGraphicsGetImageFromCurrentImageContext() {
    id ret = [UIImage imageWithCGImage:CGBitmapContextGetImage(UIGraphicsGetCurrentContext())
                                 scale:UIGraphicsGetCurrentContext()->scale
                           orientation:UIImageOrientationUp];

    return ret;
}

/**
 @Status Interoperable
*/
void UIGraphicsEndImageContext() {
    CGContextRef ctx = UIGraphicsGetCurrentContext();

    UIGraphicsPopContext();
    CGContextRelease(ctx);
}

/**
 @Status Interoperable
*/
void UIRectFill(CGRect rect) {
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextFillRect(ctx, rect);
}

/**
 @Status Stub
*/
void UIRectFrame(CGRect rect) {
    UNIMPLEMENTED();
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    // CGContextFillRect(ctx, rect);
    EbrDebugLog("UIRectFrame not supported\n");
}

/**
 @Status Interoperable
*/
void UIRectClip(CGRect clip) {
    CGContextRef ctx = UIGraphicsGetCurrentContext();

    CGContextClipToRect(ctx, clip);
}

/**
 @Status Interoperable
*/
void UIRectFillUsingBlendMode(CGRect rect, CGBlendMode mode) {
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGBlendMode oldBlend = CGContextGetBlendMode(ctx);
    CGContextSetBlendMode(ctx, mode);
    CGContextFillRect(ctx, rect);
    CGContextSetBlendMode(ctx, oldBlend);
}

/**
 @Status Interoperable
*/
NSString* NSStringFromCGPoint(CGPoint p) {
    return [NSString stringWithFormat:@"{%f,%f}", p.x, p.y];
}

/**
 @Status Interoperable
*/
NSString* NSStringFromCGSize(CGSize s) {
    return [NSString stringWithFormat:@"{%f,%f}", s.width, s.height];
}

/**
 @Status Interoperable
*/
NSString* NSStringFromCGRect(CGRect r) {
    return [NSString stringWithFormat:@"{{%f, %f}, {%f, %f}}", r.origin.x, r.origin.y, r.size.width, r.size.height];
}
<commit_msg>VSO 5763047: Raise the max CGContext depth to 128 from 16.<commit_after>//******************************************************************************
//
// Copyright (c) 2015 Microsoft Corporation. All rights reserved.
//
// This code is licensed under the MIT License (MIT).
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
//******************************************************************************

#include "Starboard.h"
#include "UIKit/UIKit.h"
#include "CGContextInternal.h"

#define MAX_CONTEXT_DEPTH 128
__declspec(thread) CGContextRef _currentCGContext[MAX_CONTEXT_DEPTH];
__declspec(thread) int _currentCGContextDepth;

/**
 @Status Interoperable
*/
void UIGraphicsPushContext(CGContextRef context) {
    if (_currentCGContextDepth >= MAX_CONTEXT_DEPTH - 1) {
        assert(0);
        return;
    }

    CGContextRetain(context);
    _currentCGContext[++(_currentCGContextDepth)] = context;
}

/**
 @Status Interoperable
*/
void UIGraphicsPopContext() {
    if (_currentCGContextDepth <= 0) {
        assert(0);
        return;
    }
    CGContextRelease(_currentCGContext[_currentCGContextDepth]);
    _currentCGContext[_currentCGContextDepth] = nil;
    _currentCGContextDepth--;
}

/**
 @Status Interoperable
*/
CGContextRef UIGraphicsGetCurrentContext() {
    return _currentCGContext[_currentCGContextDepth];
}

/**
 @Status Caveat
 @Notes opaque parameter not supported
*/
void UIGraphicsBeginImageContextWithOptions(CGSize size, BOOL opaque, float scale) {
    if (scale == 0.0f) {
        scale = GetCACompositor()->screenScale();
    }
    CGContextRef newCtx = CGBitmapContextCreate32((int)(size.width * scale), (int)(size.height * scale));
    newCtx->scale = scale;
    CGContextTranslateCTM(newCtx, 0.0f, size.height * scale);
    CGContextScaleCTM(newCtx, scale, scale);
    CGContextScaleCTM(newCtx, 1.0f, -1.0f);

    UIGraphicsPushContext(newCtx);
}

/**
 @Status Interoperable
*/
void UIGraphicsBeginImageContext(CGSize size) {
    UIGraphicsBeginImageContextWithOptions(size, FALSE, 1.0f);
}

/**
 @Status Interoperable
*/
UIImage* UIGraphicsGetImageFromCurrentImageContext() {
    id ret = [UIImage imageWithCGImage:CGBitmapContextGetImage(UIGraphicsGetCurrentContext())
                                 scale:UIGraphicsGetCurrentContext()->scale
                           orientation:UIImageOrientationUp];

    return ret;
}

/**
 @Status Interoperable
*/
void UIGraphicsEndImageContext() {
    CGContextRef ctx = UIGraphicsGetCurrentContext();

    UIGraphicsPopContext();
    CGContextRelease(ctx);
}

/**
 @Status Interoperable
*/
void UIRectFill(CGRect rect) {
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextFillRect(ctx, rect);
}

/**
 @Status Stub
*/
void UIRectFrame(CGRect rect) {
    UNIMPLEMENTED();
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    // CGContextFillRect(ctx, rect);
    EbrDebugLog("UIRectFrame not supported\n");
}

/**
 @Status Interoperable
*/
void UIRectClip(CGRect clip) {
    CGContextRef ctx = UIGraphicsGetCurrentContext();

    CGContextClipToRect(ctx, clip);
}

/**
 @Status Interoperable
*/
void UIRectFillUsingBlendMode(CGRect rect, CGBlendMode mode) {
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGBlendMode oldBlend = CGContextGetBlendMode(ctx);
    CGContextSetBlendMode(ctx, mode);
    CGContextFillRect(ctx, rect);
    CGContextSetBlendMode(ctx, oldBlend);
}

/**
 @Status Interoperable
*/
NSString* NSStringFromCGPoint(CGPoint p) {
    return [NSString stringWithFormat:@"{%f,%f}", p.x, p.y];
}

/**
 @Status Interoperable
*/
NSString* NSStringFromCGSize(CGSize s) {
    return [NSString stringWithFormat:@"{%f,%f}", s.width, s.height];
}

/**
 @Status Interoperable
*/
NSString* NSStringFromCGRect(CGRect r) {
    return [NSString stringWithFormat:@"{{%f, %f}, {%f, %f}}", r.origin.x, r.origin.y, r.size.width, r.size.height];
}

{'fraction_non_alphanumeric': 0.1492048643592142, 'fraction_numerical': 0.00666510757717493, 'mean_word_length': 4.399621212121212, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2219136', 'n_tokens_mistral': 2761, 'n_tokens_neox': 2596, 'n_words': 604}