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

UI Image fixes #636

Merged
merged 9 commits into from
Jul 25, 2016
Merged

Conversation

shahmeeresmail
Copy link
Contributor

@shahmeeresmail shahmeeresmail commented Jul 12, 2016

Fixes graphical corruption in UI elements (examples: UIDatePicker, UISegmentControl) resulting in a checkerboard pattern being drawn and optimized patched draw function. The corruption is what is seen in issue #622 and is visible in the Segments and DatePicker sections of WOCCATALOG. This also resolves issue #674 since it implements the use of blendMode and alpha for the various drawAtPoint and drawInRect functions.

Details:

  • Instead of creating a pattern and calling a CB function (drawNinePatchCallback) to subdivide image into patches and draw individually, the change was made to just call a function which subdivides the images into patches and draws (drawPatches)
  • Insets improperly scaled in many places
  • drawPatches optimized to subdivide the image into the smallest number of patches to reduce draw setup and state management overhead
  • Depending on what insets are set, 1-9 patched draws may be needed. Optimized drawPatches function to do 1 to 9 draws instead of 3 to 9 draws (effectively reducing min draws from 3 to 1) and minimize the number of draws used.
  • Make makeRect and drawPatches functions inline

Shahmeer Esmail added 2 commits July 11, 2016 15:48
…ges with imageCaps:

- drawNinePatchCallback renamed to drawPatches
- Instead of creating a pattern and calling a CB function (drawNinePatchCallback) to subdivide image into patches and draw individually, the change was made to just call a function which subdivides the images into patches and draws (drawPatches)
- Insets improperly scaled in many places
- drawPatches optimized to subdivide the image into the smallest number of patches to reduce draw setup and state management overhead
- make drawPatches and makeRect inline
makeRect((dst->origin.x + leftCap),
(dst->origin.y + botCap),
(dst->size.width - leftCap - rightCap),
(dst->size.height - topCap - botCap)));
} else {
assert(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

assert(0); [](start = 11, length = 11)

although this is old code, it would be much better to Throw and exception with some information on why this is an issue.
It would provide much more information rather than just asserting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replaced assert with unimplemented_with_msg macro.

@rajsesh
Copy link
Contributor

rajsesh commented Jul 13, 2016

@Ramu-msft is added to the review. #Closed

@rajsesh
Copy link
Contributor

rajsesh commented Jul 13, 2016

@davelamb is added to the review. #Closed

(dst->size.height - topCap - botCap)));
}
} else {
UNIMPLEMENTED_WITH_MSG("Patched draws only supported when sum of topCap and botCap is less than the height of the UI element.");
Copy link
Contributor

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 the case on the reference platform. It seems to draw the caps as a ratio between the cap sizes.

Copy link
Contributor Author

@shahmeeresmail shahmeeresmail Jul 13, 2016

Choose a reason for hiding this comment

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

That's true and this is a pre-existing issue which isn't resolved here. We should create another pull request in the future to address this and maybe even a functional test to make sure the output produced in this scenario matches that of the reference platform.

@davelamb
Copy link
Contributor

We've root caused the crashing issue to a missing call to EMMS (_mm_empty, clears MMX state) and the tiling issue to x/y step size being incorrect in the call to CGPatternCreate. I have a small fix that addresses both these issues that we'd like to push out that shouldn't collide (but for one line) with your change.

@shahmeeresmail shahmeeresmail changed the title Core graphics fixes UI Image fixes Jul 15, 2016
Shahmeer Esmail added 2 commits July 21, 2016 16:50
…os, blendMode, alpha), drawAtPoint(pos), drawAtPoint(pos, blendMode, alpha)

- When alpha and blendMode are not provided in drawRect and drawAtPoint functions, use  values from the current graphics state instead of hardcoded values which force full opacity or transparency and a KCGBlendModeNormal and thus ignoring the app's intentions
- In drawRect/drawAtPoint, set opacity (alpha) as part of draw setup
- Use cairo_paint_with_alpha using the current alpha/opacity state instead of using just cairo_paint
@jaredhms
Copy link
Contributor

}

delete and just call CGRectMake?


Refers to: Frameworks/UIKit/UIImage.mm:948 in 532b33e. [](commit_id = 532b33e, deletion_comment = False)

@jaredhms
Copy link
Contributor

static void drawLeftCap(UIImage* self, CGContextRef cur, CGRect pos) {

Can we delete this?


Refers to: Frameworks/UIKit/UIImage.mm:821 in 532b33e. [](commit_id = 532b33e, deletion_comment = False)

@jaredhms
Copy link
Contributor

static void drawTopCap(UIImage* self, CGContextRef cur, CGRect pos) {

Can we delete this?


Refers to: Frameworks/UIKit/UIImage.mm:883 in 532b33e. [](commit_id = 532b33e, deletion_comment = False)

@jaredhms
Copy link
Contributor

static void drawLeftAndTopCap(UIImage* self, CGContextRef ctx, CGRect rect) {

Can we delete this?


Refers to: Frameworks/UIKit/UIImage.mm:950 in 532b33e. [](commit_id = 532b33e, deletion_comment = False)

@shahmeeresmail
Copy link
Contributor Author

shahmeeresmail commented Jul 22, 2016

I don't see why we can't delete the drawTopCap, drawLeftCap or drawLeftAndTopCap methods. They are unused but I originaly left them alone because I wasn't sure if it was envisioned to use them as part of a future change.

@shahmeeresmail
Copy link
Contributor Author

shahmeeresmail commented Jul 22, 2016

I will also remove makeRect and substitute existing references to it with CGRectMake and make a few small changes to drawInRect(pos) and drawAtPoint(point) functions.

…eRect, removed unused static functions, made changes to drawInRect(pos) and drawAtPoint(pos) so that blendMode and alpha default to normal and 1.0f as per the spec.
srcRect.origin.y = float(getImage(self)->Backing()->Height());
srcRect.size.width = float(getImage(self)->Backing()->Width());
srcRect.size.height = -((float)getImage(self)->Backing()->Height());
srcRect.origin.y = float(imgBacking->Height());
Copy link
Contributor

Choose a reason for hiding this comment

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

float( [](start = 23, length = 6)

nit: it's a bid odd that two of these are constructing a float rather than casting to a float

@jaredhms
Copy link
Contributor

In CI build.

@jaredhms
Copy link
Contributor

:shipit:

@jaredhms jaredhms merged commit a106d3d into microsoft:develop Jul 25, 2016
Ramu-msft added a commit that referenced this pull request Jul 27, 2016
rajsesh pushed a commit that referenced this pull request Aug 2, 2016
…ave the fixes for High-DPI issues ready to merge.

This reverts commit a106d3d.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants