Commit 130c27a3 by Nicolas Capens

Move blit routine generation to a method.

Bug 21716622 Change-Id: Ida62ad1f1f51f035969754f2c5ff800a0afc6fd5 Reviewed-on: https://swiftshader-review.googlesource.com/3452Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent a8b364b7
...@@ -170,30 +170,7 @@ namespace sw ...@@ -170,30 +170,7 @@ namespace sw
return true; return true;
} }
bool Blitter::blitReactor(Surface *source, const SliceRect &sourceRect, Surface *dest, const SliceRect &destRect, bool filter) Routine *Blitter::generate(BlitState &state)
{
Rect dRect = destRect;
Rect sRect = sourceRect;
if(destRect.x0 > destRect.x1)
{
swap(dRect.x0, dRect.x1);
swap(sRect.x0, sRect.x1);
}
if(destRect.y0 > destRect.y1)
{
swap(dRect.y0, dRect.y1);
swap(sRect.y0, sRect.y1);
}
BlitState state;
state.sourceFormat = source->getInternalFormat();
state.destFormat = dest->getInternalFormat();
state.filter = filter;
Routine *blitRoutine = blitCache->query(state);
if(!blitRoutine)
{ {
Function<Void, Pointer<Byte> > function; Function<Void, Pointer<Byte> > function;
{ {
...@@ -228,7 +205,7 @@ namespace sw ...@@ -228,7 +205,7 @@ namespace sw
{ {
Float4 color; Float4 color;
if(!filter) if(!state.filter)
{ {
Int X = Int(x); Int X = Int(x);
Int Y = Int(y); Int Y = Int(y);
...@@ -237,7 +214,7 @@ namespace sw ...@@ -237,7 +214,7 @@ namespace sw
if(!read(color, s, state.sourceFormat)) if(!read(color, s, state.sourceFormat))
{ {
return false; return nullptr;
} }
} }
else // Bilinear filtering else // Bilinear filtering
...@@ -256,10 +233,10 @@ namespace sw ...@@ -256,10 +233,10 @@ namespace sw
Pointer<Byte> s10 = source + Y1 * sPitchB + X0 * Surface::bytes(state.sourceFormat); Pointer<Byte> s10 = source + Y1 * sPitchB + X0 * Surface::bytes(state.sourceFormat);
Pointer<Byte> s11 = source + Y1 * sPitchB + X1 * Surface::bytes(state.sourceFormat); Pointer<Byte> s11 = source + Y1 * sPitchB + X1 * Surface::bytes(state.sourceFormat);
Float4 c00; if(!read(c00, s00, state.sourceFormat)) return false; Float4 c00; if(!read(c00, s00, state.sourceFormat)) return nullptr;
Float4 c01; if(!read(c01, s01, state.sourceFormat)) return false; Float4 c01; if(!read(c01, s01, state.sourceFormat)) return nullptr;
Float4 c10; if(!read(c10, s10, state.sourceFormat)) return false; Float4 c10; if(!read(c10, s10, state.sourceFormat)) return nullptr;
Float4 c11; if(!read(c11, s11, state.sourceFormat)) return false; Float4 c11; if(!read(c11, s11, state.sourceFormat)) return nullptr;
Float4 fx = Float4(x0 - Float(X0)); Float4 fx = Float4(x0 - Float(X0));
Float4 fy = Float4(y0 - Float(Y0)); Float4 fy = Float4(y0 - Float(Y0));
...@@ -399,7 +376,40 @@ namespace sw ...@@ -399,7 +376,40 @@ namespace sw
} }
} }
blitRoutine = function(L"BlitRoutine"); return function(L"BlitRoutine");
}
bool Blitter::blitReactor(Surface *source, const SliceRect &sourceRect, Surface *dest, const SliceRect &destRect, bool filter)
{
Rect dRect = destRect;
Rect sRect = sourceRect;
if(destRect.x0 > destRect.x1)
{
swap(dRect.x0, dRect.x1);
swap(sRect.x0, sRect.x1);
}
if(destRect.y0 > destRect.y1)
{
swap(dRect.y0, dRect.y1);
swap(sRect.y0, sRect.y1);
}
BlitState state;
state.sourceFormat = source->getInternalFormat();
state.destFormat = dest->getInternalFormat();
state.filter = filter;
Routine *blitRoutine = blitCache->query(state);
if(!blitRoutine)
{
blitRoutine = generate(state);
if(!blitRoutine)
{
return false;
}
blitCache->add(state, blitRoutine); blitCache->add(state, blitRoutine);
} }
......
...@@ -22,18 +22,6 @@ namespace sw ...@@ -22,18 +22,6 @@ namespace sw
{ {
class Blitter class Blitter
{ {
public:
Blitter();
virtual ~Blitter();
void blit(Surface *source, const SliceRect &sRect, Surface *dest, const SliceRect &dRect, bool filter);
void blit3D(Surface *source, Surface *dest);
private:
bool read(Float4 &color, Pointer<Byte> element, Format format);
bool blitReactor(Surface *source, const SliceRect &sRect, Surface *dest, const SliceRect &dRect, bool filter);
struct BlitState struct BlitState
{ {
bool operator==(const BlitState &state) const bool operator==(const BlitState &state) const
...@@ -67,6 +55,19 @@ namespace sw ...@@ -67,6 +55,19 @@ namespace sw
int sHeight; int sHeight;
}; };
public:
Blitter();
virtual ~Blitter();
void blit(Surface *source, const SliceRect &sRect, Surface *dest, const SliceRect &dRect, bool filter);
void blit3D(Surface *source, Surface *dest);
private:
bool read(Float4 &color, Pointer<Byte> element, Format format);
bool blitReactor(Surface *source, const SliceRect &sRect, Surface *dest, const SliceRect &dRect, bool filter);
Routine *generate(BlitState &state);
RoutineCache<BlitState> *blitCache; RoutineCache<BlitState> *blitCache;
}; };
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment