Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(706)

Unified Diff: src/pdf/SkPDFCanon.cpp

Issue 873543002: More changes to SkPDFShader to eliminate multiple inheritance! (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/pdf/SkPDFCanon.cpp
diff --git a/src/pdf/SkPDFCanon.cpp b/src/pdf/SkPDFCanon.cpp
index 31212f8c91564d5568ea5f56371593435463bc17..bea1400bd64ca5de40a59d78fe38dc6ea061211f 100644
--- a/src/pdf/SkPDFCanon.cpp
+++ b/src/pdf/SkPDFCanon.cpp
@@ -37,6 +37,32 @@ static void assert_mutex_held(const SkPDFCanon* canon, SkBaseMutex& mutex) {
}
}
+template <class T> T* assert_ptr(T* p) { SkASSERT(p); return p; }
+
+// TODO(halcanary): add this method to SkTDArray.
mtklein 2015/01/23 14:16:11 I'm on board with a ? at the end. Generally I don
+template <typename T>
+bool remove_item(SkTDArray<T>* array, const T& elem) {
+ int i = array->find(elem);
+ if (i >= 0) {
+ array->removeShuffle(i);
+ return true;
+ }
+ return false;
+}
+
+// requires `bool T::equals(const U&) const`
+template <typename T, typename U>
+T* find_item(const SkTDArray<T*>& ptrArray, const U& object) {
mtklein 2015/01/23 14:16:11 consider object -> key ?
+ for (int i = 0; i < ptrArray.count(); ++i) {
+ if (ptrArray[i]->equals(object)) {
+ return ptrArray[i];
+ }
+ }
+ return NULL;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
SkPDFFont* SkPDFCanon::findFont(uint32_t fontID,
uint16_t glyphID,
SkPDFFont** relatedFontPtr) const {
@@ -79,58 +105,67 @@ void SkPDFCanon::removeFont(SkPDFFont* pdfFont) {
////////////////////////////////////////////////////////////////////////////////
-SkPDFShader* SkPDFCanon::findShader(const SkPDFShader::State& state) const {
+SkPDFFunctionShader* SkPDFCanon::findFunctionShader(
+ const SkPDFShader::State& state) const {
assert_mutex_held(this, gSkPDFCanonShaderMutex);
- for (int i = 0; i < fShaderRecords.count(); ++i) {
- if (fShaderRecords[i]->equals(state)) {
- return fShaderRecords[i];
- }
- }
- return NULL;
+ return find_item(fFunctionShaderRecords, state);
+}
+void SkPDFCanon::addFunctionShader(SkPDFFunctionShader* pdfShader) {
+ assert_mutex_held(this, gSkPDFCanonShaderMutex);
+ fFunctionShaderRecords.push(assert_ptr(pdfShader));
+}
+void SkPDFCanon::removeFunctionShader(SkPDFFunctionShader* pdfShader) {
+ assert_mutex_held(this, gSkPDFCanonShaderMutex);
+ SkAssertResult(remove_item(&fFunctionShaderRecords, pdfShader));
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+SkPDFAlphaFunctionShader* SkPDFCanon::findAlphaShader(
+ const SkPDFShader::State& state) const {
+ assert_mutex_held(this, gSkPDFCanonShaderMutex);
+ return find_item(fAlphaShaderRecords, state);
+}
+void SkPDFCanon::addAlphaShader(SkPDFAlphaFunctionShader* pdfShader) {
+ assert_mutex_held(this, gSkPDFCanonShaderMutex);
+ fAlphaShaderRecords.push(assert_ptr(pdfShader));
+}
+void SkPDFCanon::removeAlphaShader(SkPDFAlphaFunctionShader* pdfShader) {
+ assert_mutex_held(this, gSkPDFCanonShaderMutex);
+ SkAssertResult(remove_item(&fAlphaShaderRecords, pdfShader));
}
-void SkPDFCanon::addShader(SkPDFShader* shader) {
+////////////////////////////////////////////////////////////////////////////////
+
+SkPDFImageShader* SkPDFCanon::findImageShader(
+ const SkPDFShader::State& state) const {
assert_mutex_held(this, gSkPDFCanonShaderMutex);
- SkASSERT(shader);
- fShaderRecords.push(shader);
+ return find_item(fImageShaderRecords, state);
}
-void SkPDFCanon::removeShader(SkPDFShader* pdfShader) {
+void SkPDFCanon::addImageShader(SkPDFImageShader* pdfShader) {
assert_mutex_held(this, gSkPDFCanonShaderMutex);
- for (int i = 0; i < fShaderRecords.count(); ++i) {
- if (fShaderRecords[i] == pdfShader) {
- fShaderRecords.removeShuffle(i);
- return;
- }
- }
- SkDEBUGFAIL("pdfShader not found");
+ fImageShaderRecords.push(assert_ptr(pdfShader));
+}
+
+void SkPDFCanon::removeImageShader(SkPDFImageShader* pdfShader) {
+ assert_mutex_held(this, gSkPDFCanonShaderMutex);
+ SkAssertResult(remove_item(&fImageShaderRecords, pdfShader));
}
////////////////////////////////////////////////////////////////////////////////
SkPDFGraphicState* SkPDFCanon::findGraphicState(const SkPaint& paint) const {
assert_mutex_held(this, gSkPDFCanonPaintMutex);
- for (int i = 0; i < fGraphicStateRecords.count(); ++i) {
- if (fGraphicStateRecords[i]->equals(paint)) {
- return fGraphicStateRecords[i];
- }
- }
- return NULL;
+ return find_item(fGraphicStateRecords, paint);
}
void SkPDFCanon::addGraphicState(SkPDFGraphicState* state) {
assert_mutex_held(this, gSkPDFCanonPaintMutex);
- SkASSERT(state);
- fGraphicStateRecords.push(state);
+ fGraphicStateRecords.push(assert_ptr(state));
}
void SkPDFCanon::removeGraphicState(SkPDFGraphicState* pdfGraphicState) {
assert_mutex_held(this, gSkPDFCanonPaintMutex);
- for (int i = 0; i < fGraphicStateRecords.count(); ++i) {
- if (fGraphicStateRecords[i] == pdfGraphicState) {
- fGraphicStateRecords.removeShuffle(i);
- return;
- }
- }
- SkDEBUGFAIL("pdfGraphicState not found");
+ SkAssertResult(remove_item(&fGraphicStateRecords, pdfGraphicState));
}
« no previous file with comments | « src/pdf/SkPDFCanon.h ('k') | src/pdf/SkPDFShader.h » ('j') | src/pdf/SkPDFShader.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698