diff options
| author | Neil <nyamatongwe@gmail.com> | 2021-03-20 16:25:35 +1100 | 
|---|---|---|
| committer | Neil <nyamatongwe@gmail.com> | 2021-03-20 16:25:35 +1100 | 
| commit | 434ea41aa400557964d73867008cfa8b1f64d8c4 (patch) | |
| tree | 7a6981a28f521391a97cdbd4224fd81b2035bf24 /src | |
| parent | 3d45c4bf974b6fdcce9712bbd3f0071a9618b89f (diff) | |
| download | scintilla-mirror-434ea41aa400557964d73867008cfa8b1f64d8c4.tar.gz | |
Use Surface::AllocatePixMap instead of changing an existing surface with
InitPixMap. Changed DropGraphics from releasing surfaces to deleting them.
This simplifies code and the added cost of allocating a new Surface is small.
Diffstat (limited to 'src')
| -rw-r--r-- | src/EditView.cxx | 34 | ||||
| -rw-r--r-- | src/EditView.h | 5 | ||||
| -rw-r--r-- | src/Editor.cxx | 36 | ||||
| -rw-r--r-- | src/Editor.h | 3 | ||||
| -rw-r--r-- | src/MarginView.cxx | 34 | ||||
| -rw-r--r-- | src/MarginView.h | 5 | 
6 files changed, 34 insertions, 83 deletions
| diff --git a/src/EditView.cxx b/src/EditView.cxx index 8243169d0..a835ab0a0 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -251,28 +251,10 @@ void EditView::LinesAddedOrRemoved(Sci::Line lineOfPos, Sci::Line linesAdded) {  	}  } -void EditView::DropGraphics(bool freeObjects) noexcept { -	if (freeObjects) { -		pixmapLine.reset(); -		pixmapIndentGuide.reset(); -		pixmapIndentGuideHighlight.reset(); -	} else { -		if (pixmapLine) -			pixmapLine->Release(); -		if (pixmapIndentGuide) -			pixmapIndentGuide->Release(); -		if (pixmapIndentGuideHighlight) -			pixmapIndentGuideHighlight->Release(); -	} -} - -void EditView::AllocateGraphics(const ViewStyle &vsDraw) { -	if (!pixmapLine) -		pixmapLine = Surface::Allocate(vsDraw.technology); -	if (!pixmapIndentGuide) -		pixmapIndentGuide = Surface::Allocate(vsDraw.technology); -	if (!pixmapIndentGuideHighlight) -		pixmapIndentGuideHighlight = Surface::Allocate(vsDraw.technology); +void EditView::DropGraphics() noexcept { +	pixmapLine.reset(); +	pixmapIndentGuide.reset(); +	pixmapIndentGuideHighlight.reset();  }  static const char *ControlCharacterString(unsigned char ch) noexcept { @@ -311,11 +293,11 @@ static void DrawTabArrow(Surface *surface, PRectangle rcTab, int ymid, const Vie  	}  } -void EditView::RefreshPixMaps(Surface *surfaceWindow, WindowID wid, const ViewStyle &vsDraw) { -	if (!pixmapIndentGuide->Initialised()) { +void EditView::RefreshPixMaps(Surface *surfaceWindow, const ViewStyle &vsDraw) { +	if (!pixmapIndentGuide) {  		// 1 extra pixel in height so can handle odd/even positions and so produce a continuous line -		pixmapIndentGuide->InitPixMap(1, vsDraw.lineHeight + 1, surfaceWindow, wid); -		pixmapIndentGuideHighlight->InitPixMap(1, vsDraw.lineHeight + 1, surfaceWindow, wid); +		pixmapIndentGuide = surfaceWindow->AllocatePixMap(1, vsDraw.lineHeight + 1); +		pixmapIndentGuideHighlight = surfaceWindow->AllocatePixMap(1, vsDraw.lineHeight + 1);  		const PRectangle rcIG = PRectangle::FromInts(0, 0, 1, vsDraw.lineHeight);  		pixmapIndentGuide->FillRectangle(rcIG, vsDraw.styles[STYLE_INDENTGUIDE].back);  		pixmapIndentGuideHighlight->FillRectangle(rcIG, vsDraw.styles[STYLE_BRACELIGHT].back); diff --git a/src/EditView.h b/src/EditView.h index 11fe5c659..f5df7143f 100644 --- a/src/EditView.h +++ b/src/EditView.h @@ -109,9 +109,8 @@ public:  	int GetNextTabstop(Sci::Line line, int x) const noexcept;  	void LinesAddedOrRemoved(Sci::Line lineOfPos, Sci::Line linesAdded); -	void DropGraphics(bool freeObjects) noexcept; -	void AllocateGraphics(const ViewStyle &vsDraw); -	void RefreshPixMaps(Surface *surfaceWindow, WindowID wid, const ViewStyle &vsDraw); +	void DropGraphics() noexcept; +	void RefreshPixMaps(Surface *surfaceWindow, const ViewStyle &vsDraw);  	LineLayout *RetrieveLineLayout(Sci::Line lineNumber, const EditModel &model);  	void LayoutLine(const EditModel &model, Sci::Line line, Surface *surface, const ViewStyle &vstyle, diff --git a/src/Editor.cxx b/src/Editor.cxx index 15936e150..44c80451b 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -199,7 +199,7 @@ Editor::Editor() : durationWrapOneLine(0.00001, 0.000001, 0.0001) {  Editor::~Editor() {  	pdoc->RemoveWatcher(this, 0); -	DropGraphics(true); +	DropGraphics();  }  void Editor::Finalise() { @@ -262,21 +262,15 @@ void Editor::SetRepresentations() {  	}  } -void Editor::DropGraphics(bool freeObjects) noexcept { -	marginView.DropGraphics(freeObjects); -	view.DropGraphics(freeObjects); -} - -void Editor::AllocateGraphics() { -	marginView.AllocateGraphics(vs); -	view.AllocateGraphics(vs); +void Editor::DropGraphics() noexcept { +	marginView.DropGraphics(); +	view.DropGraphics();  }  void Editor::InvalidateStyleData() {  	stylesValid = false;  	vs.technology = technology; -	DropGraphics(false); -	AllocateGraphics(); +	DropGraphics();  	view.llc.Invalidate(LineLayout::ValidLevel::invalid);  	view.posCache.Clear();  } @@ -1677,7 +1671,6 @@ void Editor::PaintSelMargin(Surface *surfaceWindow, const PRectangle &rc) {  	if (vs.fixedColumnWidth == 0)  		return; -	AllocateGraphics();  	RefreshStyleData();  	RefreshPixMaps(surfaceWindow); @@ -1719,18 +1712,16 @@ void Editor::PaintSelMargin(Surface *surfaceWindow, const PRectangle &rc) {  }  void Editor::RefreshPixMaps(Surface *surfaceWindow) { -	view.RefreshPixMaps(surfaceWindow, wMain.GetID(), vs); -	marginView.RefreshPixMaps(surfaceWindow, wMain.GetID(), vs); +	view.RefreshPixMaps(surfaceWindow, vs); +	marginView.RefreshPixMaps(surfaceWindow, vs);  	if (view.bufferedDraw) {  		const PRectangle rcClient = GetClientRectangle(); -		if (!view.pixmapLine->Initialised()) { - -			view.pixmapLine->InitPixMap(static_cast<int>(rcClient.Width()), vs.lineHeight, -			        surfaceWindow, wMain.GetID()); +		if (!view.pixmapLine) { +			view.pixmapLine = surfaceWindow->AllocatePixMap(static_cast<int>(rcClient.Width()), vs.lineHeight);  		} -		if (!marginView.pixmapSelMargin->Initialised()) { -			marginView.pixmapSelMargin->InitPixMap(vs.fixedColumnWidth, -				static_cast<int>(rcClient.Height()), surfaceWindow, wMain.GetID()); +		if (!marginView.pixmapSelMargin) { +			marginView.pixmapSelMargin = surfaceWindow->AllocatePixMap(vs.fixedColumnWidth, +				static_cast<int>(rcClient.Height()));  		}  	}  } @@ -1738,7 +1729,6 @@ void Editor::RefreshPixMaps(Surface *surfaceWindow) {  void Editor::Paint(Surface *surfaceWindow, PRectangle rcArea) {  	//Platform::DebugPrintf("Paint:%1d (%3d,%3d) ... (%3d,%3d)\n",  	//	paintingAllText, rcArea.left, rcArea.top, rcArea.right, rcArea.bottom); -	AllocateGraphics();  	RefreshStyleData();  	if (paintState == PaintState::abandoned) @@ -1882,7 +1872,7 @@ void Editor::SetScrollBars() {  }  void Editor::ChangeSize() { -	DropGraphics(false); +	DropGraphics();  	SetScrollBars();  	if (Wrapping()) {  		PRectangle rcTextArea = GetClientRectangle(); diff --git a/src/Editor.h b/src/Editor.h index fc3a84ecd..d4f997af6 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -284,8 +284,7 @@ protected:	// ScintillaBase subclass needs access to much of Editor  	void InvalidateStyleRedraw();  	void RefreshStyleData();  	void SetRepresentations(); -	void DropGraphics(bool freeObjects) noexcept; -	void AllocateGraphics(); +	void DropGraphics() noexcept;  	// The top left visible point in main window coordinates. Will be 0,0 except for  	// scroll views where it will be equivalent to the current scroll position. diff --git a/src/MarginView.cxx b/src/MarginView.cxx index 4d040776d..913fd0e2d 100644 --- a/src/MarginView.cxx +++ b/src/MarginView.cxx @@ -109,35 +109,17 @@ MarginView::MarginView() noexcept {  	customDrawWrapMarker = nullptr;  } -void MarginView::DropGraphics(bool freeObjects) noexcept { -	if (freeObjects) { -		pixmapSelMargin.reset(); -		pixmapSelPattern.reset(); -		pixmapSelPatternOffset1.reset(); -	} else { -		if (pixmapSelMargin) -			pixmapSelMargin->Release(); -		if (pixmapSelPattern) -			pixmapSelPattern->Release(); -		if (pixmapSelPatternOffset1) -			pixmapSelPatternOffset1->Release(); -	} -} - -void MarginView::AllocateGraphics(const ViewStyle &vsDraw) { -	if (!pixmapSelMargin) -		pixmapSelMargin = Surface::Allocate(vsDraw.technology); -	if (!pixmapSelPattern) -		pixmapSelPattern = Surface::Allocate(vsDraw.technology); -	if (!pixmapSelPatternOffset1) -		pixmapSelPatternOffset1 = Surface::Allocate(vsDraw.technology); +void MarginView::DropGraphics() noexcept { +	pixmapSelMargin.reset(); +	pixmapSelPattern.reset(); +	pixmapSelPatternOffset1.reset();  } -void MarginView::RefreshPixMaps(Surface *surfaceWindow, WindowID wid, const ViewStyle &vsDraw) { -	if (!pixmapSelPattern->Initialised()) { +void MarginView::RefreshPixMaps(Surface *surfaceWindow, const ViewStyle &vsDraw) { +	if (!pixmapSelPattern) {  		const int patternSize = 8; -		pixmapSelPattern->InitPixMap(patternSize, patternSize, surfaceWindow, wid); -		pixmapSelPatternOffset1->InitPixMap(patternSize, patternSize, surfaceWindow, wid); +		pixmapSelPattern = surfaceWindow->AllocatePixMap(patternSize, patternSize); +		pixmapSelPatternOffset1 = surfaceWindow->AllocatePixMap(patternSize, patternSize);  		// This complex procedure is to reproduce the checkerboard dithered pattern used by windows  		// for scroll bars and Visual Studio for its selection margin. The colour of this pattern is half  		// way between the chrome colour and the chrome highlight colour making a nice transition diff --git a/src/MarginView.h b/src/MarginView.h index bb1981ed8..9d74ddb5e 100644 --- a/src/MarginView.h +++ b/src/MarginView.h @@ -34,9 +34,8 @@ public:  	MarginView() noexcept; -	void DropGraphics(bool freeObjects) noexcept; -	void AllocateGraphics(const ViewStyle &vsDraw); -	void RefreshPixMaps(Surface *surfaceWindow, WindowID wid, const ViewStyle &vsDraw); +	void DropGraphics() noexcept; +	void RefreshPixMaps(Surface *surfaceWindow, const ViewStyle &vsDraw);  	void PaintMargin(Surface *surface, Sci::Line topLine, PRectangle rc, PRectangle rcMargin,  		const EditModel &model, const ViewStyle &vs);  }; | 
