add SkEmptyShader, and return it from CreateBitmapShader if the bitmap is empty
(i.e. has no pixels at all)
git-svn-id: http://skia.googlecode.com/svn/trunk@1792 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/core/SkEmptyShader.h b/include/core/SkEmptyShader.h
new file mode 100644
index 0000000..1c40d0b
--- /dev/null
+++ b/include/core/SkEmptyShader.h
@@ -0,0 +1,48 @@
+/*
+ Copyright 2011 Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+
+#ifndef SkEmptyShader_DEFINED
+#define SkEmptyShader_DEFINED
+
+#include "SkShader.h"
+
+/**
+ * \class SkEmptyShader
+ * A Shader that always draws nothing.
+ */
+class SK_API SkEmptyShader : public SkShader {
+public:
+ SkEmptyShader();
+
+ virtual uint32_t getFlags();
+ virtual uint8_t getSpan16Alpha() const;
+ virtual bool setContext(const SkBitmap& device, const SkPaint& paint,
+ const SkMatrix& matrix);
+ virtual void shadeSpan(int x, int y, SkPMColor span[], int count);
+ virtual void shadeSpan16(int x, int y, uint16_t span[], int count);
+ virtual void shadeSpanAlpha(int x, int y, uint8_t alpha[], int count);
+
+protected:
+ SkEmptyShader(SkFlattenableReadBuffer&);
+ virtual Factory getFactory();
+ virtual void flatten(SkFlattenableWriteBuffer&);
+
+private:
+ typedef SkShader INHERITED;
+};
+
+#endif
diff --git a/src/core/SkBitmapProcShader.cpp b/src/core/SkBitmapProcShader.cpp
index a16e96a..a3132c7 100644
--- a/src/core/SkBitmapProcShader.cpp
+++ b/src/core/SkBitmapProcShader.cpp
@@ -228,6 +228,7 @@
#include "SkUnPreMultiply.h"
#include "SkColorShader.h"
+#include "SkEmptyShader.h"
// returns true and set color if the bitmap can be drawn as a single color
// (for efficiency)
@@ -264,7 +265,10 @@
void* storage, size_t storageSize) {
SkShader* shader;
SkColor color;
- if (canUseColorShader(src, &color)) {
+ if (src.isNull()) {
+ SK_PLACEMENT_NEW(shader, SkEmptyShader, storage, storageSize);
+ }
+ else if (canUseColorShader(src, &color)) {
SK_PLACEMENT_NEW_ARGS(shader, SkColorShader, storage, storageSize,
(color));
} else {
diff --git a/src/core/SkShader.cpp b/src/core/SkShader.cpp
index b51705e..48c9966 100644
--- a/src/core/SkShader.cpp
+++ b/src/core/SkShader.cpp
@@ -344,3 +344,26 @@
}
return kColor_GradientType;
}
+
+///////////////////////////////////////////////////////////////////////////////
+
+#include "SkEmptyShader.h"
+
+SkEmptyShader::SkEmptyShader() {}
+SkEmptyShader::SkEmptyShader(SkFlattenableReadBuffer& b) : INHERITED(b) {}
+
+uint32_t SkEmptyShader::getFlags() { return 0; }
+uint8_t SkEmptyShader::getSpan16Alpha() const { return 0; }
+bool SkEmptyShader::setContext(const SkBitmap& device, const SkPaint& paint,
+ const SkMatrix& matrix) {
+ return false;
+}
+void SkEmptyShader::shadeSpan(int x, int y, SkPMColor span[], int count) {}
+void SkEmptyShader::shadeSpan16(int x, int y, uint16_t span[], int count) {}
+void SkEmptyShader::shadeSpanAlpha(int x, int y, uint8_t alpha[], int count) {}
+
+SkFlattenable::Factory SkEmptyShader::getFactory() { return NULL; }
+void SkEmptyShader::flatten(SkFlattenableWriteBuffer& buffer) {
+ this->INHERITED::flatten(buffer);
+}
+