app_server: rename DrawingContext to Canvas

* Better reflects the purpose of the class: an interface for things
  in which we can draw (e.g. a View)

* Accordingly rename OffscreenContext to OffscreenCanvas
This commit is contained in:
Julian Harnath
2015-07-25 16:30:29 +02:00
parent 5d8a237146
commit ab1bd2fd07
8 changed files with 205 additions and 203 deletions
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2001-2014, Haiku, Inc. * Copyright (c) 2001-2015, Haiku, Inc.
* Distributed under the terms of the MIT license. * Distributed under the terms of the MIT license.
* *
* Authors: * Authors:
@@ -9,10 +9,11 @@
* Stephan Aßmus <superstippi@gmx.de> * Stephan Aßmus <superstippi@gmx.de>
* Marcus Overhagen <marcus@overhagen.de> * Marcus Overhagen <marcus@overhagen.de>
* Adrien Destugues <pulkomandy@pulkomandy.tk * Adrien Destugues <pulkomandy@pulkomandy.tk
* Julian Harnath <julian.harnath@rwth-aachen.de>
*/ */
#include "DrawingContext.h" #include "Canvas.h"
#include <new> #include <new>
@@ -27,27 +28,27 @@
#include "DrawState.h" #include "DrawState.h"
DrawingContext::DrawingContext() Canvas::Canvas()
: :
fDrawState(new(std::nothrow) DrawState()) fDrawState(new(std::nothrow) DrawState())
{ {
} }
DrawingContext::DrawingContext(const DrawState& state) Canvas::Canvas(const DrawState& state)
: :
fDrawState(new(std::nothrow) DrawState(state)) fDrawState(new(std::nothrow) DrawState(state))
{ {
} }
DrawingContext::~DrawingContext() Canvas::~Canvas()
{ {
} }
status_t status_t
DrawingContext::InitCheck() const Canvas::InitCheck() const
{ {
if (fDrawState == NULL) if (fDrawState == NULL)
return B_NO_MEMORY; return B_NO_MEMORY;
@@ -57,7 +58,7 @@ DrawingContext::InitCheck() const
void void
DrawingContext::PushState() Canvas::PushState()
{ {
DrawState* newState = fDrawState->PushState(); DrawState* newState = fDrawState->PushState();
if (newState) if (newState)
@@ -66,7 +67,7 @@ DrawingContext::PushState()
void void
DrawingContext::PopState() Canvas::PopState()
{ {
if (fDrawState->PreviousState() == NULL) if (fDrawState->PreviousState() == NULL)
return; return;
@@ -83,7 +84,7 @@ DrawingContext::PopState()
void void
DrawingContext::SetDrawingOrigin(BPoint origin) Canvas::SetDrawingOrigin(BPoint origin)
{ {
fDrawState->SetOrigin(origin); fDrawState->SetOrigin(origin);
@@ -94,7 +95,7 @@ DrawingContext::SetDrawingOrigin(BPoint origin)
BPoint BPoint
DrawingContext::DrawingOrigin() const Canvas::DrawingOrigin() const
{ {
BPoint origin(fDrawState->Origin()); BPoint origin(fDrawState->Origin());
float scale = Scale(); float scale = Scale();
@@ -107,7 +108,7 @@ DrawingContext::DrawingOrigin() const
void void
DrawingContext::SetScale(float scale) Canvas::SetScale(float scale)
{ {
fDrawState->SetScale(scale); fDrawState->SetScale(scale);
@@ -118,31 +119,31 @@ DrawingContext::SetScale(float scale)
float float
DrawingContext::Scale() const Canvas::Scale() const
{ {
return fDrawState->Scale(); return fDrawState->Scale();
} }
void void
DrawingContext::SetUserClipping(const BRegion* region) Canvas::SetUserClipping(const BRegion* region)
{ {
fDrawState->SetClippingRegion(region); fDrawState->SetClippingRegion(region);
// rebuild clipping (for just this context) // rebuild clipping (for just this canvas)
RebuildClipping(false); RebuildClipping(false);
} }
void void
DrawingContext::SetAlphaMask(AlphaMask* mask) Canvas::SetAlphaMask(AlphaMask* mask)
{ {
fDrawState->SetAlphaMask(mask); fDrawState->SetAlphaMask(mask);
} }
AlphaMask* AlphaMask*
DrawingContext::GetAlphaMask() const Canvas::GetAlphaMask() const
{ {
return fDrawState->GetAlphaMask(); return fDrawState->GetAlphaMask();
} }
@@ -150,7 +151,7 @@ DrawingContext::GetAlphaMask() const
//! 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 Canvas::ConvertToScreenForDrawing(BPoint* point) const
{ {
fDrawState->Transform(point); fDrawState->Transform(point);
// NOTE: from here on, don't use the // NOTE: from here on, don't use the
@@ -161,7 +162,7 @@ DrawingContext::ConvertToScreenForDrawing(BPoint* point) const
//! converts a rect from local *drawing* to screen coordinate system //! converts a rect from local *drawing* to screen coordinate system
void void
DrawingContext::ConvertToScreenForDrawing(BRect* rect) const Canvas::ConvertToScreenForDrawing(BRect* rect) const
{ {
fDrawState->Transform(rect); fDrawState->Transform(rect);
// NOTE: from here on, don't use the // NOTE: from here on, don't use the
@@ -172,7 +173,7 @@ DrawingContext::ConvertToScreenForDrawing(BRect* rect) const
//! converts a region from local *drawing* to screen coordinate system //! converts a region from local *drawing* to screen coordinate system
void void
DrawingContext::ConvertToScreenForDrawing(BRegion* region) const Canvas::ConvertToScreenForDrawing(BRegion* region) const
{ {
fDrawState->Transform(region); fDrawState->Transform(region);
// NOTE: from here on, don't use the // NOTE: from here on, don't use the
@@ -183,7 +184,7 @@ DrawingContext::ConvertToScreenForDrawing(BRegion* region) const
//! converts a gradient from local *drawing* to screen coordinate system //! converts a gradient from local *drawing* to screen coordinate system
void void
DrawingContext::ConvertToScreenForDrawing(BGradient* gradient) const Canvas::ConvertToScreenForDrawing(BGradient* gradient) const
{ {
switch (gradient->GetType()) { switch (gradient->GetType()) {
case BGradient::TYPE_LINEAR: case BGradient::TYPE_LINEAR:
@@ -266,7 +267,7 @@ DrawingContext::ConvertToScreenForDrawing(BGradient* gradient) const
//! converts points from local *drawing* to screen coordinate system //! converts points from local *drawing* to screen coordinate system
void void
DrawingContext::ConvertToScreenForDrawing(BPoint* dst, const BPoint* src, int32 num) const Canvas::ConvertToScreenForDrawing(BPoint* dst, const BPoint* src, int32 num) const
{ {
// TODO: optimize this, it should be smarter // TODO: optimize this, it should be smarter
while (num--) { while (num--) {
@@ -283,7 +284,7 @@ DrawingContext::ConvertToScreenForDrawing(BPoint* dst, const BPoint* src, int32
//! converts rects from local *drawing* to screen coordinate system //! converts rects from local *drawing* to screen coordinate system
void void
DrawingContext::ConvertToScreenForDrawing(BRect* dst, const BRect* src, int32 num) const Canvas::ConvertToScreenForDrawing(BRect* dst, const BRect* src, int32 num) const
{ {
// TODO: optimize this, it should be smarter // TODO: optimize this, it should be smarter
while (num--) { while (num--) {
@@ -300,7 +301,7 @@ DrawingContext::ConvertToScreenForDrawing(BRect* dst, const BRect* src, int32 nu
//! converts regions from local *drawing* to screen coordinate system //! converts regions from local *drawing* to screen coordinate system
void void
DrawingContext::ConvertToScreenForDrawing(BRegion* dst, const BRegion* src, int32 num) const Canvas::ConvertToScreenForDrawing(BRegion* dst, const BRegion* src, int32 num) const
{ {
// TODO: optimize this, it should be smarter // TODO: optimize this, it should be smarter
while (num--) { while (num--) {
@@ -317,20 +318,20 @@ DrawingContext::ConvertToScreenForDrawing(BRegion* dst, const BRegion* src, int3
//! converts a point from screen to local coordinate system //! converts a point from screen to local coordinate system
void void
DrawingContext::ConvertFromScreenForDrawing(BPoint* point) const Canvas::ConvertFromScreenForDrawing(BPoint* point) const
{ {
ConvertFromScreen(point); ConvertFromScreen(point);
fDrawState->InverseTransform(point); fDrawState->InverseTransform(point);
} }
// #pragma mark - OffscreenContext // #pragma mark - OffscreenCanvas
OffscreenContext::OffscreenContext(DrawingEngine* engine, OffscreenCanvas::OffscreenCanvas(DrawingEngine* engine,
const DrawState& state) const DrawState& state)
: :
DrawingContext(state), Canvas(state),
fDrawingEngine(engine) fDrawingEngine(engine)
{ {
ResyncDrawState(); ResyncDrawState();
@@ -338,7 +339,7 @@ OffscreenContext::OffscreenContext(DrawingEngine* engine,
void void
OffscreenContext::ResyncDrawState() OffscreenCanvas::ResyncDrawState()
{ {
fDrawingEngine->SetDrawState(fDrawState); fDrawingEngine->SetDrawState(fDrawState);
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2001-2014, Haiku, Inc. * Copyright (c) 2001-2015, Haiku, Inc.
* Distributed under the terms of the MIT license. * Distributed under the terms of the MIT license.
* *
* Authors: * Authors:
@@ -9,9 +9,10 @@
* Stephan Aßmus <superstippi@gmx.de> * Stephan Aßmus <superstippi@gmx.de>
* Marcus Overhagen <marcus@overhagen.de> * Marcus Overhagen <marcus@overhagen.de>
* Adrien Destugues <pulkomandy@pulkomandy.tk> * Adrien Destugues <pulkomandy@pulkomandy.tk>
* Julian Harnath <julian.harnath@rwth-aachen.de>
*/ */
#ifndef DRAWING_CONTEXT_H #ifndef CANVAS_H
#define DRAWING_CONTEXT_H #define CANVAS_H
#include <Point.h> #include <Point.h>
@@ -27,11 +28,11 @@ class IntRect;
class ServerPicture; class ServerPicture;
class DrawingContext { class Canvas {
public: public:
DrawingContext(); Canvas();
DrawingContext(const DrawState& state); Canvas(const DrawState& state);
virtual ~DrawingContext(); virtual ~Canvas();
status_t InitCheck() const; status_t InitCheck() const;
@@ -47,10 +48,10 @@ public:
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); void SetAlphaMask(AlphaMask* mask);
AlphaMask* GetAlphaMask() const; 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;
@@ -82,9 +83,9 @@ protected:
}; };
class OffscreenContext: public DrawingContext { class OffscreenCanvas : public Canvas {
public: public:
OffscreenContext(DrawingEngine* engine, OffscreenCanvas(DrawingEngine* engine,
const DrawState& state); const DrawState& state);
// Screen and View coordinates are the same for us. // Screen and View coordinates are the same for us.
@@ -108,4 +109,4 @@ private:
}; };
#endif #endif // CANVAS_H
+5 -5
View File
@@ -32,10 +32,10 @@ local font_src =
; ;
UseBuildFeatureHeaders freetype ; UseBuildFeatureHeaders freetype ;
Includes [ FGristFiles AppServer.cpp BitmapManager.cpp Includes [ FGristFiles AppServer.cpp BitmapManager.cpp Canvas.cpp
ClientMemoryAllocator.cpp Desktop.cpp DesktopSettings.cpp ClientMemoryAllocator.cpp Desktop.cpp DesktopSettings.cpp
DrawState.cpp DrawingContext.cpp DrawingEngine.cpp ServerApp.cpp DrawState.cpp DrawingEngine.cpp ServerApp.cpp
ServerBitmap.cpp ServerCursor.cpp ServerFont.cpp ServerPicture.cpp ServerBitmap.cpp ServerCursor.cpp ServerFont.cpp ServerPicture.cpp
ServerWindow.cpp View.cpp Window.cpp WorkspacesView.cpp ServerWindow.cpp View.cpp Window.cpp WorkspacesView.cpp
$(decorator_src) $(font_src) ] $(decorator_src) $(font_src) ]
: [ BuildFeatureAttribute freetype : headers ] ; : [ BuildFeatureAttribute freetype : headers ] ;
@@ -51,6 +51,7 @@ Server app_server :
AppServer.cpp AppServer.cpp
#BitfieldRegion.cpp #BitfieldRegion.cpp
BitmapManager.cpp BitmapManager.cpp
Canvas.cpp
ClientMemoryAllocator.cpp ClientMemoryAllocator.cpp
CursorData.cpp CursorData.cpp
CursorManager.cpp CursorManager.cpp
@@ -59,7 +60,6 @@ Server app_server :
DesktopListener.cpp DesktopListener.cpp
DesktopSettings.cpp DesktopSettings.cpp
DirectWindowInfo.cpp DirectWindowInfo.cpp
DrawingContext.cpp
DrawState.cpp DrawState.cpp
EventDispatcher.cpp EventDispatcher.cpp
EventStream.cpp EventStream.cpp
@@ -97,7 +97,7 @@ Server app_server :
# libraries # libraries
: :
libtranslation.so libbe.so libbnetapi.so libtranslation.so libbe.so libbnetapi.so
libaslocal.a $(BROKEN_64)libasremote.a $(BROKEN_64)libashtml5.a libaslocal.a $(BROKEN_64)libasremote.a $(BROKEN_64)libashtml5.a
libasdrawing.a libpainter.a libagg.a libasdrawing.a libpainter.a libagg.a
[ BuildFeatureAttribute freetype : library ] [ BuildFeatureAttribute freetype : library ]
libstackandtile.a liblinprog.a libtextencoding.so libshared.a libstackandtile.a liblinprog.a libtextencoding.so libshared.a
+143 -143
View File
@@ -44,7 +44,7 @@ using std::stack;
class ShapePainter : public BShapeIterator { class ShapePainter : public BShapeIterator {
public: public:
ShapePainter(DrawingContext* context); ShapePainter(Canvas* canvas);
virtual ~ShapePainter(); virtual ~ShapePainter();
status_t Iterate(const BShape* shape); status_t Iterate(const BShape* shape);
@@ -59,15 +59,15 @@ public:
void Draw(BRect frame, bool filled); void Draw(BRect frame, bool filled);
private: private:
DrawingContext* fContext; Canvas* fCanvas;
stack<uint32> fOpStack; stack<uint32> fOpStack;
stack<BPoint> fPtStack; stack<BPoint> fPtStack;
}; };
ShapePainter::ShapePainter(DrawingContext* context) ShapePainter::ShapePainter(Canvas* canvas)
: :
fContext(context) fCanvas(canvas)
{ {
} }
@@ -203,10 +203,10 @@ ShapePainter::Draw(BRect frame, bool filled)
fPtStack.pop(); fPtStack.pop();
} }
BPoint offset(fContext->CurrentState()->PenLocation()); BPoint offset(fCanvas->CurrentState()->PenLocation());
fContext->ConvertToScreenForDrawing(&offset); fCanvas->ConvertToScreenForDrawing(&offset);
fContext->GetDrawingEngine()->DrawShape(frame, opCount, opList, fCanvas->GetDrawingEngine()->DrawShape(frame, opCount, opList,
ptCount, ptList, filled, offset, fContext->Scale()); ptCount, ptList, filled, offset, fCanvas->Scale());
delete[] opList; delete[] opList;
delete[] ptList; delete[] ptList;
@@ -253,23 +253,23 @@ nop()
static void static void
move_pen_by(DrawingContext* context, BPoint delta) move_pen_by(Canvas* canvas, BPoint delta)
{ {
context->CurrentState()->SetPenLocation( canvas->CurrentState()->SetPenLocation(
context->CurrentState()->PenLocation() + delta); canvas->CurrentState()->PenLocation() + delta);
} }
static void static void
stroke_line(DrawingContext* context, BPoint start, BPoint end) stroke_line(Canvas* canvas, BPoint start, BPoint end)
{ {
BPoint penPos = end; BPoint penPos = end;
context->ConvertToScreenForDrawing(&start); canvas->ConvertToScreenForDrawing(&start);
context->ConvertToScreenForDrawing(&end); canvas->ConvertToScreenForDrawing(&end);
context->GetDrawingEngine()->StrokeLine(start, end); canvas->GetDrawingEngine()->StrokeLine(start, end);
context->CurrentState()->SetPenLocation(penPos); canvas->CurrentState()->SetPenLocation(penPos);
// the DrawingEngine/Painter does not need to be updated, since this // the DrawingEngine/Painter does not need to be updated, since this
// effects only the view->screen coord conversion, which is handled // effects only the view->screen coord conversion, which is handled
// by the view only // by the view only
@@ -277,109 +277,109 @@ stroke_line(DrawingContext* context, BPoint start, BPoint end)
static void static void
stroke_rect(DrawingContext* context, BRect rect) stroke_rect(Canvas* canvas, BRect rect)
{ {
context->ConvertToScreenForDrawing(&rect); canvas->ConvertToScreenForDrawing(&rect);
context->GetDrawingEngine()->StrokeRect(rect); canvas->GetDrawingEngine()->StrokeRect(rect);
} }
static void static void
fill_rect(DrawingContext* context, BRect rect) fill_rect(Canvas* canvas, BRect rect)
{ {
context->ConvertToScreenForDrawing(&rect); canvas->ConvertToScreenForDrawing(&rect);
context->GetDrawingEngine()->FillRect(rect); canvas->GetDrawingEngine()->FillRect(rect);
} }
static void static void
draw_round_rect(DrawingContext* context, BRect rect, BPoint radii, bool fill) draw_round_rect(Canvas* canvas, BRect rect, BPoint radii, bool fill)
{ {
context->ConvertToScreenForDrawing(&rect); canvas->ConvertToScreenForDrawing(&rect);
float scale = context->CurrentState()->CombinedScale(); float scale = canvas->CurrentState()->CombinedScale();
context->GetDrawingEngine()->DrawRoundRect(rect, radii.x * scale, canvas->GetDrawingEngine()->DrawRoundRect(rect, radii.x * scale,
radii.y * scale, fill); radii.y * scale, fill);
} }
static void static void
stroke_round_rect(DrawingContext* context, BRect rect, BPoint radii) stroke_round_rect(Canvas* canvas, BRect rect, BPoint radii)
{ {
draw_round_rect(context, rect, radii, false); draw_round_rect(canvas, rect, radii, false);
} }
static void static void
fill_round_rect(DrawingContext* context, BRect rect, BPoint radii) fill_round_rect(Canvas* canvas, BRect rect, BPoint radii)
{ {
draw_round_rect(context, rect, radii, true); draw_round_rect(canvas, rect, radii, true);
} }
static void static void
stroke_bezier(DrawingContext* context, const BPoint* viewPoints) stroke_bezier(Canvas* canvas, const BPoint* viewPoints)
{ {
BPoint points[4]; BPoint points[4];
context->ConvertToScreenForDrawing(points, viewPoints, 4); canvas->ConvertToScreenForDrawing(points, viewPoints, 4);
context->GetDrawingEngine()->DrawBezier(points, false); canvas->GetDrawingEngine()->DrawBezier(points, false);
} }
static void static void
fill_bezier(DrawingContext* context, const BPoint* viewPoints) fill_bezier(Canvas* canvas, const BPoint* viewPoints)
{ {
BPoint points[4]; BPoint points[4];
context->ConvertToScreenForDrawing(points, viewPoints, 4); canvas->ConvertToScreenForDrawing(points, viewPoints, 4);
context->GetDrawingEngine()->DrawBezier(points, true); canvas->GetDrawingEngine()->DrawBezier(points, true);
} }
static void static void
stroke_arc(DrawingContext* context, BPoint center, BPoint radii, stroke_arc(Canvas* canvas, BPoint center, BPoint radii,
float startTheta, float arcTheta) float startTheta, float arcTheta)
{ {
BRect rect(center.x - radii.x, center.y - radii.y, BRect rect(center.x - radii.x, center.y - radii.y,
center.x + radii.x - 1, center.y + radii.y - 1); center.x + radii.x - 1, center.y + radii.y - 1);
context->ConvertToScreenForDrawing(&rect); canvas->ConvertToScreenForDrawing(&rect);
context->GetDrawingEngine()->DrawArc(rect, startTheta, arcTheta, false); canvas->GetDrawingEngine()->DrawArc(rect, startTheta, arcTheta, false);
} }
static void static void
fill_arc(DrawingContext* context, BPoint center, BPoint radii, fill_arc(Canvas* canvas, BPoint center, BPoint radii,
float startTheta, float arcTheta) float startTheta, float arcTheta)
{ {
BRect rect(center.x - radii.x, center.y - radii.y, BRect rect(center.x - radii.x, center.y - radii.y,
center.x + radii.x - 1, center.y + radii.y - 1); center.x + radii.x - 1, center.y + radii.y - 1);
context->ConvertToScreenForDrawing(&rect); canvas->ConvertToScreenForDrawing(&rect);
context->GetDrawingEngine()->DrawArc(rect, startTheta, arcTheta, true); canvas->GetDrawingEngine()->DrawArc(rect, startTheta, arcTheta, true);
} }
static void static void
stroke_ellipse(DrawingContext* context, BPoint center, BPoint radii) stroke_ellipse(Canvas* canvas, BPoint center, BPoint radii)
{ {
BRect rect(center.x - radii.x, center.y - radii.y, BRect rect(center.x - radii.x, center.y - radii.y,
center.x + radii.x - 1, center.y + radii.y - 1); center.x + radii.x - 1, center.y + radii.y - 1);
context->ConvertToScreenForDrawing(&rect); canvas->ConvertToScreenForDrawing(&rect);
context->GetDrawingEngine()->DrawEllipse(rect, false); canvas->GetDrawingEngine()->DrawEllipse(rect, false);
} }
static void static void
fill_ellipse(DrawingContext* context, BPoint center, BPoint radii) fill_ellipse(Canvas* canvas, BPoint center, BPoint radii)
{ {
BRect rect(center.x - radii.x, center.y - radii.y, BRect rect(center.x - radii.x, center.y - radii.y,
center.x + radii.x - 1, center.y + radii.y - 1); center.x + radii.x - 1, center.y + radii.y - 1);
context->ConvertToScreenForDrawing(&rect); canvas->ConvertToScreenForDrawing(&rect);
context->GetDrawingEngine()->DrawEllipse(rect, true); canvas->GetDrawingEngine()->DrawEllipse(rect, true);
} }
static void static void
stroke_polygon(DrawingContext* context, int32 numPoints, stroke_polygon(Canvas* canvas, int32 numPoints,
const BPoint* viewPoints, bool isClosed) const BPoint* viewPoints, bool isClosed)
{ {
if (numPoints <= 0) if (numPoints <= 0)
@@ -391,12 +391,12 @@ stroke_polygon(DrawingContext* context, int32 numPoints,
char data[200 * sizeof(BPoint)]; char data[200 * sizeof(BPoint)];
BPoint* points = (BPoint*)data; BPoint* points = (BPoint*)data;
context->ConvertToScreenForDrawing(points, viewPoints, numPoints); canvas->ConvertToScreenForDrawing(points, viewPoints, numPoints);
BRect polyFrame; BRect polyFrame;
get_polygon_frame(points, numPoints, &polyFrame); get_polygon_frame(points, numPoints, &polyFrame);
context->GetDrawingEngine()->DrawPolygon(points, numPoints, polyFrame, canvas->GetDrawingEngine()->DrawPolygon(points, numPoints, polyFrame,
false, isClosed && numPoints > 2); false, isClosed && numPoints > 2);
} else { } else {
// avoid constructor/destructor calls by // avoid constructor/destructor calls by
@@ -405,12 +405,12 @@ stroke_polygon(DrawingContext* context, int32 numPoints,
if (points == NULL) if (points == NULL)
return; return;
context->ConvertToScreenForDrawing(points, viewPoints, numPoints); canvas->ConvertToScreenForDrawing(points, viewPoints, numPoints);
BRect polyFrame; BRect polyFrame;
get_polygon_frame(points, numPoints, &polyFrame); get_polygon_frame(points, numPoints, &polyFrame);
context->GetDrawingEngine()->DrawPolygon(points, numPoints, polyFrame, canvas->GetDrawingEngine()->DrawPolygon(points, numPoints, polyFrame,
false, isClosed && numPoints > 2); false, isClosed && numPoints > 2);
free(points); free(points);
} }
@@ -418,7 +418,7 @@ stroke_polygon(DrawingContext* context, int32 numPoints,
static void static void
fill_polygon(DrawingContext* context, int32 numPoints, fill_polygon(Canvas* canvas, int32 numPoints,
const BPoint* viewPoints) const BPoint* viewPoints)
{ {
if (numPoints <= 0) if (numPoints <= 0)
@@ -430,12 +430,12 @@ fill_polygon(DrawingContext* context, int32 numPoints,
char data[200 * sizeof(BPoint)]; char data[200 * sizeof(BPoint)];
BPoint* points = (BPoint*)data; BPoint* points = (BPoint*)data;
context->ConvertToScreenForDrawing(points, viewPoints, numPoints); canvas->ConvertToScreenForDrawing(points, viewPoints, numPoints);
BRect polyFrame; BRect polyFrame;
get_polygon_frame(points, numPoints, &polyFrame); get_polygon_frame(points, numPoints, &polyFrame);
context->GetDrawingEngine()->DrawPolygon(points, numPoints, polyFrame, canvas->GetDrawingEngine()->DrawPolygon(points, numPoints, polyFrame,
true, true); true, true);
} else { } else {
// avoid constructor/destructor calls by // avoid constructor/destructor calls by
@@ -444,12 +444,12 @@ fill_polygon(DrawingContext* context, int32 numPoints,
if (points == NULL) if (points == NULL)
return; return;
context->ConvertToScreenForDrawing(points, viewPoints, numPoints); canvas->ConvertToScreenForDrawing(points, viewPoints, numPoints);
BRect polyFrame; BRect polyFrame;
get_polygon_frame(points, numPoints, &polyFrame); get_polygon_frame(points, numPoints, &polyFrame);
context->GetDrawingEngine()->DrawPolygon(points, numPoints, polyFrame, canvas->GetDrawingEngine()->DrawPolygon(points, numPoints, polyFrame,
true, true); true, true);
free(points); free(points);
} }
@@ -457,9 +457,9 @@ fill_polygon(DrawingContext* context, int32 numPoints,
static void static void
stroke_shape(DrawingContext* context, const BShape* shape) stroke_shape(Canvas* canvas, const BShape* shape)
{ {
ShapePainter drawShape(context); ShapePainter drawShape(canvas);
drawShape.Iterate(shape); drawShape.Iterate(shape);
drawShape.Draw(shape->Bounds(), false); drawShape.Draw(shape->Bounds(), false);
@@ -467,9 +467,9 @@ stroke_shape(DrawingContext* context, const BShape* shape)
static void static void
fill_shape(DrawingContext* context, const BShape* shape) fill_shape(Canvas* canvas, const BShape* shape)
{ {
ShapePainter drawShape(context); ShapePainter drawShape(canvas);
drawShape.Iterate(shape); drawShape.Iterate(shape);
drawShape.Draw(shape->Bounds(), true); drawShape.Draw(shape->Bounds(), true);
@@ -477,21 +477,21 @@ fill_shape(DrawingContext* context, const BShape* shape)
static void static void
draw_string(DrawingContext* context, const char* string, float deltaSpace, draw_string(Canvas* canvas, const char* string, float deltaSpace,
float deltaNonSpace) float deltaNonSpace)
{ {
// NOTE: the picture data was recorded with a "set pen location" // NOTE: the picture data was recorded with a "set pen location"
// command inserted before the "draw string" command, so we can // command inserted before the "draw string" command, so we can
// use PenLocation() // use PenLocation()
BPoint location = context->CurrentState()->PenLocation(); BPoint location = canvas->CurrentState()->PenLocation();
escapement_delta delta = { deltaSpace, deltaNonSpace }; escapement_delta delta = { deltaSpace, deltaNonSpace };
context->ConvertToScreenForDrawing(&location); canvas->ConvertToScreenForDrawing(&location);
location = context->GetDrawingEngine()->DrawString(string, strlen(string), location = canvas->GetDrawingEngine()->DrawString(string, strlen(string),
location, &delta); location, &delta);
context->ConvertFromScreenForDrawing(&location); canvas->ConvertFromScreenForDrawing(&location);
context->CurrentState()->SetPenLocation(location); canvas->CurrentState()->SetPenLocation(location);
// the DrawingEngine/Painter does not need to be updated, since this // the DrawingEngine/Painter does not need to be updated, since this
// effects only the view->screen coord conversion, which is handled // effects only the view->screen coord conversion, which is handled
// by the view only // by the view only
@@ -499,7 +499,7 @@ draw_string(DrawingContext* context, const char* string, float deltaSpace,
static void static void
draw_pixels(DrawingContext* context, BRect src, BRect dest, int32 width, draw_pixels(Canvas* canvas, BRect src, BRect dest, int32 width,
int32 height, int32 bytesPerRow, int32 pixelFormat, int32 options, int32 height, int32 bytesPerRow, int32 pixelFormat, int32 options,
const void* data) const void* data)
{ {
@@ -511,31 +511,31 @@ draw_pixels(DrawingContext* context, BRect src, BRect dest, int32 width,
memcpy(bitmap.Bits(), data, height * bytesPerRow); memcpy(bitmap.Bits(), data, height * bytesPerRow);
context->ConvertToScreenForDrawing(&dest); canvas->ConvertToScreenForDrawing(&dest);
context->GetDrawingEngine()->DrawBitmap(&bitmap, src, dest, options); canvas->GetDrawingEngine()->DrawBitmap(&bitmap, src, dest, options);
} }
static void static void
draw_picture(DrawingContext* context, BPoint where, int32 token) draw_picture(Canvas* canvas, BPoint where, int32 token)
{ {
ServerPicture* picture = context->GetPicture(token); ServerPicture* picture = canvas->GetPicture(token);
if (picture != NULL) { if (picture != NULL) {
context->PushState(); canvas->PushState();
context->SetDrawingOrigin(where); canvas->SetDrawingOrigin(where);
context->PushState(); canvas->PushState();
picture->Play(context); picture->Play(canvas);
context->PopState(); canvas->PopState();
context->PopState(); canvas->PopState();
picture->ReleaseReference(); picture->ReleaseReference();
} }
} }
static void static void
set_clipping_rects(DrawingContext* context, const BRect* rects, set_clipping_rects(Canvas* canvas, const BRect* rects,
uint32 numRects) uint32 numRects)
{ {
// TODO: This might be too slow, we should copy the rects // TODO: This might be too slow, we should copy the rects
@@ -543,13 +543,13 @@ set_clipping_rects(DrawingContext* context, const BRect* rects,
BRegion region; BRegion region;
for (uint32 c = 0; c < numRects; c++) for (uint32 c = 0; c < numRects; c++)
region.Include(rects[c]); region.Include(rects[c]);
context->SetUserClipping(&region); canvas->SetUserClipping(&region);
context->UpdateCurrentDrawingRegion(); canvas->UpdateCurrentDrawingRegion();
} }
static void static void
clip_to_picture(DrawingContext* context, BPicture* picture, BPoint pt, clip_to_picture(Canvas* canvas, BPicture* picture, BPoint pt,
bool clipToInverse) bool clipToInverse)
{ {
printf("ClipToPicture(picture, BPoint(%.2f, %.2f), %s)\n", printf("ClipToPicture(picture, BPoint(%.2f, %.2f), %s)\n",
@@ -558,20 +558,20 @@ clip_to_picture(DrawingContext* context, BPicture* picture, BPoint pt,
static void static void
push_state(DrawingContext* context) push_state(Canvas* canvas)
{ {
context->PushState(); canvas->PushState();
} }
static void static void
pop_state(DrawingContext* context) pop_state(Canvas* canvas)
{ {
context->PopState(); canvas->PopState();
BPoint p(0, 0); BPoint p(0, 0);
context->ConvertToScreenForDrawing(&p); canvas->ConvertToScreenForDrawing(&p);
context->GetDrawingEngine()->SetDrawState(context->CurrentState(), canvas->GetDrawingEngine()->SetDrawState(canvas->CurrentState(),
(int32)p.x, (int32)p.y); (int32)p.x, (int32)p.y);
} }
@@ -579,42 +579,42 @@ pop_state(DrawingContext* context)
// TODO: Be smart and actually take advantage of these methods: // TODO: Be smart and actually take advantage of these methods:
// only apply state changes when they are called // only apply state changes when they are called
static void static void
enter_state_change(DrawingContext* context) enter_state_change(Canvas* canvas)
{ {
} }
static void static void
exit_state_change(DrawingContext* context) exit_state_change(Canvas* canvas)
{ {
context->ResyncDrawState(); canvas->ResyncDrawState();
} }
static void static void
enter_font_state(DrawingContext* context) enter_font_state(Canvas* canvas)
{ {
} }
static void static void
exit_font_state(DrawingContext* context) exit_font_state(Canvas* canvas)
{ {
context->GetDrawingEngine()->SetFont(context->CurrentState()->Font()); canvas->GetDrawingEngine()->SetFont(canvas->CurrentState()->Font());
} }
static void static void
set_origin(DrawingContext* context, BPoint pt) set_origin(Canvas* canvas, BPoint pt)
{ {
context->CurrentState()->SetOrigin(pt); canvas->CurrentState()->SetOrigin(pt);
} }
static void static void
set_pen_location(DrawingContext* context, BPoint pt) set_pen_location(Canvas* canvas, BPoint pt)
{ {
context->CurrentState()->SetPenLocation(pt); canvas->CurrentState()->SetPenLocation(pt);
// the DrawingEngine/Painter does not need to be updated, since this // the DrawingEngine/Painter does not need to be updated, since this
// effects only the view->screen coord conversion, which is handled // effects only the view->screen coord conversion, which is handled
// by the view only // by the view only
@@ -622,65 +622,65 @@ set_pen_location(DrawingContext* context, BPoint pt)
static void static void
set_drawing_mode(DrawingContext* context, drawing_mode mode) set_drawing_mode(Canvas* canvas, drawing_mode mode)
{ {
context->CurrentState()->SetDrawingMode(mode); canvas->CurrentState()->SetDrawingMode(mode);
context->GetDrawingEngine()->SetDrawingMode(mode); canvas->GetDrawingEngine()->SetDrawingMode(mode);
} }
static void static void
set_line_mode(DrawingContext* context, cap_mode capMode, join_mode joinMode, set_line_mode(Canvas* canvas, cap_mode capMode, join_mode joinMode,
float miterLimit) float miterLimit)
{ {
DrawState* state = context->CurrentState(); DrawState* state = canvas->CurrentState();
state->SetLineCapMode(capMode); state->SetLineCapMode(capMode);
state->SetLineJoinMode(joinMode); state->SetLineJoinMode(joinMode);
state->SetMiterLimit(miterLimit); state->SetMiterLimit(miterLimit);
context->GetDrawingEngine()->SetStrokeMode(capMode, joinMode, miterLimit); canvas->GetDrawingEngine()->SetStrokeMode(capMode, joinMode, miterLimit);
} }
static void static void
set_pen_size(DrawingContext* context, float size) set_pen_size(Canvas* canvas, float size)
{ {
context->CurrentState()->SetPenSize(size); canvas->CurrentState()->SetPenSize(size);
context->GetDrawingEngine()->SetPenSize( canvas->GetDrawingEngine()->SetPenSize(
context->CurrentState()->PenSize()); canvas->CurrentState()->PenSize());
// DrawState::PenSize() returns the scaled pen size, so we // DrawState::PenSize() returns the scaled pen size, so we
// need to use that value to set the drawing engine pen size. // need to use that value to set the drawing engine pen size.
} }
static void static void
set_fore_color(DrawingContext* context, rgb_color color) set_fore_color(Canvas* canvas, rgb_color color)
{ {
context->CurrentState()->SetHighColor(color); canvas->CurrentState()->SetHighColor(color);
context->GetDrawingEngine()->SetHighColor(color); canvas->GetDrawingEngine()->SetHighColor(color);
} }
static void static void
set_back_color(DrawingContext* context, rgb_color color) set_back_color(Canvas* canvas, rgb_color color)
{ {
context->CurrentState()->SetLowColor(color); canvas->CurrentState()->SetLowColor(color);
context->GetDrawingEngine()->SetLowColor(color); canvas->GetDrawingEngine()->SetLowColor(color);
} }
static void static void
set_stipple_pattern(DrawingContext* context, pattern p) set_stipple_pattern(Canvas* canvas, pattern p)
{ {
context->CurrentState()->SetPattern(Pattern(p)); canvas->CurrentState()->SetPattern(Pattern(p));
context->GetDrawingEngine()->SetPattern(p); canvas->GetDrawingEngine()->SetPattern(p);
} }
static void static void
set_scale(DrawingContext* context, float scale) set_scale(Canvas* canvas, float scale)
{ {
context->CurrentState()->SetScale(scale); canvas->CurrentState()->SetScale(scale);
context->ResyncDrawState(); canvas->ResyncDrawState();
// Update the drawing engine draw state, since some stuff // Update the drawing engine draw state, since some stuff
// (for example the pen size) needs to be recalculated. // (for example the pen size) needs to be recalculated.
@@ -688,94 +688,94 @@ set_scale(DrawingContext* context, float scale)
static void static void
set_font_family(DrawingContext* context, const char* family) set_font_family(Canvas* canvas, const char* family)
{ {
FontStyle* fontStyle = gFontManager->GetStyleByIndex(family, 0); FontStyle* fontStyle = gFontManager->GetStyleByIndex(family, 0);
ServerFont font; ServerFont font;
font.SetStyle(fontStyle); font.SetStyle(fontStyle);
context->CurrentState()->SetFont(font, B_FONT_FAMILY_AND_STYLE); canvas->CurrentState()->SetFont(font, B_FONT_FAMILY_AND_STYLE);
} }
static void static void
set_font_style(DrawingContext* context, const char* style) set_font_style(Canvas* canvas, const char* style)
{ {
ServerFont font(context->CurrentState()->Font()); ServerFont font(canvas->CurrentState()->Font());
FontStyle* fontStyle = gFontManager->GetStyle(font.Family(), style); FontStyle* fontStyle = gFontManager->GetStyle(font.Family(), style);
font.SetStyle(fontStyle); font.SetStyle(fontStyle);
context->CurrentState()->SetFont(font, B_FONT_FAMILY_AND_STYLE); canvas->CurrentState()->SetFont(font, B_FONT_FAMILY_AND_STYLE);
} }
static void static void
set_font_spacing(DrawingContext* context, int32 spacing) set_font_spacing(Canvas* canvas, int32 spacing)
{ {
ServerFont font; ServerFont font;
font.SetSpacing(spacing); font.SetSpacing(spacing);
context->CurrentState()->SetFont(font, B_FONT_SPACING); canvas->CurrentState()->SetFont(font, B_FONT_SPACING);
} }
static void static void
set_font_size(DrawingContext* context, float size) set_font_size(Canvas* canvas, float size)
{ {
ServerFont font; ServerFont font;
font.SetSize(size); font.SetSize(size);
context->CurrentState()->SetFont(font, B_FONT_SIZE); canvas->CurrentState()->SetFont(font, B_FONT_SIZE);
} }
static void static void
set_font_rotate(DrawingContext* context, float rotation) set_font_rotate(Canvas* canvas, float rotation)
{ {
ServerFont font; ServerFont font;
font.SetRotation(rotation); font.SetRotation(rotation);
context->CurrentState()->SetFont(font, B_FONT_ROTATION); canvas->CurrentState()->SetFont(font, B_FONT_ROTATION);
} }
static void static void
set_font_encoding(DrawingContext* context, int32 encoding) set_font_encoding(Canvas* canvas, int32 encoding)
{ {
ServerFont font; ServerFont font;
font.SetEncoding(encoding); font.SetEncoding(encoding);
context->CurrentState()->SetFont(font, B_FONT_ENCODING); canvas->CurrentState()->SetFont(font, B_FONT_ENCODING);
} }
static void static void
set_font_flags(DrawingContext* context, int32 flags) set_font_flags(Canvas* canvas, int32 flags)
{ {
ServerFont font; ServerFont font;
font.SetFlags(flags); font.SetFlags(flags);
context->CurrentState()->SetFont(font, B_FONT_FLAGS); canvas->CurrentState()->SetFont(font, B_FONT_FLAGS);
} }
static void static void
set_font_shear(DrawingContext* context, float shear) set_font_shear(Canvas* canvas, float shear)
{ {
ServerFont font; ServerFont font;
font.SetShear(shear); font.SetShear(shear);
context->CurrentState()->SetFont(font, B_FONT_SHEAR); canvas->CurrentState()->SetFont(font, B_FONT_SHEAR);
} }
static void static void
set_font_face(DrawingContext* context, int32 face) set_font_face(Canvas* canvas, int32 face)
{ {
ServerFont font; ServerFont font;
font.SetFace(face); font.SetFace(face);
context->CurrentState()->SetFont(font, B_FONT_FACE); canvas->CurrentState()->SetFont(font, B_FONT_FACE);
} }
static void static void
set_blending_mode(DrawingContext* context, int16 alphaSrcMode, int16 alphaFncMode) set_blending_mode(Canvas* canvas, int16 alphaSrcMode, int16 alphaFncMode)
{ {
context->CurrentState()->SetBlendingMode((source_alpha)alphaSrcMode, canvas->CurrentState()->SetBlendingMode((source_alpha)alphaSrcMode,
(alpha_function)alphaFncMode); (alpha_function)alphaFncMode);
} }
@@ -1068,7 +1068,7 @@ ServerPicture::SetFontFromLink(BPrivate::LinkReceiver& link)
void void
ServerPicture::Play(DrawingContext* target) ServerPicture::Play(Canvas* target)
{ {
// TODO: for now: then change PicturePlayer // TODO: for now: then change PicturePlayer
// to accept a BPositionIO object // to accept a BPositionIO object
+2 -2
View File
@@ -18,7 +18,7 @@
class BFile; class BFile;
class DrawingContext; class Canvas;
class ServerApp; class ServerApp;
class View; class View;
@@ -49,7 +49,7 @@ public:
void SyncState(View* view); void SyncState(View* view);
void SetFontFromLink(BPrivate::LinkReceiver& link); void SetFontFromLink(BPrivate::LinkReceiver& link);
void Play(DrawingContext* target); void Play(Canvas* target);
void PushPicture(ServerPicture* picture); void PushPicture(ServerPicture* picture);
ServerPicture* PopPicture(); ServerPicture* PopPicture();
+2 -2
View File
@@ -14,7 +14,7 @@
#define VIEW_H #define VIEW_H
#include "DrawingContext.h" #include "Canvas.h"
#include "IntRect.h" #include "IntRect.h"
#include <GraphicsDefs.h> #include <GraphicsDefs.h>
@@ -37,7 +37,7 @@ class ServerCursor;
class ServerPicture; class ServerPicture;
class BGradient; class BGradient;
class View: public DrawingContext { class View: public Canvas {
public: public:
View(IntRect frame, IntPoint scrollingOffset, View(IntRect frame, IntPoint scrollingOffset,
const char* name, int32 token, const char* name, int32 token,
+8 -8
View File
@@ -12,7 +12,7 @@
#include "BitmapHWInterface.h" #include "BitmapHWInterface.h"
#include "BitmapManager.h" #include "BitmapManager.h"
#include "DrawingContext.h" #include "Canvas.h"
#include "DrawingEngine.h" #include "DrawingEngine.h"
#include "ServerBitmap.h" #include "ServerBitmap.h"
#include "ServerPicture.h" #include "ServerPicture.h"
@@ -56,7 +56,7 @@ AlphaMask::Update(BRect bounds, BPoint offset)
{ {
fViewBounds = bounds; fViewBounds = bounds;
fViewOffset = offset; fViewOffset = offset;
if (fPreviousMask != NULL) if (fPreviousMask != NULL)
fPreviousMask->Update(bounds, offset); fPreviousMask->Update(bounds, offset);
} }
@@ -98,7 +98,7 @@ AlphaMask::Generate()
delete[] fCachedBitmap; delete[] fCachedBitmap;
fCachedBitmap = new(std::nothrow) uint8[width * height]; fCachedBitmap = new(std::nothrow) uint8[width * height];
} }
// If rendering the picture fails, we will draw without any clipping. // If rendering the picture fails, we will draw without any clipping.
ServerBitmap* bitmap = _RenderPicture(); ServerBitmap* bitmap = _RenderPicture();
if (bitmap == NULL || fCachedBitmap == NULL) { if (bitmap == NULL || fCachedBitmap == NULL) {
@@ -140,7 +140,7 @@ AlphaMask::Generate()
transferBitmap = false; transferBitmap = false;
} }
} }
if (transferBitmap) { if (transferBitmap) {
for (uint32 y = 0; y < height; y++) { for (uint32 y = 0; y < height; y++) {
for (uint32 x = 0; x < width; x++) { for (uint32 x = 0; x < width; x++) {
@@ -194,8 +194,8 @@ AlphaMask::_RenderPicture() const
return NULL; return NULL;
} }
OffscreenContext context(engine, fDrawState); OffscreenCanvas canvas(engine, fDrawState);
context.PushState(); canvas.PushState();
if (engine->LockParallelAccess()) { if (engine->LockParallelAccess()) {
// FIXME ConstrainClippingRegion docs says passing NULL disables // FIXME ConstrainClippingRegion docs says passing NULL disables
@@ -203,11 +203,11 @@ AlphaMask::_RenderPicture() const
BRegion clipping; BRegion clipping;
clipping.Include(fViewBounds); clipping.Include(fViewBounds);
engine->ConstrainClippingRegion(&clipping); engine->ConstrainClippingRegion(&clipping);
fPicture->Play(&context); fPicture->Play(&canvas);
engine->UnlockParallelAccess(); engine->UnlockParallelAccess();
} }
context.PopState(); canvas.PopState();
delete engine; delete engine;
return bitmap; return bitmap;
+3 -3
View File
@@ -152,8 +152,8 @@ SharedLibrary libtestappserver.so :
AlphaMask.cpp AlphaMask.cpp
BitmapHWInterface.cpp BitmapHWInterface.cpp
Canvas.cpp
DesktopSettings.cpp DesktopSettings.cpp
DrawingContext.cpp
OffscreenServerWindow.cpp OffscreenServerWindow.cpp
OffscreenWindow.cpp OffscreenWindow.cpp
RegionPool.cpp RegionPool.cpp
@@ -173,9 +173,9 @@ SharedLibrary libtestappserver.so :
[ BuildFeatureAttribute freetype : library ] [ BuildFeatureAttribute freetype : library ]
; ;
Includes [ FGristFiles AppServer.cpp BitmapManager.cpp Includes [ FGristFiles AppServer.cpp BitmapManager.cpp Canvas.cpp
ClientMemoryAllocator.cpp Desktop.cpp DesktopSettings.cpp ClientMemoryAllocator.cpp Desktop.cpp DesktopSettings.cpp
DrawState.cpp DrawingContext.cpp DrawingEngine.cpp ServerApp.cpp DrawState.cpp DrawingEngine.cpp ServerApp.cpp
ServerBitmap.cpp ServerCursor.cpp ServerFont.cpp ServerPicture.cpp ServerBitmap.cpp ServerCursor.cpp ServerFont.cpp ServerPicture.cpp
ServerWindow.cpp View.cpp Window.cpp WorkspacesView.cpp ServerWindow.cpp View.cpp Window.cpp WorkspacesView.cpp
$(decorator_src) $(font_src) ] $(decorator_src) $(font_src) ]