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
This commit is contained in:
parent
1d6ee0bd4d
commit
37a201231b
48
include/core/SkEmptyShader.h
Normal file
48
include/core/SkEmptyShader.h
Normal file
@ -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
|
@ -228,6 +228,7 @@ void SkBitmapProcShader::shadeSpan16(int x, int y, uint16_t dstC[], int count) {
|
|||||||
|
|
||||||
#include "SkUnPreMultiply.h"
|
#include "SkUnPreMultiply.h"
|
||||||
#include "SkColorShader.h"
|
#include "SkColorShader.h"
|
||||||
|
#include "SkEmptyShader.h"
|
||||||
|
|
||||||
// returns true and set color if the bitmap can be drawn as a single color
|
// returns true and set color if the bitmap can be drawn as a single color
|
||||||
// (for efficiency)
|
// (for efficiency)
|
||||||
@ -264,7 +265,10 @@ SkShader* SkShader::CreateBitmapShader(const SkBitmap& src,
|
|||||||
void* storage, size_t storageSize) {
|
void* storage, size_t storageSize) {
|
||||||
SkShader* shader;
|
SkShader* shader;
|
||||||
SkColor color;
|
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,
|
SK_PLACEMENT_NEW_ARGS(shader, SkColorShader, storage, storageSize,
|
||||||
(color));
|
(color));
|
||||||
} else {
|
} else {
|
||||||
|
@ -344,3 +344,26 @@ SkShader::GradientType SkColorShader::asAGradient(GradientInfo* info) const {
|
|||||||
}
|
}
|
||||||
return kColor_GradientType;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user