Revert of add ImageShader, sharing code with its Bitmap cousin (patchset #10 id:180001 of https://codereview.chromium.org/1342113002/ )
Reason for revert: Failing ImageNewShaderTest on both Android (Tegra3 GPU) and iOS bots. e.g. /Users/chrome-bot/buildbot/skiabot-ipad4-000/build/slave/workdir/build/skia/tests/ ImageNewShaderTest.cpp:24 0 == memcmp(bm1.getPixels(), bm2.getPixels(), bm1.getSize()) ImageNewShaderTest.cpp:95 0xFFFF0000 == bmt.getColor(0, y) ImageNewShaderTest.cpp:98 0xFFDEDEDE == bmt.getColor(x, y) ImageNewShaderTest.cpp:98 0xFFDEDEDE == bmt.getColor(x, y) ImageNewShaderTest.cpp:98 0xFFDEDEDE == bmt.getColor(x, y) ImageNewShaderTest.cpp:98 0xFFDEDEDE == bmt.getColor(x, y) ImageNewShaderTest.cpp:95 0xFFFF0000 == bmt.getColor(0, y) ... Original issue's description: > add ImageShader, sharing code with its Bitmap cousin > > This is done by having abstracted the BitmapShaderContext to take a BitmapProvider, instead of just a bitmap. This allows us to share all of that code between SkBitmap and SkImage, since both are valid providers. > > It also means that we can simplify SkImage_Base to not need a virtual for onNewShader, since ALL images can uniformly be turned into a shader now. > > BUG=skia: > > Committed: https://skia.googlesource.com/skia/+/0b93e3149d2cb30860c51f9f3204ae811d9a97ca TBR=fmalita@chromium.org,bsalomon@google.com,robertphillips@google.com,reed@google.com NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=skia: Review URL: https://codereview.chromium.org/1355863002
This commit is contained in:
parent
bcfd511eb1
commit
f260851362
@ -254,8 +254,6 @@
|
|||||||
'<(skia_src_path)/image/SkImage_Generator.cpp',
|
'<(skia_src_path)/image/SkImage_Generator.cpp',
|
||||||
# '<(skia_src_path)/image/SkImage_Gpu.cpp',
|
# '<(skia_src_path)/image/SkImage_Gpu.cpp',
|
||||||
'<(skia_src_path)/image/SkImage_Raster.cpp',
|
'<(skia_src_path)/image/SkImage_Raster.cpp',
|
||||||
'<(skia_src_path)/image/SkImageShader.cpp',
|
|
||||||
'<(skia_src_path)/image/SkImageShader.h',
|
|
||||||
'<(skia_src_path)/image/SkSurface.cpp',
|
'<(skia_src_path)/image/SkSurface.cpp',
|
||||||
'<(skia_src_path)/image/SkSurface_Base.h',
|
'<(skia_src_path)/image/SkSurface_Base.h',
|
||||||
# '<(skia_src_path)/image/SkSurface_Gpu.cpp',
|
# '<(skia_src_path)/image/SkSurface_Gpu.cpp',
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
#include "SkData.h"
|
#include "SkData.h"
|
||||||
#include "SkImageGenerator.h"
|
#include "SkImageGenerator.h"
|
||||||
#include "SkImagePriv.h"
|
#include "SkImagePriv.h"
|
||||||
#include "SkImageShader.h"
|
|
||||||
#include "SkImage_Base.h"
|
#include "SkImage_Base.h"
|
||||||
#include "SkNextID.h"
|
#include "SkNextID.h"
|
||||||
#include "SkPixelRef.h"
|
#include "SkPixelRef.h"
|
||||||
@ -70,7 +69,7 @@ void SkImage::preroll(GrContext* ctx) const {
|
|||||||
SkShader* SkImage::newShader(SkShader::TileMode tileX,
|
SkShader* SkImage::newShader(SkShader::TileMode tileX,
|
||||||
SkShader::TileMode tileY,
|
SkShader::TileMode tileY,
|
||||||
const SkMatrix* localMatrix) const {
|
const SkMatrix* localMatrix) const {
|
||||||
return SkImageShader::Create(this, tileX, tileY, localMatrix);
|
return as_IB(this)->onNewShader(tileX, tileY, localMatrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
SkData* SkImage::encode(SkImageEncoder::Type type, int quality) const {
|
SkData* SkImage::encode(SkImageEncoder::Type type, int quality) const {
|
||||||
|
@ -1,145 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2015 Google Inc.
|
|
||||||
*
|
|
||||||
* Use of this source code is governed by a BSD-style license that can be
|
|
||||||
* found in the LICENSE file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "SkBitmapProcShader.h"
|
|
||||||
#include "SkBitmapProvider.h"
|
|
||||||
#include "SkImage_Base.h"
|
|
||||||
#include "SkImageShader.h"
|
|
||||||
#include "SkReadBuffer.h"
|
|
||||||
#include "SkWriteBuffer.h"
|
|
||||||
|
|
||||||
SkImageShader::SkImageShader(const SkImage* img, TileMode tmx, TileMode tmy, const SkMatrix* matrix)
|
|
||||||
: INHERITED(matrix)
|
|
||||||
, fImage(SkRef(img))
|
|
||||||
, fTileModeX(tmx)
|
|
||||||
, fTileModeY(tmy)
|
|
||||||
{}
|
|
||||||
|
|
||||||
SkFlattenable* SkImageShader::CreateProc(SkReadBuffer& buffer) {
|
|
||||||
const TileMode tx = (TileMode)buffer.readUInt();
|
|
||||||
const TileMode ty = (TileMode)buffer.readUInt();
|
|
||||||
SkMatrix matrix;
|
|
||||||
buffer.readMatrix(&matrix);
|
|
||||||
SkAutoTUnref<SkImage> img(buffer.readImage());
|
|
||||||
if (!img) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return new SkImageShader(img, tx, ty, &matrix);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SkImageShader::flatten(SkWriteBuffer& buffer) const {
|
|
||||||
buffer.writeUInt(fTileModeX);
|
|
||||||
buffer.writeUInt(fTileModeY);
|
|
||||||
buffer.writeMatrix(this->getLocalMatrix());
|
|
||||||
buffer.writeImage(fImage);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SkImageShader::isOpaque() const {
|
|
||||||
return fImage->isOpaque();
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t SkImageShader::contextSize() const {
|
|
||||||
return SkBitmapProcShader::ContextSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
SkShader::Context* SkImageShader::onCreateContext(const ContextRec& rec, void* storage) const {
|
|
||||||
return SkBitmapProcShader::MakeContext(*this, fTileModeX, fTileModeY,
|
|
||||||
SkBitmapProvider(fImage), rec, storage);
|
|
||||||
}
|
|
||||||
|
|
||||||
SkShader* SkImageShader::Create(const SkImage* image, TileMode tx, TileMode ty,
|
|
||||||
const SkMatrix* localMatrix) {
|
|
||||||
if (!image) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return new SkImageShader(image, tx, ty, localMatrix);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef SK_IGNORE_TO_STRING
|
|
||||||
void SkImageShader::toString(SkString* str) const {
|
|
||||||
const char* gTileModeName[SkShader::kTileModeCount] = {
|
|
||||||
"clamp", "repeat", "mirror"
|
|
||||||
};
|
|
||||||
|
|
||||||
str->appendf("ImageShader: ((%s %s) ", gTileModeName[fTileModeX], gTileModeName[fTileModeY]);
|
|
||||||
fImage->toString(str);
|
|
||||||
this->INHERITED::toString(str);
|
|
||||||
str->append(")");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#if SK_SUPPORT_GPU
|
|
||||||
|
|
||||||
#include "GrTextureAccess.h"
|
|
||||||
#include "SkGr.h"
|
|
||||||
#include "effects/GrSimpleTextureEffect.h"
|
|
||||||
#include "effects/GrBicubicEffect.h"
|
|
||||||
#include "effects/GrExtractAlphaFragmentProcessor.h"
|
|
||||||
#include "effects/GrSimpleTextureEffect.h"
|
|
||||||
|
|
||||||
const GrFragmentProcessor* SkImageShader::asFragmentProcessor(GrContext* context,
|
|
||||||
const SkMatrix& viewM,
|
|
||||||
const SkMatrix* localMatrix,
|
|
||||||
SkFilterQuality filterQuality,
|
|
||||||
GrProcessorDataManager* mgr) const {
|
|
||||||
SkMatrix matrix;
|
|
||||||
matrix.setIDiv(fImage->width(), fImage->height());
|
|
||||||
|
|
||||||
SkMatrix lmInverse;
|
|
||||||
if (!this->getLocalMatrix().invert(&lmInverse)) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
if (localMatrix) {
|
|
||||||
SkMatrix inv;
|
|
||||||
if (!localMatrix->invert(&inv)) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
lmInverse.postConcat(inv);
|
|
||||||
}
|
|
||||||
matrix.preConcat(lmInverse);
|
|
||||||
|
|
||||||
SkShader::TileMode tm[] = { fTileModeX, fTileModeY };
|
|
||||||
|
|
||||||
// Must set wrap and filter on the sampler before requesting a texture. In two places below
|
|
||||||
// we check the matrix scale factors to determine how to interpret the filter quality setting.
|
|
||||||
// This completely ignores the complexity of the drawVertices case where explicit local coords
|
|
||||||
// are provided by the caller.
|
|
||||||
bool doBicubic;
|
|
||||||
GrTextureParams::FilterMode textureFilterMode =
|
|
||||||
GrSkFilterQualityToGrFilterMode(filterQuality, viewM, this->getLocalMatrix(), &doBicubic);
|
|
||||||
GrTextureParams params(tm, textureFilterMode);
|
|
||||||
|
|
||||||
SkImageUsageType usageType;
|
|
||||||
if (kClamp_TileMode == fTileModeX && kClamp_TileMode == fTileModeY) {
|
|
||||||
usageType = kUntiled_SkImageUsageType;
|
|
||||||
} else if (GrTextureParams::kNone_FilterMode == textureFilterMode) {
|
|
||||||
usageType = kTiled_Unfiltered_SkImageUsageType;
|
|
||||||
} else {
|
|
||||||
usageType = kTiled_Filtered_SkImageUsageType;
|
|
||||||
}
|
|
||||||
|
|
||||||
SkAutoTUnref<GrTexture> texture(as_IB(fImage)->asTextureRef(context, usageType));
|
|
||||||
if (!texture) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
SkAutoTUnref<GrFragmentProcessor> inner;
|
|
||||||
if (doBicubic) {
|
|
||||||
inner.reset(GrBicubicEffect::Create(mgr, texture, matrix, tm));
|
|
||||||
} else {
|
|
||||||
inner.reset(GrSimpleTextureEffect::Create(mgr, texture, matrix, params));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (GrPixelConfigIsAlphaOnly(texture->config())) {
|
|
||||||
return SkRef(inner.get());
|
|
||||||
}
|
|
||||||
return GrExtractAlphaFragmentProcessor::Create(inner);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,44 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2015 Google Inc.
|
|
||||||
*
|
|
||||||
* Use of this source code is governed by a BSD-style license that can be
|
|
||||||
* found in the LICENSE file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef SkImageShader_DEFINED
|
|
||||||
#define SkImageShader_DEFINED
|
|
||||||
|
|
||||||
#include "SkImage.h"
|
|
||||||
#include "SkShader.h"
|
|
||||||
|
|
||||||
class SkImageShader : public SkShader {
|
|
||||||
public:
|
|
||||||
static SkShader* Create(const SkImage*, TileMode tx, TileMode ty, const SkMatrix* localMatrix);
|
|
||||||
|
|
||||||
bool isOpaque() const override;
|
|
||||||
size_t contextSize() const override;
|
|
||||||
|
|
||||||
SK_TO_STRING_OVERRIDE()
|
|
||||||
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkImageShader)
|
|
||||||
|
|
||||||
#if SK_SUPPORT_GPU
|
|
||||||
const GrFragmentProcessor* asFragmentProcessor(GrContext*, const SkMatrix& viewM,
|
|
||||||
const SkMatrix*, SkFilterQuality,
|
|
||||||
GrProcessorDataManager*) const override;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void flatten(SkWriteBuffer&) const override;
|
|
||||||
Context* onCreateContext(const ContextRec&, void* storage) const override;
|
|
||||||
|
|
||||||
SkAutoTUnref<const SkImage> fImage;
|
|
||||||
const TileMode fTileModeX;
|
|
||||||
const TileMode fTileModeY;
|
|
||||||
|
|
||||||
private:
|
|
||||||
SkImageShader(const SkImage*, TileMode tx, TileMode ty, const SkMatrix* localMatrix);
|
|
||||||
|
|
||||||
typedef SkShader INHERITED;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -56,6 +56,10 @@ public:
|
|||||||
// Caller must call unref when they are done.
|
// Caller must call unref when they are done.
|
||||||
virtual GrTexture* asTextureRef(GrContext*, SkImageUsageType) const = 0;
|
virtual GrTexture* asTextureRef(GrContext*, SkImageUsageType) const = 0;
|
||||||
|
|
||||||
|
virtual SkShader* onNewShader(SkShader::TileMode,
|
||||||
|
SkShader::TileMode,
|
||||||
|
const SkMatrix* localMatrix) const { return nullptr; }
|
||||||
|
|
||||||
// newWidth > 0, newHeight > 0, subset either nullptr or a proper subset of this bounds
|
// newWidth > 0, newHeight > 0, subset either nullptr or a proper subset of this bounds
|
||||||
virtual SkImage* onNewImage(int newWidth, int newHeight, const SkIRect* subset,
|
virtual SkImage* onNewImage(int newWidth, int newHeight, const SkIRect* subset,
|
||||||
SkFilterQuality) const;
|
SkFilterQuality) const;
|
||||||
|
@ -28,6 +28,11 @@ public:
|
|||||||
|
|
||||||
bool getROPixels(SkBitmap*) const override;
|
bool getROPixels(SkBitmap*) const override;
|
||||||
GrTexture* asTextureRef(GrContext*, SkImageUsageType) const override;
|
GrTexture* asTextureRef(GrContext*, SkImageUsageType) const override;
|
||||||
|
|
||||||
|
SkShader* onNewShader(SkShader::TileMode,
|
||||||
|
SkShader::TileMode,
|
||||||
|
const SkMatrix* localMatrix) const override;
|
||||||
|
|
||||||
bool onIsLazyGenerated() const override { return true; }
|
bool onIsLazyGenerated() const override { return true; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -38,6 +43,17 @@ private:
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
SkShader* SkImage_Generator::onNewShader(SkShader::TileMode tileX, SkShader::TileMode tileY,
|
||||||
|
const SkMatrix* localMatrix) const {
|
||||||
|
// TODO: need a native Shader that takes Cacherator (or this image) so we can natively return
|
||||||
|
// textures as output from the shader.
|
||||||
|
SkBitmap bm;
|
||||||
|
if (this->getROPixels(&bm)) {
|
||||||
|
return SkShader::CreateBitmapShader(bm, tileX, tileY, localMatrix);
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
SkSurface* SkImage_Generator::onNewSurface(const SkImageInfo& info,
|
SkSurface* SkImage_Generator::onNewSurface(const SkImageInfo& info,
|
||||||
const SkSurfaceProps& props) const {
|
const SkSurfaceProps& props) const {
|
||||||
return SkSurface::NewRaster(info, &props);
|
return SkSurface::NewRaster(info, &props);
|
||||||
|
@ -49,6 +49,13 @@ extern void SkTextureImageApplyBudgetedDecision(SkImage* image) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SkShader* SkImage_Gpu::onNewShader(SkShader::TileMode tileX, SkShader::TileMode tileY,
|
||||||
|
const SkMatrix* localMatrix) const {
|
||||||
|
SkBitmap bm;
|
||||||
|
GrWrapTextureInBitmap(fTexture, this->width(), this->height(), this->isOpaque(), &bm);
|
||||||
|
return SkShader::CreateBitmapShader(bm, tileX, tileY, localMatrix);
|
||||||
|
}
|
||||||
|
|
||||||
bool SkImage_Gpu::getROPixels(SkBitmap* dst) const {
|
bool SkImage_Gpu::getROPixels(SkBitmap* dst) const {
|
||||||
if (SkBitmapCache::Find(this->uniqueID(), dst)) {
|
if (SkBitmapCache::Find(this->uniqueID(), dst)) {
|
||||||
SkASSERT(dst->getGenerationID() == this->uniqueID());
|
SkASSERT(dst->getGenerationID() == this->uniqueID());
|
||||||
|
@ -40,6 +40,9 @@ public:
|
|||||||
GrTexture* asTextureRef(GrContext* ctx, SkImageUsageType usage) const override;
|
GrTexture* asTextureRef(GrContext* ctx, SkImageUsageType usage) const override;
|
||||||
|
|
||||||
GrTexture* peekTexture() const override { return fTexture; }
|
GrTexture* peekTexture() const override { return fTexture; }
|
||||||
|
SkShader* onNewShader(SkShader::TileMode,
|
||||||
|
SkShader::TileMode,
|
||||||
|
const SkMatrix* localMatrix) const override;
|
||||||
bool isOpaque() const override;
|
bool isOpaque() const override;
|
||||||
SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) const override;
|
SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) const override;
|
||||||
bool onReadPixels(const SkImageInfo&, void* dstPixels, size_t dstRowBytes,
|
bool onReadPixels(const SkImageInfo&, void* dstPixels, size_t dstRowBytes,
|
||||||
|
@ -80,6 +80,10 @@ public:
|
|||||||
|
|
||||||
SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); }
|
SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); }
|
||||||
|
|
||||||
|
SkShader* onNewShader(SkShader::TileMode,
|
||||||
|
SkShader::TileMode,
|
||||||
|
const SkMatrix* localMatrix) const override;
|
||||||
|
|
||||||
bool isOpaque() const override;
|
bool isOpaque() const override;
|
||||||
bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const override;
|
bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const override;
|
||||||
|
|
||||||
@ -140,6 +144,11 @@ SkImage_Raster::SkImage_Raster(const Info& info, SkPixelRef* pr, const SkIPoint&
|
|||||||
|
|
||||||
SkImage_Raster::~SkImage_Raster() {}
|
SkImage_Raster::~SkImage_Raster() {}
|
||||||
|
|
||||||
|
SkShader* SkImage_Raster::onNewShader(SkShader::TileMode tileX, SkShader::TileMode tileY,
|
||||||
|
const SkMatrix* localMatrix) const {
|
||||||
|
return SkShader::CreateBitmapShader(fBitmap, tileX, tileY, localMatrix);
|
||||||
|
}
|
||||||
|
|
||||||
SkSurface* SkImage_Raster::onNewSurface(const SkImageInfo& info, const SkSurfaceProps& props) const {
|
SkSurface* SkImage_Raster::onNewSurface(const SkImageInfo& info, const SkSurfaceProps& props) const {
|
||||||
return SkSurface::NewRaster(info, &props);
|
return SkSurface::NewRaster(info, &props);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user