'../tests/ImageDecodingTest.cpp',
'../tests/ImageFilterTest.cpp',
'../tests/ImageGeneratorTest.cpp',
+ '../tests/ImageIsOpaqueTest.cpp',
'../tests/ImageNewShaderTest.cpp',
'../tests/InfRectTest.cpp',
'../tests/InterpolatorTest.cpp',
*/
static SkImage* NewTexture(const SkBitmap&);
+ virtual bool isOpaque() const { return false; }
+
/**
* Construct a new SkImage based on the given ImageGenerator.
* This function will always take ownership of the passed
virtual void onDrawRectToRect(SkCanvas*, const SkRect*, const SkRect&,
const SkPaint*) const SK_OVERRIDE;
+ virtual bool isOpaque() const SK_OVERRIDE;
+
private:
SkData* fEncodedData;
SkBitmap fBitmap;
return SkNEW_ARGS(SkImage_Codec, (data, bitmap.width(), bitmap.height()));
}
+
+
+bool SkImage_Codec::isOpaque() const {
+ return fBitmap.isOpaque();
+}
virtual SkShader* onNewShader(SkShader::TileMode,
SkShader::TileMode,
const SkMatrix* localMatrix) const SK_OVERRIDE;
+
+ virtual bool isOpaque() const SK_OVERRIDE;
+
private:
SkBitmap fBitmap;
return fBitmap.copyTo(dst, kN32_SkColorType);
}
+bool SkImage_Gpu::isOpaque() const {
+ return fBitmap.isOpaque();
+}
+
///////////////////////////////////////////////////////////////////////////////
SkImage* SkImage::NewTexture(const SkBitmap& bitmap) {
SkShader::TileMode,
const SkMatrix* localMatrix) const SK_OVERRIDE;
+ virtual bool isOpaque() const SK_OVERRIDE;
+
SkImage_Raster(const SkBitmap& bm)
: INHERITED(bm.width(), bm.height())
, fBitmap(bm) {}
SkPixelRef* SkBitmapImageGetPixelRef(SkImage* image) {
return ((SkImage_Raster*)image)->getPixelRef();
}
+
+bool SkImage_Raster::isOpaque() const {
+ return fBitmap.isOpaque();
+}
--- /dev/null
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkTypes.h"
+#if SK_SUPPORT_GPU
+#include "GrContextFactory.h"
+#endif
+#include "SkImage.h"
+#include "SkSurface.h"
+
+#include "Test.h"
+
+DEF_TEST(ImageIsOpaqueTest, reporter) {
+ SkImageInfo infoTransparent = SkImageInfo::MakeN32Premul(5, 5);
+ SkAutoTUnref<SkSurface> surfaceTransparent(SkSurface::NewRaster(infoTransparent));
+ REPORTER_ASSERT(reporter, !surfaceTransparent->newImageSnapshot()->isOpaque());
+
+ SkImageInfo infoOpaque = SkImageInfo::MakeN32(5, 5, kOpaque_SkAlphaType);
+ SkAutoTUnref<SkSurface> surfaceOpaque(SkSurface::NewRaster(infoOpaque));
+ REPORTER_ASSERT(reporter, surfaceOpaque->newImageSnapshot()->isOpaque());
+}
+
+#if SK_SUPPORT_GPU
+
+DEF_GPUTEST(ImageIsOpaqueTest_GPU, reporter, factory) {
+ for (int i = 0; i < GrContextFactory::kGLContextTypeCnt; ++i) {
+ GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContextType) i;
+
+ if (!GrContextFactory::IsRenderingGLContext(glCtxType)) {
+ continue;
+ }
+
+ GrContext* context = factory->get(glCtxType);
+
+ if (NULL == context) {
+ continue;
+ }
+
+ SkImageInfo infoTransparent = SkImageInfo::MakeN32Premul(5, 5);
+ SkAutoTUnref<SkSurface> surfaceTransparent(SkSurface::NewRenderTarget(context, infoTransparent));
+ REPORTER_ASSERT(reporter, !surfaceTransparent->newImageSnapshot()->isOpaque());
+
+ SkImageInfo infoOpaque = SkImageInfo::MakeN32(5, 5, kOpaque_SkAlphaType);
+ SkAutoTUnref<SkSurface> surfaceOpaque(SkSurface::NewRenderTarget(context, infoOpaque));
+ REPORTER_ASSERT(reporter, !surfaceOpaque->newImageSnapshot()->isOpaque());
+
+ }
+}
+
+#endif