aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrBitmapTextureMaker.cpp
diff options
context:
space:
mode:
authorGravatar Brian Osman <brianosman@google.com>2016-11-28 09:26:31 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2016-11-28 14:58:41 +0000
commit3b66ab6f9fdc6eacdf0ee1921da28751de30c018 (patch)
treee81d2a52f48030084c53260a0d3b1bcf0463c96c /src/gpu/GrBitmapTextureMaker.cpp
parent781c3c14629342ed3eb00d153822c751406ad80b (diff)
GrTextureProducer cleanup, phase one: Bitmap and Image makers
Split these into their own files, and actually name the files after the classes they contain. The top three classes in the hierarchy still need attention, but those are going to be trickier. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=5195 Change-Id: I295f4d50e35748eac38a31f302e14b5b62653c55 Reviewed-on: https://skia-review.googlesource.com/5195 Commit-Queue: Brian Osman <brianosman@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'src/gpu/GrBitmapTextureMaker.cpp')
-rw-r--r--src/gpu/GrBitmapTextureMaker.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/gpu/GrBitmapTextureMaker.cpp b/src/gpu/GrBitmapTextureMaker.cpp
new file mode 100644
index 0000000000..0f26e51e91
--- /dev/null
+++ b/src/gpu/GrBitmapTextureMaker.cpp
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "GrBitmapTextureMaker.h"
+
+#include "GrContext.h"
+#include "GrGpuResourcePriv.h"
+#include "SkBitmap.h"
+#include "SkGrPriv.h"
+#include "SkPixelRef.h"
+
+static bool bmp_is_alpha_only(const SkBitmap& bm) { return kAlpha_8_SkColorType == bm.colorType(); }
+
+GrBitmapTextureMaker::GrBitmapTextureMaker(GrContext* context, const SkBitmap& bitmap)
+ : INHERITED(context, bitmap.width(), bitmap.height(), bmp_is_alpha_only(bitmap))
+ , fBitmap(bitmap) {
+ if (!bitmap.isVolatile()) {
+ SkIPoint origin = bitmap.pixelRefOrigin();
+ SkIRect subset = SkIRect::MakeXYWH(origin.fX, origin.fY, bitmap.width(),
+ bitmap.height());
+ GrMakeKeyFromImageID(&fOriginalKey, bitmap.pixelRef()->getGenerationID(), subset);
+ }
+}
+
+GrTexture* GrBitmapTextureMaker::refOriginalTexture(bool willBeMipped,
+ SkDestinationSurfaceColorMode colorMode) {
+ GrTexture* tex = nullptr;
+
+ if (fOriginalKey.isValid()) {
+ tex = this->context()->textureProvider()->findAndRefTextureByUniqueKey(fOriginalKey);
+ if (tex) {
+ return tex;
+ }
+ }
+ if (willBeMipped) {
+ tex = GrGenerateMipMapsAndUploadToTexture(this->context(), fBitmap, colorMode);
+ }
+ if (!tex) {
+ tex = GrUploadBitmapToTexture(this->context(), fBitmap);
+ }
+ if (tex && fOriginalKey.isValid()) {
+ tex->resourcePriv().setUniqueKey(fOriginalKey);
+ GrInstallBitmapUniqueKeyInvalidator(fOriginalKey, fBitmap.pixelRef());
+ }
+ return tex;
+}
+
+void GrBitmapTextureMaker::makeCopyKey(const CopyParams& copyParams, GrUniqueKey* copyKey,
+ SkDestinationSurfaceColorMode colorMode) {
+ // Color mode is irrelevant in this case - we always upload the bitmap's contents as-is
+ if (fOriginalKey.isValid()) {
+ MakeCopyKeyFromOrigKey(fOriginalKey, copyParams, copyKey);
+ }
+}
+
+void GrBitmapTextureMaker::didCacheCopy(const GrUniqueKey& copyKey) {
+ GrInstallBitmapUniqueKeyInvalidator(copyKey, fBitmap.pixelRef());
+}
+
+SkAlphaType GrBitmapTextureMaker::alphaType() const {
+ return fBitmap.alphaType();
+}
+
+sk_sp<SkColorSpace> GrBitmapTextureMaker::getColorSpace(SkDestinationSurfaceColorMode colorMode) {
+ // Color space doesn't depend on mode - it's just whatever is in the bitmap
+ return sk_ref_sp(fBitmap.colorSpace());
+}