Skip to content

Commit

Permalink
Refactored out create_optimized_surface
Browse files Browse the repository at this point in the history
Instead, we simply call adjust_surface_alpha directly. This removes the creation of another temporary surface.
This also removes cases when it's called after creating a surface with create_neutral_surface, since that
function should produce the same result.
  • Loading branch information
Vultraz committed Sep 15, 2016
1 parent da818c1 commit ed8c8fb
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 61 deletions.
14 changes: 8 additions & 6 deletions src/floating_label.cpp
Expand Up @@ -179,8 +179,8 @@ surface floating_label::create_surface()

if (background == nullptr) {
ERR_FT << "could not create tooltip box" << std::endl;
surf_ = create_optimized_surface(foreground);
return surf_;
adjust_surface_alpha(foreground, SDL_ALPHA_OPAQUE);
return surf_ = foreground;
}

Uint32 color = SDL_MapRGBA(foreground->format, bgcolor_.r,bgcolor_.g, bgcolor_.b, bgalpha_);
Expand All @@ -196,7 +196,8 @@ surface floating_label::create_surface()
adjust_surface_alpha(foreground, SDL_ALPHA_OPAQUE);
blit_surface(foreground, nullptr, background, &r);

surf_ = create_optimized_surface(background);
adjust_surface_alpha(background, SDL_ALPHA_OPAQUE);
surf_ = background;
// RLE compression seems less efficient for big semi-transparent area
// so, remove it for this case, but keep the optimized display format
adjust_surface_alpha(surf_, SDL_ALPHA_OPAQUE);
Expand All @@ -212,12 +213,13 @@ surface floating_label::create_surface()

if (background == nullptr) {
ERR_FT << "could not create floating label's shadow" << std::endl;
surf_ = create_optimized_surface(foreground);
return surf_;
adjust_surface_alpha(foreground, SDL_ALPHA_OPAQUE);
return surf_ = foreground;
}
adjust_surface_alpha(foreground, SDL_ALPHA_OPAQUE);
blit_surface(foreground, nullptr, background, &r);
surf_ = create_optimized_surface(background);
adjust_surface_alpha(background, SDL_ALPHA_OPAQUE);
surf_ = background;
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/image.cpp
Expand Up @@ -959,7 +959,7 @@ surface get_image(const image::locator& i_locator, TYPE type)

// Optimizes surface before storing it
if(res)
res = create_optimized_surface(res);
adjust_surface_alpha(res, SDL_ALPHA_OPAQUE);

#ifdef _OPENMP
#pragma omp critical(image_cache)
Expand Down Expand Up @@ -1112,7 +1112,8 @@ surface get_lighted_image(const image::locator& i_locator, const light_string& l
}

// Optimizes surface before storing it
res = create_optimized_surface(res);
adjust_surface_alpha(res, SDL_ALPHA_OPAQUE);

// record the lighted surface in the corresponding variants cache
i_locator.access_in_cache(*imap)[ls] = res;

Expand Down
5 changes: 3 additions & 2 deletions src/image_modifications.cpp
Expand Up @@ -247,8 +247,9 @@ surface crop_modification::operator()(const surface& src) const
* Since it seems to work for most cases, rather change this caller instead
* of the function signature. (The issue was discovered in bug #20876).
*/
return create_optimized_surface(
cut_surface(make_neutral_surface(src), area));
surface temp = cut_surface(make_neutral_surface(src), area);
adjust_surface_alpha(temp, SDL_ALPHA_OPAQUE);
return temp;
}

const SDL_Rect& crop_modification::get_slice() const
Expand Down

0 comments on commit ed8c8fb

Please sign in to comment.