Refactor bitmap scaler to make it easier to migrate rest of chrome to use it

Previously, the set of platform-specific function pointers to do fast convolution (e.g., neon, SSE) were passed in a structure to the scaler.

I refactored this so that the scaler fills in these function pointers after it's called, so the caller doesn't have to worry about it.

R=mtklein@google.com
TBR=mtklein
NOTRY=True

Author: humper@google.com

Review URL: https://codereview.chromium.org/354193002
This commit is contained in:
humper 2014-06-27 11:27:03 -07:00 committed by Commit bot
parent 1f8ed02222
commit 4f96ab3618
7 changed files with 16 additions and 17 deletions

View File

@ -172,16 +172,11 @@ bool SkBitmapProcState::possiblyScaleImage() {
// All the criteria are met; let's make a new bitmap.
SkConvolutionProcs simd;
sk_bzero(&simd, sizeof(simd));
this->platformConvolutionProcs(&simd);
if (!SkBitmapScaler::Resize(&fScaledBitmap,
fOrigBitmap,
SkBitmapScaler::RESIZE_BEST,
dest_width,
dest_height,
simd,
SkScaledImageCache::GetAllocator())) {
// we failed to create fScaledBitmap, so just return and let
// the scanline proc handle it.

View File

@ -33,7 +33,6 @@
#endif
class SkPaint;
struct SkConvolutionProcs;
struct SkBitmapProcState {
@ -104,12 +103,6 @@ struct SkBitmapProcState {
*/
void platformProcs();
/** Platforms can also optionally overwrite the convolution functions
if we have SIMD versions of them.
*/
void platformConvolutionProcs(SkConvolutionProcs*);
/** Given the byte size of the index buffer to be passed to the matrix proc,
return the maximum number of resulting pixels that can be computed
(i.e. the number of SkPMColor values to be written by the sample proc).

View File

@ -246,9 +246,11 @@ bool SkBitmapScaler::Resize(SkBitmap* resultPtr,
const SkBitmap& source,
ResizeMethod method,
float destWidth, float destHeight,
const SkConvolutionProcs& convolveProcs,
SkBitmap::Allocator* allocator) {
SkConvolutionProcs convolveProcs= { 0, NULL, NULL, NULL, NULL };
PlatformConvolutionProcs(&convolveProcs);
SkRect destSubset = { 0, 0, destWidth, destHeight };
// Ensure that the ResizeMethod enumeration is sound.

View File

@ -83,8 +83,13 @@ public:
const SkBitmap& source,
ResizeMethod method,
float dest_width, float dest_height,
const SkConvolutionProcs&,
SkBitmap::Allocator* allocator = NULL);
/** Platforms can also optionally overwrite the convolution functions
if we have SIMD versions of them.
*/
static void PlatformConvolutionProcs(SkConvolutionProcs*);
};
#endif

View File

@ -6,6 +6,7 @@
*/
#include "SkBitmapScaler.h"
#include "SkBitmapProcState.h"
#include "SkColorPriv.h"
#include "SkPaint.h"
@ -229,6 +230,6 @@ extern void platformConvolutionProcs_arm_neon(SkConvolutionProcs* procs);
void platformConvolutionProcs_arm(SkConvolutionProcs* procs) {
}
void SkBitmapProcState::platformConvolutionProcs(SkConvolutionProcs* procs) {
void SkBitmapScaler::PlatformConvolutionProcs(SkConvolutionProcs* procs) {
SK_ARM_NEON_WRAP(platformConvolutionProcs_arm)(procs);
}

View File

@ -5,6 +5,8 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkBitmapScaler.h"
#include "SkBitmapProcState.h"
/* A platform may optionally overwrite any of these with accelerated
@ -23,4 +25,4 @@
void SkBitmapProcState::platformProcs() {}
// empty implementation just uses default supplied function pointers
void SkBitmapProcState::platformConvolutionProcs(SkConvolutionProcs*) {}
void SkBitmapScaler::PlatformConvolutionProcs(SkConvolutionProcs*) {}

View File

@ -8,6 +8,7 @@
#include "SkBitmapFilter_opts_SSE2.h"
#include "SkBitmapProcState_opts_SSE2.h"
#include "SkBitmapProcState_opts_SSSE3.h"
#include "SkBitmapScaler.h"
#include "SkBlitMask.h"
#include "SkBlitRect_opts_SSE2.h"
#include "SkBlitRow.h"
@ -123,7 +124,7 @@ static inline bool supports_simd(int minLevel) {
SK_CONF_DECLARE( bool, c_hqfilter_sse, "bitmap.filter.highQualitySSE", false, "Use SSE optimized version of high quality image filters");
void SkBitmapProcState::platformConvolutionProcs(SkConvolutionProcs* procs) {
void SkBitmapScaler::PlatformConvolutionProcs(SkConvolutionProcs* procs) {
if (supports_simd(SK_CPU_SSE_LEVEL_SSE2)) {
procs->fExtraHorizontalReads = 3;
procs->fConvolveVertically = &convolveVertically_SSE2;