Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement CGColor independent of UIColor #2538

Merged
merged 19 commits into from
Apr 27, 2017

Conversation

msft-Jeyaram
Copy link
Contributor

@msft-Jeyaram msft-Jeyaram commented Apr 17, 2017

  • Implement CGColor independent of UIColor
  • Implement UIColor as a class cluster
  • Removal of BrushTypes
  • Overall code improvements
  • Support for grayscale
  • Remove UIColor usage from CALayer
  • Update UIKit to properly confirm to UIColor
    Implement newly added CGColor Apis #2614,
    The current changes, which touch CoreGraphics, help remove the dependencies CoreGraphics.UnitTests & CoreGraphics.DrawingTests had on UIKit. CoreGraphics.UnitTests & CoreGraphics.DrawingTests pass.

fixes #2243, #2524

return _id;
}

__CGColor(CGColorSpaceRef colorspace, CGFloat r, CGFloat g, CGFloat b, CGFloat alpha) : _colorSpace(colorspace), _pattern(nullptr) {
Copy link

@DHowett-MSFT DHowett-MSFT Apr 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can struct-initialize components to remove the constructor body here #Resolved

}

// CreateCopyWithAlpha
__CGColor(CGColorRef color, float alpha) : _colorSpace(color->_colorSpace), _pattern(color->_pattern) {
Copy link

@DHowett-MSFT DHowett-MSFT Apr 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might like to make this more like a copy constructor and take const __CGColor& #Resolved

_components.a = alpha;
}

__CGColor(CGColorSpaceRef colorSpace, CGPatternRef pattern) : _colorSpace(colorSpace), _pattern(pattern) {
Copy link

@DHowett-MSFT DHowett-MSFT Apr 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whack some TODOs in here about support components #Resolved

}

bool operator==(const __CGColor& other) const {
RETURN_FALSE_IF(isPatternColor() != other.isPatternColor());
Copy link

@DHowett-MSFT DHowett-MSFT Apr 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my word, these macros generate an explosion of branches #Resolved

return true;
}

inline bool isPatternColor() const {
Copy link

@DHowett-MSFT DHowett-MSFT Apr 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this is the only one that's lowercase? #Resolved

Copy link

@DHowett-MSFT DHowett-MSFT Apr 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it private? #Resolved

[static_cast<UIColor*>(ret) setColorSpace:colorSpace];
return ret;
}
RETURN_NULL_IF(CGColorSpaceGetNumberOfComponents(colorSpace) == 0);
Copy link

@DHowett-MSFT DHowett-MSFT Apr 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will a colorspace with an RGB or Monochrome model ever have 0? #ByDesign

Copy link
Contributor Author

@msft-Jeyaram msft-Jeyaram Apr 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if colorspacemodel is unimplemented.
#ByDesign

Copy link
Contributor

@rajsesh rajsesh Apr 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is extraneous check. The switch statement below will suffice. #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kCGColorSpaceModelUnknown would do.


In reply to: 113351799 [](ancestors = 113351799)

return ((components1->r == components2->r) && (components1->g == components2->g) && (components1->b == components2->b) &&
(components1->a == components2->a)) &&
(CGColorSpaceGetModel(CGColorGetColorSpace(color1)) == CGColorSpaceGetModel(CGColorGetColorSpace(color2)));
RETURN_RESULT_IF(color1 == color2, true);
Copy link

@DHowett-MSFT DHowett-MSFT Apr 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CF takes care of ==, but not NULL #ByDesign

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

early return would void the call into CFEqual


In reply to: 111798718 [](ancestors = 111798718)

}

/**
@Status Caveat
@Notes Limited support for colorspace
*/
size_t CGColorGetNumberOfComponents(CGColorRef color) {
return CGColorSpaceGetNumberOfComponents(CGColorGetColorSpace(color)) + 1;
return CGColorSpaceGetNumberOfComponents(color->ColorSpace()) + 1;
Copy link

@DHowett-MSFT DHowett-MSFT Apr 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: seems like not the most necessary change #ByDesign

Copy link
Contributor Author

@msft-Jeyaram msft-Jeyaram Apr 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm +2 calls vs +1.
actually -1 since it's inlined #ByDesign

Copy link
Contributor

@aballway aballway Apr 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't test for a null color #Resolved

return __CGColor::GetTypeID();
}

#pragma region InternalHelpers
Copy link

@DHowett-MSFT DHowett-MSFT Apr 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: regions can be named in normal english #Resolved


#pragma region InternalHelpers

CGColorRef _CGColorCreateWithComponents(CGColorSpaceRef colorspace, CGFloat r, CGFloat g, CGFloat b, CGFloat alpha) {
Copy link

@DHowett-MSFT DHowett-MSFT Apr 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is an incompatible concept. you can't provide a generic colorspace and then require r/g/b/a.

Please reimplement callers in terms of CGColorCreate or CGColorCreateGenericRGB #Resolved

Copy link
Contributor Author

@msft-Jeyaram msft-Jeyaram Apr 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CGColorCreateGenericRGB now how did I forget about that :(
this will allow us to add the missing apis #Resolved

Copy link
Contributor

@aballway aballway left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit: for this half of the change 😸

}

bool operator==(const __CGColor& other) const {
RETURN_FALSE_IF(isPatternColor() != other.isPatternColor());
Copy link
Contributor

@aballway aballway Apr 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this should be unneeded since you already compare _pattern, #Resolved


bool operator==(const __CGColor& other) const {
RETURN_FALSE_IF(isPatternColor() != other.isPatternColor());
RETURN_FALSE_IF(CGColorSpaceGetModel(_colorSpace) != CGColorSpaceGetModel(other._colorSpace));
Copy link
Contributor

@aballway aballway Apr 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: would it be worth adding a CFEqual for CGColorSpace? #WontFix

RETURN_FALSE_IF(isPatternColor() != other.isPatternColor());
RETURN_FALSE_IF(CGColorSpaceGetModel(_colorSpace) != CGColorSpaceGetModel(other._colorSpace));
RETURN_FALSE_IF(_pattern != other._pattern);
RETURN_FALSE_IF(_components.r != other._components.r);
Copy link
Contributor

@aballway aballway Apr 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add an operator== for __CGColorQuad? #Resolved

return __CGColor::CreateInstance(kCFAllocatorDefault, colorSpace, pattern);
}

CGColorRef __CreateBlackColor() {
Copy link
Contributor

@aballway aballway Apr 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could just inline these in CGColorGetConstantColor and share a static colorspace #Resolved

return __CGColor::CreateInstance(kCFAllocatorDefault, colorSpace, components[0], components[0], components[0], components[1]);
default:
UNIMPLEMENTED_WITH_MSG("Colorspace Unsupported. Model: %d", model);
return nullptr;
Copy link
Contributor

@aballway aballway Apr 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extraneous return #Resolved

return ((components1->r == components2->r) && (components1->g == components2->g) && (components1->b == components2->b) &&
(components1->a == components2->a)) &&
(CGColorSpaceGetModel(CGColorGetColorSpace(color1)) == CGColorSpaceGetModel(CGColorGetColorSpace(color2)));
RETURN_RESULT_IF(color1 == color2, true);
Copy link
Contributor

@aballway aballway Apr 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this case is handled by CFEqual #ByDesign

CGFloat g;
CGFloat b;
CGFloat a;
} __CGColorQuad;
Copy link
Contributor

@aballway aballway Apr 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is this being used outside of CGColor? #ByDesign

Copy link
Contributor Author

@msft-Jeyaram msft-Jeyaram Apr 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in UIKit #ByDesign

}

bool operator==(const __CGColor& other) const {
if ((CGColorSpaceGetModel(_colorSpace) != CGColorSpaceGetModel(other._colorSpace)) || (_pattern != other._pattern) ||
Copy link
Contributor

@aballway aballway Apr 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: return _ == _ && #Resolved

Copy link
Contributor

@aballway aballway Apr 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is still unresolved #Resolved

CGFloat a;

bool operator==(const __CGColorQuad& other) const {
if ((r != other.r) || (g != other.g) || (b != other.b) || (a != other.a)) {
Copy link
Contributor

@aballway aballway Apr 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: return _ == other._ && ... #Resolved

@@ -74,6 +75,8 @@ LIBRARY CoreGraphics
CGColorGetPattern
CGColorGetTypeID
CGColorGetConstantColor
CGColorCreateGenericRGB
Copy link
Contributor

@aballway aballway Apr 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 #ByDesign

@@ -40,3 +40,5 @@ COREGRAPHICS_EXPORT size_t CGColorGetNumberOfComponents(CGColorRef color);
COREGRAPHICS_EXPORT const CGFloat* CGColorGetComponents(CGColorRef color);
COREGRAPHICS_EXPORT CGPatternRef CGColorGetPattern(CGColorRef color);
COREGRAPHICS_EXPORT CFTypeID CGColorGetTypeID();
COREGRAPHICS_EXPORT CGColorRef CGColorCreateGenericRGB(CGFloat red, CGFloat green, CGFloat blue, CGFloat alpha);
Copy link
Contributor

@aballway aballway Apr 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like there are a couple other CGColor functions which aren't in here like CGColorCreateCopyByMatchingToColorSpace #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be done by an extra issue.


In reply to: 112492607 [](ancestors = 112492607)

Copy link
Contributor

@aballway aballway Apr 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should add the issue number here then, or at least add declaration so it gets tracked as STUB api #Resolved

return __CGColor::CreateInstance(kCFAllocatorDefault, colorSpace, pattern);
}

static inline CGColorRef __CreateBlackColor() {
Copy link
Contributor

@aballway aballway Apr 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could just inline these in CGColorGetConstantColor and share a static colorspace #Resolved

@msft-Jeyaram
Copy link
Contributor Author

msft-Jeyaram commented Apr 21, 2017

@DHowett-MSFT @aballway ping #ByDesign

@msft-Jeyaram
Copy link
Contributor Author

msft-Jeyaram commented Apr 25, 2017

@DHowett-MSFT @aballway @MSFTFox Ping #ByDesign

#endif
#endif

hsv rgb2hsv(rgb in) {
Copy link
Contributor Author

@msft-Jeyaram msft-Jeyaram Apr 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the below two are just moved. These are from the earlier implementation.

}

bool operator==(const __CGColor& other) const {
if ((CGColorSpaceGetModel(_colorSpace) != CGColorSpaceGetModel(other._colorSpace)) || (_pattern != other._pattern) ||
Copy link
Contributor

@aballway aballway Apr 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is still unresolved #Resolved

}

/**
@Status Caveat
@Notes Limited support for colorspace
*/
size_t CGColorGetNumberOfComponents(CGColorRef color) {
return CGColorSpaceGetNumberOfComponents(CGColorGetColorSpace(color)) + 1;
return CGColorSpaceGetNumberOfComponents(color->ColorSpace()) + 1;
Copy link
Contributor

@aballway aballway Apr 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't test for a null color #Resolved

#include "UIKit/UIColor.h"
#include "UIColorInternal.h"
#include "UIKit/NSValue+UIKitAdditions.h"
#include <UIKit/UIApplication.h>
Copy link
Contributor

@aballway aballway Apr 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: consistent on import/include #Resolved

@@ -1570,9 +1568,9 @@ - (CATransform3D)sublayerTransform {
*/
- (void)setBackgroundColor:(CGColorRef)color {
if (color != nil) {
priv->backgroundColor = *[static_cast<UIColor*>(color) _getColors];
priv->backgroundColor = *(reinterpret_cast<const __CGColorQuad*>(CGColorGetComponents(color)));
Copy link
Contributor

@aballway aballway Apr 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

! this feels super unsafe! just construct a __CGColorQuad if you need this #ByDesign

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is with the knowledge of transparent information.
the backing of CGColorGetComponents are a quad struct. Another way is to have a private getter or just take it out of the Quad struct and put it into another Quad struct.


In reply to: 113286126 [](ancestors = 113286126)

Copy link
Contributor

@aballway aballway Apr 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already assigning into a new struct, so it wouldn't be costly to take the extra safety of constructing a __CGColorQuad with the pointer and moving it #Resolved

Copy link
Contributor

@aballway aballway Apr 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also _backgroundColor is a CGColorRef, so I'm not sure what this is doing. We should probably just purge QuartzCore of UIColor and __CGColorQuad since they're not the same #ByDesign

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is not the scope of this PR.The main purpose to detangle CGColor<->UIColor dependencies
We should do that at some point, Raj could weight in on the priority of this.


In reply to: 113504346 [](ancestors = 113504346)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not eh


In reply to: 113503612 [](ancestors = 113503612)

@@ -1583,7 +1581,7 @@ - (void)setBackgroundColor:(CGColorRef)color {
// is updated almost immediately.By setting the priv->background first,
// we can ensure both states are kept in sync which is useful when performing
// automated testing.
[CATransaction _setPropertyForLayer:self name:@"backgroundColor" value:(NSObject*)color];
[CATransaction _setPropertyForLayer:self name:@"backgroundColor" value:(NSObject*)[UIColor colorWithCGColor:color]];
Copy link
Contributor

@aballway aballway Apr 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QuartzCore shouldn't use UIColor #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider them dead


In reply to: 113286201 [](ancestors = 113286201)

[coder encodeFloat:_components.g forKey:@"UIGreen"];
[coder encodeFloat:_components.b forKey:@"UIBlue"];
[coder encodeFloat:_components.a forKey:@"UIAlpha"];
+ (UIColor*)colorWithWhite:(float)gray alpha:(float)alpha {
Copy link
Contributor

@aballway aballway Apr 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be CGFloats #Resolved

static UIColor* color = [_UICachedColor colorWithRed:0.25f green:0.25f blue:0.25f alpha:1.0f];
return color;
- (instancetype)initWithHue:(float)h saturation:(float)s brightness:(float)v alpha:(float)a {
return NSInvalidAbstractInvocationReturn();
Copy link
Contributor

@aballway aballway Apr 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need to be NSIAIR? #ByDesign

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it's our own implementation.


In reply to: 113287177 [](ancestors = 113287177)


return YES;
+ (UIColor*)orangeColor {
static UIColor* color = [UIColor colorWithRed:1.0f green:0.5f blue:0.0f alpha:1.0f];
Copy link
Contributor

@aballway aballway Apr 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could these be stuck in a StrongId so they get unloaded w/ the module... or something like that #Resolved

@@ -146,7 +146,7 @@ - (instancetype)initWithFrame:(CGRect)pos {

[super initWithFrame:pos];

[[self layer] setBackgroundColor:(CGColorRef)[UIColor whiteColor]];
[[self layer] setBackgroundColor:[[UIColor whiteColor] CGColor]];
Copy link
Contributor

@aballway aballway Apr 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use CGConstantColor directly #Resolved

@@ -132,7 +132,7 @@ static inline bool shouldUseConcreteClass(Class self, Class base, Class derived)

// Helper macro for implementing allocWithZone
#define ALLOC_PROTOTYPE_SUBCLASS_WITH_ZONE(NSBridgedType, NSBridgedPrototypeType) \
(NSObject*) allocWithZone : (NSZone*)zone { \
(NSObject*)allocWithZone : (NSZone*)zone { \
Copy link
Contributor

@aballway aballway Apr 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: revert this file #WontFix

Copy link
Contributor

@ms-jihua ms-jihua Apr 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would like to +1 this: formatting-only changes like this clutter up git history and make it harder to figure out when a regression might've occurred #ByDesign

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

separated out commits are wonderful though


In reply to: 113529420 [](ancestors = 113529420)

@msft-Jeyaram
Copy link
Contributor Author

@DHowett-MSFT @aballway @MSFTFox Ping

@DHowett-MSFT
Copy link

When you merge this, I would like to see it squashed into two separate commits -- one for CGColor, and one for UIColor.


#pragma region Inits

@implementation UIColorPrototype {
Copy link

@DHowett-MSFT DHowett-MSFT Apr 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you will want to name this _UIColorConcrete; it's not a prototype #Resolved

Copy link

@DHowett-MSFT DHowett-MSFT Apr 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in fact, you have combined the prototype and the non-prototype #Resolved

Copy link

@DHowett-MSFT DHowett-MSFT Apr 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's actually really quite bad; the prototype is a singleton (!!!!) #Resolved

@DHowett-MSFT
Copy link

DHowett-MSFT commented Apr 25, 2017

oh! this could be very important later.

Please annotate -[UIColor CGColor] in the header with NS_RETURNS_INNER_POINTER!

This is a hint to ARC that the return value from that method may become invalid if the owning object gets released. #Resolved

if (CFEqual(kCGColorBlack, name)) {
ret = static_cast<CGColorRef>([[__LazyUIColor blackColor] CGColor]);
static woc::StrongCF<CGColorRef> s_black{ woc::TakeOwnership, CGColorCreateGenericGray(0.0f, 1.0f) };
Copy link
Contributor

@aballway aballway Apr 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the color space of these on the reference platform? #ByDesign

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grayspace


In reply to: 113502948 [](ancestors = 113502948)

}

bool operator==(const __CGColor& other) const {
return (CGColorSpaceGetModel(_colorSpace) == CGColorSpaceGetModel(other._colorSpace)) && (_pattern == other._pattern) &&
Copy link
Contributor

@aballway aballway Apr 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how will the reference platform handle the same color in different color spaces? #ByDesign

Copy link
Contributor

@aballway aballway Apr 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: would still like a CFEqual implementation for CGColorSpace for this #WontFix

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's not the scope of this PR. What we have is sufficient.


In reply to: 113503142 [](ancestors = 113503142)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean by handle?
so far we only support RGB and Grayscale.
so you are limited to RGBColspace:{r,g,b,alpha} and GrayScaleColSpace:{gray,alpha}


In reply to: 113503071 [](ancestors = 113503071)

Copy link
Contributor

@aballway aballway Apr 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like if there is RBG(.5, .5, .5, 1) and Gray(.5, 1) will the reference platform consider them the same color? #ByDesign

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, but the colorspace is still different if you are asking if it optimizes, nope.


In reply to: 113512713 [](ancestors = 113512713)

@@ -1570,9 +1568,9 @@ - (CATransform3D)sublayerTransform {
*/
- (void)setBackgroundColor:(CGColorRef)color {
if (color != nil) {
priv->backgroundColor = *[static_cast<UIColor*>(color) _getColors];
priv->backgroundColor = *(reinterpret_cast<const __CGColorQuad*>(CGColorGetComponents(color)));
Copy link
Contributor

@aballway aballway Apr 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already assigning into a new struct, so it wouldn't be costly to take the extra safety of constructing a __CGColorQuad with the pointer and moving it #Resolved

@@ -1570,9 +1568,9 @@ - (CATransform3D)sublayerTransform {
*/
- (void)setBackgroundColor:(CGColorRef)color {
if (color != nil) {
priv->backgroundColor = *[static_cast<UIColor*>(color) _getColors];
priv->backgroundColor = *(reinterpret_cast<const __CGColorQuad*>(CGColorGetComponents(color)));
Copy link
Contributor

@aballway aballway Apr 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also _backgroundColor is a CGColorRef, so I'm not sure what this is doing. We should probably just purge QuartzCore of UIColor and __CGColorQuad since they're not the same #ByDesign

: _colorSpace(colorspace), _pattern(nullptr), _components{ r, g, b, alpha } {
}

__CGColor(CGColorSpaceRef colorSpace, CGPatternRef pattern) : _colorSpace(colorSpace), _pattern(pattern) {
Copy link
Contributor

@rajsesh rajsesh Apr 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_components uninitialized. #Resolved

return _components.a;
}

inline CGColorSpaceRef ColorSpace() const {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: when you are returning Ref, it is not const, so the method can't be const.

[static_cast<UIColor*>(ret) setColorSpace:colorSpace];
return ret;
}
RETURN_NULL_IF(CGColorSpaceGetNumberOfComponents(colorSpace) == 0);
Copy link
Contributor

@rajsesh rajsesh Apr 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is extraneous check. The switch statement below will suffice. #Resolved

static const wchar_t* TAG = L"UIColor";

#if defined(WIN32) || defined(WINPHONE)
int isnan(double x) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eh? do we need all this stuff?

Copy link
Contributor

@ms-jihua ms-jihua left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to separate the prototype and concrete, as has been noted.

} else if (CFEqual(kCGColorClear, name)) {
ret = static_cast<CGColorRef>([[__LazyUIColor clearColor] CGColor]);
static woc::StrongCF<CGColorRef> s_clear{ woc::TakeOwnership, CGColorCreateGenericGray(0.0f, 0.0f) };
return s_clear;
} else {
Copy link
Contributor

@ms-jihua ms-jihua Apr 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can drop the 'else' here #Resolved

@@ -132,7 +132,7 @@ static inline bool shouldUseConcreteClass(Class self, Class base, Class derived)

// Helper macro for implementing allocWithZone
#define ALLOC_PROTOTYPE_SUBCLASS_WITH_ZONE(NSBridgedType, NSBridgedPrototypeType) \
(NSObject*) allocWithZone : (NSZone*)zone { \
(NSObject*)allocWithZone : (NSZone*)zone { \
Copy link
Contributor

@ms-jihua ms-jihua Apr 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would like to +1 this: formatting-only changes like this clutter up git history and make it harder to figure out when a regression might've occurred #ByDesign


- (CGColorSpaceRef)colorSpace {
return _colorSpace;
+ (BOOL)supportsSecureCoding {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

brownie points (and actual brownies) if you implement the coding stubs.

Copy link
Contributor

@ms-jihua ms-jihua Apr 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait are there actual brownies at the office today?? am i missing out? #ByDesign

+ (UIColor*)groupTableViewBackgroundColor {
return [self colorWithRed:197.f / 255.f green:204.f / 255.f blue:210.f / 255.f alpha:1.0f];
+ (UIColor*)brownColor {
static UIColor* color = [UIColor colorWithRed:0.65f green:0.35f blue:0.0f alpha:1.0f];
Copy link
Contributor

@rajsesh rajsesh Apr 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these statics should be strong ids. #Resolved

@msft-Jeyaram
Copy link
Contributor Author

Ping!

@@ -1090,7 +1090,7 @@ - (void)dealloc {

- (void)_addBottomBorder:(UITableView*)parentTable {
if (_borderView == nil) {
const __CGColorQuad* color = [[parentTable backgroundColor] _getColors];
const __CGColorQuad* color = reinterpret_cast<const __CGColorQuad*>(CGColorGetComponents([[parentTable backgroundColor] CGColor]));
Copy link
Contributor Author

@msft-Jeyaram msft-Jeyaram Apr 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reinterpret_cast<const __CGColorQuad*> [](start = 37, length = 38)

changing this #Resolved

return [UIColor colorWithCGColor:color];
}

+ (UIColor*)colorWithColor:(UIColor*)copyclr {
Copy link
Contributor

@ms-jihua ms-jihua Apr 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't seem to be used anywhere, and isn't a part of the docs. let's get rid of it (if we do need it for some reason, it seems like [[copyclr copy] autorelease] would be the more sensical return value?) #Resolved

@@ -1567,7 +1567,8 @@ - (CATransform3D)sublayerTransform {
*/
- (void)setBackgroundColor:(CGColorRef)color {
if (color != nil) {
priv->backgroundColor = *(reinterpret_cast<const __CGColorQuad*>(CGColorGetComponents(color)));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: consider adding a todo here, because this assumes a 4-component color space!

@@ -138,10 +147,6 @@ - (UIColor*)colorWithAlphaComponent:(CGFloat)alpha {
return NSInvalidAbstractInvocationReturn();
}

+ (UIColor*)colorWithColor:(UIColor*)copyclr {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this not an API that exists?

This will help represent the component values of colors with respect to their colorspace
- Implement CGColor backed by RGBA values
     - This would support Grayscale by only using a {gray,gray,gray,alpha} value vs {r,g,b,a}
- Support RGBA and Grayscale colorspace
- Implement via runtime base
- Implement CGColorGetPattern
- Removed Lazy loading of UIColor
- Removed dependency on UIColor
- Properly implemented CGColorEqualToColor
Fixes microsoft#2243
- Implemented CGColorSpaceCreateDeviceRGB and CGColorSpaceCreateDeviceGray
- Added Unittests for the functions
Fixes microsoft#2614
Copy link
Contributor

@aballway aballway left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would still like the unrelated file reverted

- This supports proper class clustering for UIColor.
- Implement UIColor as a class cluster
- Support singleton const color
- Support for getRed&getWhite Apis to respect colorspace
- Removed direct access of internal structs
- Removed unnecessary functionality
- Improve Code quality

Fixes microsoft#2524, microsoft#2243
The test was attempting to create a Grayscale color as an RGBA color and compare it with a Grayscale color.
This validation makes sure that the colors are compared per component.
Note: This is due to the fact that Color's are represented as RGB in Windows OS.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement CGColor independent of UIColor
6 participants