1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef sw_Blitter_hpp 16 #define sw_Blitter_hpp 17 18 #include "Surface.hpp" 19 #include "RoutineCache.hpp" 20 #include "Reactor/Reactor.hpp" 21 22 #include <string.h> 23 24 namespace sw 25 { 26 class Blitter 27 { 28 enum Options : unsigned char 29 { 30 FILTER_POINT = 0x00, 31 WRITE_RED = 0x01, 32 WRITE_GREEN = 0x02, 33 WRITE_BLUE = 0x04, 34 WRITE_ALPHA = 0x08, 35 WRITE_RGBA = WRITE_RED | WRITE_GREEN | WRITE_BLUE | WRITE_ALPHA, 36 FILTER_LINEAR = 0x10, 37 CLEAR_OPERATION = 0x20, 38 USE_STENCIL = 0x40, 39 }; 40 41 struct BlitState 42 { operator ==sw::Blitter::BlitState43 bool operator==(const BlitState &state) const 44 { 45 return memcmp(this, &state, sizeof(BlitState)) == 0; 46 } 47 48 Format sourceFormat; 49 Format destFormat; 50 Blitter::Options options; 51 }; 52 53 struct BlitData 54 { 55 void *source; 56 void *dest; 57 int sPitchB; 58 int dPitchB; 59 60 float x0; 61 float y0; 62 float w; 63 float h; 64 65 int y0d; 66 int y1d; 67 int x0d; 68 int x1d; 69 70 int sWidth; 71 int sHeight; 72 }; 73 74 public: 75 Blitter(); 76 virtual ~Blitter(); 77 78 void clear(void* pixel, sw::Format format, Surface *dest, const SliceRect &dRect, unsigned int rgbaMask); 79 void blit(Surface *source, const SliceRect &sRect, Surface *dest, const SliceRect &dRect, bool filter, bool isStencil = false); 80 void blit3D(Surface *source, Surface *dest); 81 82 private: 83 bool fastClear(void* pixel, sw::Format format, Surface *dest, const SliceRect &dRect, unsigned int rgbaMask); 84 85 bool read(Float4 &color, Pointer<Byte> element, Format format); 86 bool write(Float4 &color, Pointer<Byte> element, Format format, const Blitter::Options& options); 87 bool read(Int4 &color, Pointer<Byte> element, Format format); 88 bool write(Int4 &color, Pointer<Byte> element, Format format, const Blitter::Options& options); 89 static bool GetScale(float4& scale, Format format); 90 static bool ApplyScaleAndClamp(Float4& value, const BlitState& state); 91 static Int ComputeOffset(Int& x, Int& y, Int& pitchB, int bytes, bool quadLayout); 92 void blit(Surface *source, const SliceRect &sRect, Surface *dest, const SliceRect &dRect, const Blitter::Options& options); 93 bool blitReactor(Surface *source, const SliceRect &sRect, Surface *dest, const SliceRect &dRect, const Blitter::Options& options); 94 Routine *generate(BlitState &state); 95 96 RoutineCache<BlitState> *blitCache; 97 MutexLock criticalSection; 98 }; 99 } 100 101 #endif // sw_Blitter_hpp 102