Followup fix to T39966.

The previous fix was not quite correct:
* It would use the same wireframe/bbox check in viewport- and regular render
* The duplicator loop in Blender Internal is more permissive now to avoid disabling wireframe duplicators, but this means we need to check is_object_hidden right before making render objects to ensure this still works.
Fix T40049: cycles baking glossy shader looks faceted.

Use smooth normal instead of flat normal as view direction.
Fix possible NULL pointer dereference in Cycles
Cleanup: redundant NULL checks
Style cleanup
Fix issue discovered while investigating T39950:

Sculpt mode drawing fails after deleting a subsurf modifier
in sculpt mode and undoing.

This was quite difficult to spot. Main cause was that mesh data was not
synchronized properly between undo and sculpt code because we generated
a pbvh on derivedmesh invalidation without really refreshing the rest of
the data. This could result in undo and drawing operating on different
data.

To solve this and avoid bad level calls I had to move quite some code
around. Crazyspace is now moved to blenkernel, as did some sculpt calls
that make sure sculpt data are properly refreshed.
Bake API: fix T40054 - baked image update on uv/imag editor for linear/float/noncolor, ...

All image colorspaces should be displaying correctly in the UV/Image Editor.

Viewport may still present an issue, but it was reported separately
anyways (T40055)

Patch reviewed (and corrected) by Sergey Sharybin
Bake API: force opengl reload and mipmap recalc (fix T40055)
Fix T39653 crash on drawing modified UVs

Just a case of uninitialized material array.
Make sure object materials are initialized properly when drawing UVs.

This might look strange since we do not really need materials here.
However, the same GPU object may be used in a 3D viewport and if we try
to avoid initializing the materials somehow this will break.

Also, this breaks on full screen UV editor as is apparent from this
report.
Code cleanup: naming.

Prepend BKE_ to the functions moved in blenkernel for recent bug fix.