app_server: Move AlphaMask management into DrawState.

* Give DrawState a real copy constructor, handle deriving in PushState().
   (Although clipping region and alpha mask are not cloned, which is on the
   other hand just what's needed for now.)
 * Combining alpha masks from previous states is not yet handled.
 * Remove SetAlphaMask() from DrawingEngine and Painter. It is now done in
   SetDrawState().
This commit is contained in:
Stephan Aßmus
2014-01-28 23:27:12 +01:00
parent a2f075eb42
commit 215119a1e7
12 changed files with 136 additions and 116 deletions
+4 -1
View File
@@ -12,6 +12,7 @@
#include "BitmapHWInterface.h" #include "BitmapHWInterface.h"
#include "BitmapManager.h" #include "BitmapManager.h"
#include "DrawingEngine.h" #include "DrawingEngine.h"
#include "DrawState.h"
#include "ServerBitmap.h" #include "ServerBitmap.h"
#include "View.h" #include "View.h"
@@ -101,7 +102,9 @@ AlphaMask::_RenderPicture(ServerPicture* picture, bool inverse) const
// Copy the current state of the client view, so we draw with the right // Copy the current state of the client view, so we draw with the right
// font, color and everything // font, color and everything
engine->SetDrawState(fView->CurrentState()); DrawState drawState(*fView->CurrentState());
engine->SetDrawState(&drawState);
OffscreenContext context(engine); OffscreenContext context(engine);
if (engine->LockParallelAccess()) { if (engine->LockParallelAccess()) {
// FIXME ConstrainClippingRegion docs says passing NULL disables // FIXME ConstrainClippingRegion docs says passing NULL disables
+59 -23
View File
@@ -19,6 +19,7 @@
#include <Region.h> #include <Region.h>
#include "AlphaMask.h"
#include "LinkReceiver.h" #include "LinkReceiver.h"
#include "LinkSender.h" #include "LinkSender.h"
#include "ServerProtocolStructs.h" #include "ServerProtocolStructs.h"
@@ -28,11 +29,13 @@ using std::nothrow;
DrawState::DrawState() DrawState::DrawState()
: fOrigin(0.0, 0.0), :
fOrigin(0.0, 0.0),
fCombinedOrigin(0.0, 0.0), fCombinedOrigin(0.0, 0.0),
fScale(1.0), fScale(1.0),
fCombinedScale(1.0), fCombinedScale(1.0),
fClippingRegion(NULL), fClippingRegion(NULL),
fAlphaMask(NULL),
fHighColor((rgb_color){ 0, 0, 0, 255 }), fHighColor((rgb_color){ 0, 0, 0, 255 }),
fLowColor((rgb_color){ 255, 255, 255, 255 }), fLowColor((rgb_color){ 255, 255, 255, 255 }),
@@ -56,38 +59,40 @@ DrawState::DrawState()
} }
DrawState::DrawState(DrawState* from) DrawState::DrawState(const DrawState& other)
: fOrigin(0.0, 0.0), :
fCombinedOrigin(from->fCombinedOrigin), fOrigin(other.fOrigin),
fScale(1.0), fCombinedOrigin(other.fCombinedOrigin),
fCombinedScale(from->fCombinedScale), fScale(other.fScale),
fCombinedScale(other.fCombinedScale),
fClippingRegion(NULL), fClippingRegion(NULL),
fAlphaMask(NULL),
fHighColor(from->fHighColor), fHighColor(other.fHighColor),
fLowColor(from->fLowColor), fLowColor(other.fLowColor),
fPattern(from->fPattern), fPattern(other.fPattern),
fDrawingMode(from->fDrawingMode), fDrawingMode(other.fDrawingMode),
fAlphaSrcMode(from->fAlphaSrcMode), fAlphaSrcMode(other.fAlphaSrcMode),
fAlphaFncMode(from->fAlphaFncMode), fAlphaFncMode(other.fAlphaFncMode),
fPenLocation(from->fPenLocation), fPenLocation(other.fPenLocation),
fPenSize(from->fPenSize), fPenSize(other.fPenSize),
fFont(from->fFont), fFont(other.fFont),
fFontAliasing(from->fFontAliasing), fFontAliasing(other.fFontAliasing),
fSubPixelPrecise(from->fSubPixelPrecise), fSubPixelPrecise(other.fSubPixelPrecise),
fLineCapMode(from->fLineCapMode), fLineCapMode(other.fLineCapMode),
fLineJoinMode(from->fLineJoinMode), fLineJoinMode(other.fLineJoinMode),
fMiterLimit(from->fMiterLimit), fMiterLimit(other.fMiterLimit),
// Since fScale is reset to 1.0, the unscaled // Since fScale is reset to 1.0, the unscaled
// font size is the current size of the font // font size is the current size of the font
// (which is from->fUnscaledFontSize * from->fCombinedScale) // (which is from->fUnscaledFontSize * from->fCombinedScale)
fUnscaledFontSize(from->fUnscaledFontSize), fUnscaledFontSize(other.fUnscaledFontSize),
fPreviousState(from) fPreviousState(NULL)
{ {
} }
@@ -96,13 +101,22 @@ DrawState::~DrawState()
{ {
delete fClippingRegion; delete fClippingRegion;
delete fPreviousState; delete fPreviousState;
delete fAlphaMask;
} }
DrawState* DrawState*
DrawState::PushState() DrawState::PushState()
{ {
DrawState* next = new (nothrow) DrawState(this); DrawState* next = new (nothrow) DrawState(*this);
if (next != NULL) {
// Prepare state as derived from this state
next->fOrigin = BPoint(0.0, 0.0);
next->fScale = 1.0;
next->fPreviousState = this;
}
return next; return next;
} }
@@ -373,6 +387,28 @@ DrawState::GetCombinedClippingRegion(BRegion* region) const
} }
void
DrawState::SetAlphaMask(AlphaMask* mask)
{
// BeOS compatibility: they implemented ClipToPicture by converting the
// picture to a complex BRegion and used that as a clipping region. As a
// result, youcan't have a picture and a region clipping at the same level
// (but you can either using PushState/PopState, or using
// ConstrainClippingRegion after ClipToPicture...)
// SetClippingRegion(NULL);
delete fAlphaMask;
fAlphaMask = mask;
}
AlphaMask*
DrawState::GetAlphaMask() const
{
return fAlphaMask;
}
// #pragma mark - // #pragma mark -
+7 -2
View File
@@ -20,6 +20,7 @@
#include "ServerFont.h" #include "ServerFont.h"
#include "PatternHandler.h" #include "PatternHandler.h"
class AlphaMask;
class BRegion; class BRegion;
namespace BPrivate { namespace BPrivate {
@@ -31,8 +32,7 @@ namespace BPrivate {
class DrawState { class DrawState {
public: public:
DrawState(); DrawState();
private: DrawState(const DrawState& other);
DrawState(DrawState* from);
public: public:
virtual ~DrawState(); virtual ~DrawState();
@@ -67,6 +67,9 @@ public:
bool HasAdditionalClipping() const; bool HasAdditionalClipping() const;
bool GetCombinedClippingRegion(BRegion* region) const; bool GetCombinedClippingRegion(BRegion* region) const;
void SetAlphaMask(AlphaMask* mask);
AlphaMask* GetAlphaMask() const;
// coordinate transformations // coordinate transformations
void Transform(float* x, float* y) const; void Transform(float* x, float* y) const;
void InverseTransform(float* x, float* y) const; void InverseTransform(float* x, float* y) const;
@@ -149,6 +152,8 @@ protected:
BRegion* fClippingRegion; BRegion* fClippingRegion;
AlphaMask* fAlphaMask;
rgb_color fHighColor; rgb_color fHighColor;
rgb_color fLowColor; rgb_color fLowColor;
Pattern fPattern; Pattern fPattern;
+20 -2
View File
@@ -33,6 +33,10 @@ DrawingContext::DrawingContext()
} }
DrawingContext::~DrawingContext()
{
}
status_t status_t
DrawingContext::InitCheck() const DrawingContext::InitCheck() const
@@ -108,7 +112,7 @@ DrawingContext::SetScale(float scale)
float float
DrawingContext::Scale() const DrawingContext::Scale() const
{ {
return CurrentState()->Scale(); return fDrawState->Scale();
} }
@@ -117,11 +121,25 @@ DrawingContext::SetUserClipping(const BRegion* region)
{ {
fDrawState->SetClippingRegion(region); fDrawState->SetClippingRegion(region);
// rebuild clipping (for just this view) // rebuild clipping (for just this context)
RebuildClipping(false); RebuildClipping(false);
} }
void
DrawingContext::SetAlphaMask(AlphaMask* mask)
{
fDrawState->SetAlphaMask(mask);
}
AlphaMask*
DrawingContext::GetAlphaMask() const
{
return fDrawState->GetAlphaMask();
}
//! converts a point from local *drawing* to screen coordinate system //! converts a point from local *drawing* to screen coordinate system
void void
DrawingContext::ConvertToScreenForDrawing(BPoint* point) const DrawingContext::ConvertToScreenForDrawing(BPoint* point) const
+10 -4
View File
@@ -17,6 +17,7 @@
#include <Point.h> #include <Point.h>
class AlphaMask;
class BGradient; class BGradient;
class BRegion; class BRegion;
class DrawingEngine; class DrawingEngine;
@@ -27,8 +28,10 @@ class ServerPicture;
class DrawingContext { class DrawingContext {
public: public:
DrawingContext(); DrawingContext();
virtual ~DrawingContext();
status_t InitCheck() const; status_t InitCheck() const;
virtual void PushState(); virtual void PushState();
@@ -44,6 +47,9 @@ class DrawingContext {
void SetUserClipping(const BRegion* region); void SetUserClipping(const BRegion* region);
// region is expected in view coordinates // region is expected in view coordinates
void SetAlphaMask(AlphaMask* mask);
AlphaMask* GetAlphaMask() const;
void ConvertToScreenForDrawing(BPoint* point) const; void ConvertToScreenForDrawing(BPoint* point) const;
void ConvertToScreenForDrawing(BRect* rect) const; void ConvertToScreenForDrawing(BRect* rect) const;
void ConvertToScreenForDrawing(BRegion* region) const; void ConvertToScreenForDrawing(BRegion* region) const;
@@ -70,13 +76,13 @@ class DrawingContext {
virtual void ResyncDrawState() {}; virtual void ResyncDrawState() {};
virtual void UpdateCurrentDrawingRegion() {}; virtual void UpdateCurrentDrawingRegion() {};
protected: protected:
DrawState* fDrawState; DrawState* fDrawState;
}; };
class OffscreenContext: public DrawingContext { class OffscreenContext: public DrawingContext {
public: public:
OffscreenContext(DrawingEngine* engine) OffscreenContext(DrawingEngine* engine)
: fDrawingEngine(engine) : fDrawingEngine(engine)
{}; {};
@@ -96,7 +102,7 @@ class OffscreenContext: public DrawingContext {
void RebuildClipping(bool deep) { /* TODO */ } void RebuildClipping(bool deep) { /* TODO */ }
ServerPicture* GetPicture(int32 token) const ServerPicture* GetPicture(int32 token) const
{ /* TODO */ return NULL; } { /* TODO */ return NULL; }
private: private:
DrawingEngine* fDrawingEngine; DrawingEngine* fDrawingEngine;
}; };
+7 -4
View File
@@ -51,6 +51,7 @@
#include "clipping.h" #include "clipping.h"
#include "utf8_functions.h" #include "utf8_functions.h"
#include "AlphaMask.h"
#include "AppServer.h" #include "AppServer.h"
#include "AutoDeleter.h" #include "AutoDeleter.h"
#include "BBitmapBuffer.h" #include "BBitmapBuffer.h"
@@ -1869,7 +1870,8 @@ fDesktop->LockSingleWindow();
link.Read<int32>(&pictureToken); link.Read<int32>(&pictureToken);
if (pictureToken < 0) { if (pictureToken < 0) {
fCurrentView->SetAlphaMask(NULL, false, B_ORIGIN); fCurrentView->SetAlphaMask(NULL);
_UpdateDrawState(fCurrentView);
break; break;
} }
@@ -1881,7 +1883,10 @@ fDesktop->LockSingleWindow();
if (picture == NULL) if (picture == NULL)
break; break;
fCurrentView->SetAlphaMask(picture, inverse, where); fCurrentView->SetAlphaMask(new(std::nothrow) AlphaMask(
fCurrentView, picture, inverse, where));
_UpdateDrawState(fCurrentView);
picture->ReleaseReference(); picture->ReleaseReference();
break; break;
} }
@@ -2174,7 +2179,6 @@ ServerWindow::_DispatchViewDrawingMessage(int32 code,
// that's why you need to use the clipping only for as long // that's why you need to use the clipping only for as long
// as you have it locked // as you have it locked
drawingEngine->ConstrainClippingRegion(&fCurrentDrawingRegion); drawingEngine->ConstrainClippingRegion(&fCurrentDrawingRegion);
drawingEngine->SetAlphaMask(fCurrentView->GetAlphaMask());
switch (code) { switch (code) {
case AS_STROKE_LINE: case AS_STROKE_LINE:
@@ -2840,7 +2844,6 @@ ServerWindow::_DispatchViewDrawingMessage(int32 code,
break; break;
} }
drawingEngine->SetAlphaMask(NULL);
drawingEngine->UnlockParallelAccess(); drawingEngine->UnlockParallelAccess();
} }
-28
View File
@@ -113,7 +113,6 @@ View::View(IntRect frame, IntPoint scrollingOffset, const char* name,
fCursor(NULL), fCursor(NULL),
fPicture(NULL), fPicture(NULL),
fAlphaMask(NULL),
fLocalClipping((BRect)Bounds()), fLocalClipping((BRect)Bounds()),
fScreenClipping(), fScreenClipping(),
@@ -134,7 +133,6 @@ View::~View()
delete fScreenAndUserClipping; delete fScreenAndUserClipping;
delete fUserClipping; delete fUserClipping;
delete fDrawState; delete fDrawState;
delete fAlphaMask;
// if (fWindow && this == fWindow->TopView()) // if (fWindow && this == fWindow->TopView())
// fWindow->SetTopView(NULL); // fWindow->SetTopView(NULL);
@@ -1575,32 +1573,6 @@ View::InvalidateScreenClipping()
} }
// TODO we should be storing the ServerPicture here, so we can recompute the
// bitmap mask when the view is scaled, resized or the origin is changed.
// This would allow us to keep a bitmap mask matching exactly the view size.
// Moreover, we should clip that bitmap mask using the region-based clipping,
// so it can mask out all the clipped regions, and we don't have to worry about
// them whendoing further drawing. Essentially, switch from region-based to
// bitmap based clipping for all ourdrawing.
void
View::SetAlphaMask(ServerPicture* picture, bool inverse, BPoint origin)
{
// BeOS compatibility: they implemented ClipToPicture by converting the
// picture to a complex BRegion and used that as a clipping region. As a
// result, youcan't have a picture and a region clipping at the same level
// (but you can either using PushState/PopState, or using
// ConstrainClippingRegion after ClipToPicture...)
// SetUserClipping(NULL);
delete fAlphaMask;
if (picture != NULL) {
fAlphaMask = new(std::nothrow) AlphaMask(this, picture, inverse,
origin);
} else
fAlphaMask = NULL;
}
BRegion& BRegion&
View::_ScreenClipping(BRegion* windowContentClipping, bool force) const View::_ScreenClipping(BRegion* windowContentClipping, bool force) const
{ {
-6
View File
@@ -29,7 +29,6 @@ namespace BPrivate {
class PortLink; class PortLink;
}; };
class AlphaMask;
class DrawingEngine; class DrawingEngine;
class Overlay; class Overlay;
class Window; class Window;
@@ -221,10 +220,6 @@ public:
&& fScreenAndUserClipping != NULL)); && fScreenAndUserClipping != NULL));
} }
void SetAlphaMask(ServerPicture* picture, bool inverse,
BPoint where);
AlphaMask* GetAlphaMask() { return fAlphaMask; }
// debugging // debugging
void PrintToStream() const; void PrintToStream() const;
#if 0 #if 0
@@ -274,7 +269,6 @@ protected:
ServerCursor* fCursor; ServerCursor* fCursor;
ServerPicture* fPicture; ServerPicture* fPicture;
AlphaMask* fAlphaMask;
// clipping // clipping
BRegion fLocalClipping; BRegion fLocalClipping;
-11
View File
@@ -17,7 +17,6 @@
#include <algorithm> #include <algorithm>
#include <stack> #include <stack>
#include "AlphaMask.h"
#include "DrawState.h" #include "DrawState.h"
#include "GlyphLayoutEngine.h" #include "GlyphLayoutEngine.h"
#include "Painter.h" #include "Painter.h"
@@ -235,16 +234,6 @@ DrawingEngine::ConstrainClippingRegion(const BRegion* region)
} }
void
DrawingEngine::SetAlphaMask(AlphaMask* mask)
{
scanline_unpacked_masked_type* scanline = NULL;
if (mask != NULL)
scanline = mask->Generate();
fPainter->SetAlphaMask(scanline);
}
void void
DrawingEngine::SetDrawState(const DrawState* state, int32 xOffset, DrawingEngine::SetDrawState(const DrawState* state, int32 xOffset,
int32 yOffset) int32 yOffset)
-2
View File
@@ -25,7 +25,6 @@ class BPoint;
class BRect; class BRect;
class BRegion; class BRegion;
class AlphaMask;
class DrawState; class DrawState;
class Painter; class Painter;
class ServerBitmap; class ServerBitmap;
@@ -68,7 +67,6 @@ public:
// clipping for all drawing functions, passing a NULL region // clipping for all drawing functions, passing a NULL region
// will remove any clipping (drawing allowed everywhere) // will remove any clipping (drawing allowed everywhere)
virtual void ConstrainClippingRegion(const BRegion* region); virtual void ConstrainClippingRegion(const BRegion* region);
void SetAlphaMask(AlphaMask* mask);
virtual void SetDrawState(const DrawState* state, virtual void SetDrawState(const DrawState* state,
int32 xOffset = 0, int32 yOffset = 0); int32 xOffset = 0, int32 yOffset = 0);
+5 -7
View File
@@ -289,6 +289,11 @@ Painter::SetDrawState(const DrawState* data, int32 xOffset, int32 yOffset)
fSubpixelPrecise = data->SubPixelPrecise(); fSubpixelPrecise = data->SubPixelPrecise();
if (data->GetAlphaMask() != NULL)
fMaskedUnpackedScanline = data->GetAlphaMask()->Generate();
else
fMaskedUnpackedScanline = NULL;
// any of these conditions means we need to use a different drawing // any of these conditions means we need to use a different drawing
// mode instance // mode instance
bool updateDrawingMode bool updateDrawingMode
@@ -336,13 +341,6 @@ Painter::ConstrainClipping(const BRegion* region)
} }
void
Painter::SetAlphaMask(scanline_unpacked_masked_type* mask)
{
fMaskedUnpackedScanline = mask;
}
// SetHighColor // SetHighColor
void void
Painter::SetHighColor(const rgb_color& color) Painter::SetHighColor(const rgb_color& color)
@@ -54,8 +54,6 @@ public:
void ConstrainClipping(const BRegion* region); void ConstrainClipping(const BRegion* region);
const BRegion* ClippingRegion() const const BRegion* ClippingRegion() const
{ return fClippingRegion; } { return fClippingRegion; }
void SetAlphaMask(
scanline_unpacked_masked_type* mask);
void SetDrawState(const DrawState* data, void SetDrawState(const DrawState* data,
int32 xOffset = 0, int32 xOffset = 0,