Bug 1338086 - Remove useless else blocks in order to reduce complexity in gfx/ r?nical
MozReview-Commit-ID: H9zZd19V4Ww
--- a/gfx/2d/DrawTargetSkia.cpp
+++ b/gfx/2d/DrawTargetSkia.cpp
@@ -380,22 +380,22 @@ ExtractSubset(sk_sp<SkImage> aImage, con
static inline bool
SkImageIsMask(const sk_sp<SkImage>& aImage)
{
SkPixmap pixmap;
if (aImage->peekPixels(&pixmap)) {
return pixmap.colorType() == kAlpha_8_SkColorType;
#ifdef USE_SKIA_GPU
- } else if (GrTexture* tex = aImage->getTexture()) {
+ }
+ if (GrTexture* tex = aImage->getTexture()) {
return GrPixelConfigIsAlphaOnly(tex->config());
#endif
- } else {
- return false;
}
+ return false;
}
static bool
ExtractAlphaBitmap(const sk_sp<SkImage>& aImage, SkBitmap* aResultBitmap)
{
SkImageInfo info = SkImageInfo::MakeA8(aImage->width(), aImage->height());
SkBitmap bitmap;
if (!bitmap.tryAllocPixels(info, SkAlign4(info.minRowBytes())) ||
--- a/gfx/2d/image_operations.cpp
+++ b/gfx/2d/image_operations.cpp
@@ -188,21 +188,22 @@ ImageOperations::ResizeMethod ResizeMeth
// Resize ----------------------------------------------------------------------
// static
SkBitmap ImageOperations::Resize(const SkBitmap& source,
ResizeMethod method,
int dest_width, int dest_height,
const SkIRect& dest_subset,
void* dest_pixels /* = nullptr */) {
- if (method == ImageOperations::RESIZE_SUBPIXEL)
+ if (method == ImageOperations::RESIZE_SUBPIXEL) {
return ResizeSubpixel(source, dest_width, dest_height, dest_subset);
- else
- return ResizeBasic(source, method, dest_width, dest_height, dest_subset,
- dest_pixels);
+ }
+
+ return ResizeBasic(source, method, dest_width, dest_height, dest_subset,
+ dest_pixels);
}
// static
SkBitmap ImageOperations::ResizeSubpixel(const SkBitmap& source,
int dest_width, int dest_height,
const SkIRect& dest_subset) {
// Currently only works on Linux/BSD because these are the only platforms
// where SkFontLCDConfig::GetSubpixelOrder is defined.
--- a/gfx/gl/SkiaGLGlue.cpp
+++ b/gfx/gl/SkiaGLGlue.cpp
@@ -53,19 +53,18 @@ glGetString_mozilla(GLContext* aContext,
{
// GLContext only exposes a OpenGL 2.0 style API, so we have to intercept a bunch
// of checks that Ganesh makes to determine which capabilities are present
// on the GL implementation and change them to match what GLContext actually exposes.
if (aName == LOCAL_GL_VERSION) {
if (aContext->IsGLES()) {
return reinterpret_cast<const GLubyte*>("OpenGL ES 2.0");
- } else {
- return reinterpret_cast<const GLubyte*>("2.0");
}
+ return reinterpret_cast<const GLubyte*>("2.0");
} else if (aName == LOCAL_GL_EXTENSIONS) {
// Only expose the bare minimum extensions we want to support to ensure a functional Ganesh
// as GLContext only exposes certain extensions
static bool extensionsStringBuilt = false;
static char extensionsString[1024];
if (!extensionsStringBuilt) {
extensionsString[0] = '\0';
@@ -125,19 +124,18 @@ glGetString_mozilla(GLContext* aContext,
#endif
}
return reinterpret_cast<const GLubyte*>(extensionsString);
} else if (aName == LOCAL_GL_SHADING_LANGUAGE_VERSION) {
if (aContext->IsGLES()) {
return reinterpret_cast<const GLubyte*>("OpenGL ES GLSL ES 1.0");
- } else {
- return reinterpret_cast<const GLubyte*>("1.10");
}
+ return reinterpret_cast<const GLubyte*>("1.10");
}
return aContext->fGetString(aName);
}
static GrGLInterface* CreateGrGLInterfaceFromGLContext(GLContext* context)
{
auto *i = new GrGLInterface();
--- a/gfx/layers/LayerTreeInvalidation.cpp
+++ b/gfx/layers/LayerTreeInvalidation.cpp
@@ -778,31 +778,31 @@ LayerPropertiesBase::ComputeDifferences(
{
NS_ASSERTION(aRoot, "Must have a layer tree to compare against!");
if (mLayer != aRoot) {
if (aCallback) {
NotifySubdocumentInvalidation(aRoot, aCallback);
} else {
ClearInvalidations(aRoot);
}
- IntRect result = TransformRect(aRoot->GetLocalVisibleRegion().ToUnknownRegion().GetBounds(),
- aRoot->GetLocalTransform());
+ IntRect result = TransformRect(
+ aRoot->GetLocalVisibleRegion().ToUnknownRegion().GetBounds(),
+ aRoot->GetLocalTransform());
result = result.Union(OldTransformedBounds());
if (aGeometryChanged != nullptr) {
*aGeometryChanged = true;
}
return result;
- } else {
- bool geometryChanged = (aGeometryChanged != nullptr) ? *aGeometryChanged : false;
- nsIntRegion invalid = ComputeChange(" ", aCallback, geometryChanged);
- if (aGeometryChanged != nullptr) {
- *aGeometryChanged = geometryChanged;
- }
- return invalid;
}
+ bool geometryChanged = (aGeometryChanged != nullptr) ? *aGeometryChanged : false;
+ nsIntRegion invalid = ComputeChange(" ", aCallback, geometryChanged);
+ if (aGeometryChanged != nullptr) {
+ *aGeometryChanged = geometryChanged;
+ }
+ return invalid;
}
void
LayerPropertiesBase::MoveBy(const IntPoint& aOffset)
{
mTransform.PostTranslate(aOffset.x, aOffset.y, 0);
}
--- a/gfx/layers/Layers.cpp
+++ b/gfx/layers/Layers.cpp
@@ -665,20 +665,20 @@ const CSSTransformMatrix
Layer::GetTransformTyped() const
{
return ViewAs<CSSTransformMatrix>(GetTransform());
}
Matrix4x4
Layer::GetLocalTransform()
{
- if (HostLayer* shadow = AsHostLayer())
+ if (HostLayer* shadow = AsHostLayer()) {
return shadow->GetShadowTransform();
- else
- return GetTransform();
+ }
+ return GetTransform();
}
const LayerToParentLayerMatrix4x4
Layer::GetLocalTransformTyped()
{
return ViewAs<LayerToParentLayerMatrix4x4>(GetLocalTransform());
}
@@ -1131,20 +1131,18 @@ ContainerLayer::Collect3DContextLeaves(n
(Layer*) this,
[this, &aToSort](Layer* layer)
{
ContainerLayer* container = layer->AsContainerLayer();
if (layer == this || (container && container->Extend3DContext() &&
!container->UseIntermediateSurface())) {
return TraversalFlag::Continue;
}
- else {
- aToSort.AppendElement(layer);
- return TraversalFlag::Skip;
- }
+ aToSort.AppendElement(layer);
+ return TraversalFlag::Skip;
}
);
}
static nsTArray<LayerPolygon>
SortLayersWithBSPTree(nsTArray<Layer*>& aArray)
{
std::deque<LayerPolygon> inputLayers;
--- a/gfx/layers/basic/X11BasicCompositor.cpp
+++ b/gfx/layers/basic/X11BasicCompositor.cpp
@@ -78,42 +78,39 @@ X11DataTextureSourceBasic::AsSourceBasic
}
IntSize
X11DataTextureSourceBasic::GetSize() const
{
if (!mBufferDrawTarget) {
NS_WARNING("Trying to query the size of an uninitialized TextureSource");
return IntSize(0, 0);
- } else {
- return mBufferDrawTarget->GetSize();
}
+ return mBufferDrawTarget->GetSize();
}
gfx::SurfaceFormat
X11DataTextureSourceBasic::GetFormat() const
{
if (!mBufferDrawTarget) {
NS_WARNING("Trying to query the format of an uninitialized TextureSource");
return gfx::SurfaceFormat::UNKNOWN;
- } else {
- return mBufferDrawTarget->GetFormat();
}
+ return mBufferDrawTarget->GetFormat();
}
SourceSurface*
X11DataTextureSourceBasic::GetSurface(DrawTarget* aTarget)
{
RefPtr<gfx::SourceSurface> surface;
if (mBufferDrawTarget) {
surface = mBufferDrawTarget->Snapshot();
return surface.get();
- } else {
- return nullptr;
}
+ return nullptr;
}
void
X11DataTextureSourceBasic::DeallocateDeviceData()
{
mBufferDrawTarget = nullptr;
}
--- a/gfx/thebes/gfxASurface.cpp
+++ b/gfx/thebes/gfxASurface.cpp
@@ -76,21 +76,20 @@ gfxASurface::AddRef(void)
if (mFloatingRefs) {
// eat a floating ref
mFloatingRefs--;
} else {
cairo_surface_reference(mSurface);
}
return (nsrefcnt) cairo_surface_get_reference_count(mSurface);
- } else {
- // the surface isn't valid, but we still need to refcount
- // the gfxASurface
- return ++mFloatingRefs;
}
+ // the surface isn't valid, but we still need to refcount
+ // the gfxASurface
+ return ++mFloatingRefs;
}
nsrefcnt
gfxASurface::Release(void)
{
if (mSurfaceValid) {
NS_ASSERTION(mFloatingRefs == 0, "gfxASurface::Release with floating refs still hanging around!");
@@ -98,24 +97,22 @@ gfxASurface::Release(void)
// which will delete this gfxASurface wrapper when the surface's refcount goes
// out of scope.
nsrefcnt refcnt = (nsrefcnt) cairo_surface_get_reference_count(mSurface);
cairo_surface_destroy(mSurface);
// |this| may not be valid any more, don't use it!
return --refcnt;
- } else {
- if (--mFloatingRefs == 0) {
- delete this;
- return 0;
- }
-
- return mFloatingRefs;
}
+ if (--mFloatingRefs == 0) {
+ delete this;
+ return 0;
+ }
+ return mFloatingRefs;
}
void
gfxASurface::SurfaceDestroyFunc(void *data) {
gfxASurface *surf = (gfxASurface*) data;
// fprintf (stderr, "Deleting wrapper for %p (wrapper: %p)\n", surf->mSurface, data);
delete surf;
}
--- a/gfx/thebes/gfxFcPlatformFontList.cpp
+++ b/gfx/thebes/gfxFcPlatformFontList.cpp
@@ -129,39 +129,47 @@ GetFaceNames(FcPattern* aFont, const nsA
aFullname.Append(' ');
aFullname.Append(style);
}
}
static uint16_t
MapFcWeight(int aFcWeight)
{
- if (aFcWeight <= (FC_WEIGHT_THIN + FC_WEIGHT_EXTRALIGHT) / 2) {
- return 100;
- } else if (aFcWeight <= (FC_WEIGHT_EXTRALIGHT + FC_WEIGHT_LIGHT) / 2) {
- return 200;
- } else if (aFcWeight <= (FC_WEIGHT_LIGHT + FC_WEIGHT_BOOK) / 2) {
- return 300;
- } else if (aFcWeight <= (FC_WEIGHT_REGULAR + FC_WEIGHT_MEDIUM) / 2) {
- // This includes FC_WEIGHT_BOOK
- return 400;
- } else if (aFcWeight <= (FC_WEIGHT_MEDIUM + FC_WEIGHT_DEMIBOLD) / 2) {
- return 500;
- } else if (aFcWeight <= (FC_WEIGHT_DEMIBOLD + FC_WEIGHT_BOLD) / 2) {
- return 600;
- } else if (aFcWeight <= (FC_WEIGHT_BOLD + FC_WEIGHT_EXTRABOLD) / 2) {
- return 700;
- } else if (aFcWeight <= (FC_WEIGHT_EXTRABOLD + FC_WEIGHT_BLACK) / 2) {
- return 800;
- } else if (aFcWeight <= FC_WEIGHT_BLACK) {
- return 900;
- }
+ if (aFcWeight <= (FC_WEIGHT_THIN + FC_WEIGHT_EXTRALIGHT) / 2) {
+ return 100;
+ }
+ if (aFcWeight <= (FC_WEIGHT_EXTRALIGHT + FC_WEIGHT_LIGHT) / 2) {
+ return 200;
+ }
+ if (aFcWeight <= (FC_WEIGHT_LIGHT + FC_WEIGHT_BOOK) / 2) {
+ return 300;
+ }
+ if (aFcWeight <= (FC_WEIGHT_REGULAR + FC_WEIGHT_MEDIUM) / 2) {
+ // This includes FC_WEIGHT_BOOK
+ return 400;
+ }
+ if (aFcWeight <= (FC_WEIGHT_MEDIUM + FC_WEIGHT_DEMIBOLD) / 2) {
+ return 500;
+ }
+ if (aFcWeight <= (FC_WEIGHT_DEMIBOLD + FC_WEIGHT_BOLD) / 2) {
+ return 600;
+ }
+ if (aFcWeight <= (FC_WEIGHT_BOLD + FC_WEIGHT_EXTRABOLD) / 2) {
+ return 700;
+ }
+ if (aFcWeight <= (FC_WEIGHT_EXTRABOLD + FC_WEIGHT_BLACK) / 2) {
+ return 800;
+ }
+ if (aFcWeight <= FC_WEIGHT_BLACK) {
+ return 900;
+ }
- // including FC_WEIGHT_EXTRABLACK
- return 901;
+ // including FC_WEIGHT_EXTRABLACK
+ return 901;
}
static int16_t
MapFcWidth(int aFcWidth)
{
if (aFcWidth <= (FC_WIDTH_ULTRACONDENSED + FC_WIDTH_EXTRACONDENSED) / 2) {
return NS_FONT_STRETCH_ULTRA_CONDENSED;
}
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -1423,21 +1423,19 @@ gfxPlatform::CreateDrawTargetForBackend(
// now, but this might need to change in the future (using
// CreateOffscreenSurface() and CreateDrawTargetForSurface() for all
// backends).
if (aBackend == BackendType::CAIRO) {
RefPtr<gfxASurface> surf = CreateOffscreenSurface(aSize, SurfaceFormatToImageFormat(aFormat));
if (!surf || surf->CairoStatus()) {
return nullptr;
}
-
return CreateDrawTargetForSurface(surf, aSize);
- } else {
- return Factory::CreateDrawTarget(aBackend, aSize, aFormat);
}
+ return Factory::CreateDrawTarget(aBackend, aSize, aFormat);
}
already_AddRefed<DrawTarget>
gfxPlatform::CreateOffscreenCanvasDrawTarget(const IntSize& aSize, SurfaceFormat aFormat)
{
NS_ASSERTION(mPreferredCanvasBackend != BackendType::NONE, "No backend.");
RefPtr<DrawTarget> target = CreateDrawTargetForBackend(mPreferredCanvasBackend, aSize, aFormat);
if (target ||
--- a/gfx/thebes/gfxPlatformGtk.cpp
+++ b/gfx/thebes/gfxPlatformGtk.cpp
@@ -406,21 +406,22 @@ gfxPlatformGtk::GetDPIScale()
// Integer scale factors work well with GTK window scaling, image scaling,
// and pixel alignment, but there is a range where 1 is too small and 2 is
// too big. An additional step of 1.5 is added because this is common
// scale on WINNT and at this ratio the advantages of larger rendering
// outweigh the disadvantages from scaling and pixel mis-alignment.
int32_t dpi = GetDPI();
if (dpi < 132) {
return 1.0;
- } else if (dpi < 168) {
+ }
+ if (dpi < 168) {
return 1.5;
- } else {
- return round(dpi/96.0);
}
+ return round(dpi/96.0);
+
}
bool
gfxPlatformGtk::UseImageOffscreenSurfaces()
{
return GetDefaultContentBackend() != mozilla::gfx::BackendType::CAIRO ||
gfxPrefs::UseImageOffscreenSurfaces();
}