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

Cleaning up internal headers and moving CGImage implementation to sou… #1430

Merged
merged 1 commit into from
Nov 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
184 changes: 182 additions & 2 deletions Frameworks/CoreGraphics/CGImage.mm
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,187 @@ COREGRAPHICS_EXPORT void CGImageAddDestructionListener(CGImageDestructionListene

#pragma endregion OLD_CODE
Copy link

@DHowett-MSFT DHowett-MSFT Nov 19, 2016

Choose a reason for hiding this comment

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

How much of this OLD_CODE is still necessary? #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's pretty much the old code. given compositor uses this to release the textured images, we need a support for this.
After the refactor it can be simplified.


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


#pragma region CGImageImplementation

struct __CGImageImpl {
Copy link

@DHowett-MSFT DHowett-MSFT Nov 19, 2016

Choose a reason for hiding this comment

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

While you're doing this, how do you feel about getting rid of Impl? #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.

WIP, I though of just pushing this through for now and send that out later. Given I don't think i'll have that out till Monday.


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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually maybe not monday, tomorrow.


In reply to: 88774125 [](ancestors = 88774125,88774084)

Microsoft::WRL::ComPtr<IWICBitmap> bitmapImageSource;
bool isMask;
bool interpolate;
woc::unique_cf<CGColorSpaceRef> colorSpace;
CGImageAlphaInfo alphaInfo;
size_t height;
size_t width;
size_t bitsPerPixel;
size_t bitsPerComponent;
size_t bytesPerRow;
CGBitmapInfo bitmapInfo;
CGColorRenderingIntent renderingIntent;

__CGImageImpl() {
height = 0;
width = 0;
bitsPerComponent = 0;
bitsPerPixel = 0;
bytesPerRow = 0;
bitmapInfo = kCGBitmapByteOrderDefault;
alphaInfo = kCGImageAlphaNone;
isMask = false;
interpolate = false;
renderingIntent = kCGRenderingIntentDefault;
}

inline WICPixelFormatGUID PixelFormat() const {
WICPixelFormatGUID pixelFormat;
RETURN_RESULT_IF_FAILED(bitmapImageSource->GetPixelFormat(&pixelFormat), GUID_WICPixelFormatUndefined);
return pixelFormat;
}

inline const __CGImagePixelProperties* Properties() const {
WICPixelFormatGUID pixelFormat = PixelFormat();
return _CGGetPixelFormatProperties(pixelFormat);
}

inline size_t BitsPerPixel() const {
const __CGImagePixelProperties* properties = Properties();
RETURN_RESULT_IF_NULL(properties, 0);
return properties->bitsPerPixel;
}

inline size_t BitsPerComponent() const {
const __CGImagePixelProperties* properties = Properties();
RETURN_RESULT_IF_NULL(properties, 0);
return properties->bitsPerComponent;
}

inline CGBitmapInfo BitmapInfo() const {
const __CGImagePixelProperties* properties = Properties();
RETURN_RESULT_IF_NULL(properties, 0);
return properties->bitmapInfo;
}

inline CGImageAlphaInfo AlphaInfo() const {
return static_cast<CGImageAlphaInfo>(BitmapInfo() & kCGBitmapAlphaInfoMask);
}

inline CGColorSpaceRef ColorSpace() {
const __CGImagePixelProperties* properties = Properties();
RETURN_NULL_IF(!properties);
return _CGColorSpaceCreate(properties->colorSpaceModel);
}

inline void SetImageSource(Microsoft::WRL::ComPtr<IWICBitmap> source) {
bitmapImageSource = std::move(source);
// populate the image info.
if (FAILED(bitmapImageSource->GetSize(&width, &height))) {
height = 0;
width = 0;
}

bitmapInfo = BitmapInfo();
alphaInfo = AlphaInfo();
bitsPerPixel = BitsPerPixel();
bitsPerComponent = BitsPerComponent();
bytesPerRow = (bitsPerPixel >> 3) * width;
if (!colorSpace) {
colorSpace.reset(ColorSpace());
}
}
};

struct __CGImage : CoreFoundation::CppBase<__CGImage> {
// TODO(JJ) REMOVE THIS; Merge Impl into __CGImage.
__CGImageImpl _impl;

inline Microsoft::WRL::ComPtr<IWICBitmap>& ImageSource() {
return _impl.bitmapImageSource;
}

inline void* Data() const {
Microsoft::WRL::ComPtr<IWICBitmapLock> lock;
RETURN_NULL_IF_FAILED(_impl.bitmapImageSource->Lock(nullptr, WICBitmapLockWrite, &lock));
BYTE* data;
UINT size;
RETURN_NULL_IF_FAILED(lock->GetDataPointer(&size, &data));
return static_cast<void*>(data);
}

inline size_t Height() const {
return _impl.height;
}

inline size_t Width() const {
return _impl.width;
}

inline bool IsMask() const {
return _impl.isMask;
}

inline bool Interpolate() const {
return _impl.interpolate;
}

inline CGColorSpaceRef ColorSpace() {
return _impl.colorSpace.get();
}

inline CGColorRenderingIntent RenderingIntent() const {
return _impl.renderingIntent;
}

inline CGBitmapInfo BitmapInfo() const {
return _impl.bitmapInfo;
}

inline CGImageAlphaInfo AlphaInfo() const {
return _impl.alphaInfo;
}

inline size_t BitsPerPixel() const {
return _impl.bitsPerPixel;
}

inline size_t BytesPerRow() const {
return _impl.bytesPerRow;
}

inline size_t BitsPerComponent() const {
return _impl.bitsPerComponent;
}

inline WICPixelFormatGUID PixelFormat() const {
return _impl.PixelFormat();
}

inline __CGImage& SetImageSource(Microsoft::WRL::ComPtr<IWICBitmap> source) {
_impl.SetImageSource(source);
return *this;
}

inline __CGImage& SetIsMask(bool mask) {
_impl.isMask = mask;
return *this;
}

inline __CGImage& SetInterpolate(bool interpolate) {
_impl.interpolate = interpolate;
return *this;
}

inline __CGImage& SetColorSpace(CGColorSpaceRef space) {
_impl.colorSpace.reset(space);
CGColorSpaceRetain(space);
return *this;
}

inline __CGImage& SetRenderingIntent(CGColorRenderingIntent intent) {
_impl.renderingIntent = intent;
return *this;
}
};

#pragma endregion CGImageImplementation

/**
@Status Interoperable
*/
Expand Down Expand Up @@ -346,8 +527,7 @@ CGImageRef CGImageCreateCopyWithColorSpace(CGImageRef ref, CGColorSpaceRef color
@Status Stub
*/
CGImageRef CGImageCreateWithMask(CGImageRef image, CGImageRef mask) {
// TODO #1124: Given how masks are applied during rendering via D2D, we will hold onto the
// mask then apply it at the appropriate time.
// TODO #1425 - masks are applied during rendering via D2D.
RETURN_NULL_IF(!image);
UNIMPLEMENTED();
return StubReturn();
Expand Down
181 changes: 0 additions & 181 deletions Frameworks/include/CGImageInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
#import <wrl/client.h>
#include <COMIncludes_End.h>

class CGContextImpl;

typedef struct {
CGColorSpaceModel colorSpaceModel;
CGBitmapInfo bitmapInfo;
Expand Down Expand Up @@ -97,185 +95,6 @@ static const std::map<GUID, __CGImagePixelProperties, GuidPixelLess> s_PixelForm
bool _CGIsValidRenderTargetPixelFormat(WICPixelFormatGUID pixelFormat);
const __CGImagePixelProperties* _CGGetPixelFormatProperties(WICPixelFormatGUID pixelFormat);

struct __CGImageImpl {
Microsoft::WRL::ComPtr<IWICBitmap> bitmapImageSource;
bool isMask;
bool interpolate;
woc::unique_cf<CGColorSpaceRef> colorSpace;
CGImageAlphaInfo alphaInfo;
size_t height;
size_t width;
size_t bitsPerPixel;
size_t bitsPerComponent;
size_t bytesPerRow;
CGBitmapInfo bitmapInfo;
CGColorRenderingIntent renderingIntent;

__CGImageImpl() {
height = 0;
width = 0;
bitsPerComponent = 0;
bitsPerPixel = 0;
bytesPerRow = 0;
bitmapInfo = kCGBitmapByteOrderDefault;
alphaInfo = kCGImageAlphaNone;
isMask = false;
interpolate = false;
renderingIntent = kCGRenderingIntentDefault;
}

inline WICPixelFormatGUID PixelFormat() const {
WICPixelFormatGUID pixelFormat;
RETURN_RESULT_IF_FAILED(bitmapImageSource->GetPixelFormat(&pixelFormat), GUID_WICPixelFormatUndefined);
return pixelFormat;
}

inline const __CGImagePixelProperties* Properties() const {
WICPixelFormatGUID pixelFormat = PixelFormat();
return _CGGetPixelFormatProperties(pixelFormat);
}

inline size_t BitsPerPixel() const {
const __CGImagePixelProperties* properties = Properties();
RETURN_RESULT_IF_NULL(properties, 0);
return properties->bitsPerPixel;
}

inline size_t BitsPerComponent() const {
const __CGImagePixelProperties* properties = Properties();
RETURN_RESULT_IF_NULL(properties, 0);
return properties->bitsPerComponent;
}

inline CGBitmapInfo BitmapInfo() const {
const __CGImagePixelProperties* properties = Properties();
RETURN_RESULT_IF_NULL(properties, 0);
return properties->bitmapInfo;
}

inline CGImageAlphaInfo AlphaInfo() const {
return static_cast<CGImageAlphaInfo>(BitmapInfo() & kCGBitmapAlphaInfoMask);
}

inline CGColorSpaceRef ColorSpace() {
const __CGImagePixelProperties* properties = Properties();
RETURN_NULL_IF(!properties);
return _CGColorSpaceCreate(properties->colorSpaceModel);
}

inline void SetImageSource(Microsoft::WRL::ComPtr<IWICBitmap> source) {
bitmapImageSource = std::move(source);
// populate the image info.
if (FAILED(bitmapImageSource->GetSize(&width, &height))) {
height = 0;
width = 0;
}

bitmapInfo = BitmapInfo();
alphaInfo = AlphaInfo();
bitsPerPixel = BitsPerPixel();
bitsPerComponent = BitsPerComponent();
bytesPerRow = (bitsPerPixel >> 3) * width;
if (!colorSpace) {
colorSpace.reset(ColorSpace());
}
}
};

struct __CGImage : CoreFoundation::CppBase<__CGImage> {
// TODO(JJ) REMOVE THIS; Merge Impl into __CGImage.
__CGImageImpl _impl;

inline Microsoft::WRL::ComPtr<IWICBitmap>& ImageSource() {
return _impl.bitmapImageSource;
}

inline void* Data() const {
Microsoft::WRL::ComPtr<IWICBitmapLock> lock;
RETURN_NULL_IF_FAILED(_impl.bitmapImageSource->Lock(nullptr, WICBitmapLockWrite, &lock));
BYTE* data;
UINT size;
RETURN_NULL_IF_FAILED(lock->GetDataPointer(&size, &data));
return static_cast<void*>(data);
}

inline size_t Height() const {
return _impl.height;
}

inline size_t Width() const {
return _impl.width;
}

inline bool IsMask() const {
return _impl.isMask;
}

inline bool Interpolate() const {
return _impl.interpolate;
}

inline CGColorSpaceRef ColorSpace() {
return _impl.colorSpace.get();
}

inline CGColorRenderingIntent RenderingIntent() const {
return _impl.renderingIntent;
}

inline CGBitmapInfo BitmapInfo() const {
return _impl.bitmapInfo;
}

inline CGImageAlphaInfo AlphaInfo() const {
return _impl.alphaInfo;
}

inline size_t BitsPerPixel() const {
return _impl.bitsPerPixel;
}

inline size_t BytesPerRow() const {
return _impl.bytesPerRow;
}

inline size_t BitsPerComponent() const {
return _impl.bitsPerComponent;
}

inline WICPixelFormatGUID PixelFormat() const {
return _impl.PixelFormat();
}

inline __CGImage& SetImageSource(Microsoft::WRL::ComPtr<IWICBitmap> source) {
_impl.SetImageSource(source);
return *this;
}

inline __CGImage& SetIsMask(bool mask) {
_impl.isMask = mask;
return *this;
}

inline __CGImage& SetInterpolate(bool interpolate) {
_impl.interpolate = interpolate;
return *this;
}

inline __CGImage& SetColorSpace(CGColorSpaceRef space) {
_impl.colorSpace.reset(space);
CGColorSpaceRetain(space);
return *this;
}

inline __CGImage& SetRenderingIntent(CGColorRenderingIntent intent) {
_impl.renderingIntent = intent;
return *this;
}
};

//--Helpers--

COREGRAPHICS_EXPORT CGImageRef _CGImageLoadGIF(void* bytes, int length);

COREGRAPHICS_EXPORT CGImageRef _CGImageLoadBMP(void* bytes, size_t length);
Expand Down