Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(259)

Unified Diff: src/gpu/GrTextureParamsAdjuster.cpp

Issue 1420963008: Pull texture-backed bitmap resampler out of GrTextureParamsAdjuster code into its own class. (Closed) Base URL: https://skia.googlesource.com/skia.git@nomin
Patch Set: fix unused var warning Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/GrTextureParamsAdjuster.h ('k') | src/gpu/SkGr.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrTextureParamsAdjuster.cpp
diff --git a/src/gpu/GrTextureParamsAdjuster.cpp b/src/gpu/GrTextureParamsAdjuster.cpp
index ee3d1351d754b7af4bbadf651d2946054847246d..b1faf14bb5d9d21b4f4d8a16c8c05cbe0eb788ef 100644
--- a/src/gpu/GrTextureParamsAdjuster.cpp
+++ b/src/gpu/GrTextureParamsAdjuster.cpp
@@ -11,24 +11,31 @@
#include "GrContext.h"
#include "GrDrawContext.h"
#include "GrGpu.h"
+#include "GrGpuResourcePriv.h"
+#include "GrResourceKey.h"
#include "GrTexture.h"
#include "GrTextureParams.h"
#include "GrTextureProvider.h"
#include "SkCanvas.h"
#include "SkGr.h"
#include "SkGrPriv.h"
+#include "effects/GrTextureDomain.h"
-typedef GrTextureParamsAdjuster::CopyParams CopyParams;
+typedef GrTextureProducer::CopyParams CopyParams;
-static GrTexture* copy_on_gpu(GrTexture* inputTexture, const CopyParams& copyParams) {
+//////////////////////////////////////////////////////////////////////////////
+
+static GrTexture* copy_on_gpu(GrTexture* inputTexture, const SkIRect* subset,
+ const CopyParams& copyParams) {
+ SkASSERT(!subset || !subset->isEmpty());
GrContext* context = inputTexture->getContext();
SkASSERT(context);
const GrCaps* caps = context->caps();
// Either it's a cache miss or the original wasn't cached to begin with.
GrSurfaceDesc rtDesc = inputTexture->desc();
- rtDesc.fFlags = rtDesc.fFlags | kRenderTarget_GrSurfaceFlag;
- rtDesc.fWidth = copyParams.fWidth;
+ rtDesc.fFlags = rtDesc.fFlags | kRenderTarget_GrSurfaceFlag;
+ rtDesc.fWidth = copyParams.fWidth;
rtDesc.fHeight = copyParams.fHeight;
rtDesc.fConfig = GrMakePixelConfigUncompressed(rtDesc.fConfig);
@@ -60,27 +67,107 @@ static GrTexture* copy_on_gpu(GrTexture* inputTexture, const CopyParams& copyPar
return nullptr;
}
+ // TODO: If no scaling is being performed then use copySurface.
+
GrPaint paint;
- // If filtering is not desired then we want to ensure all texels in the resampled image are
- // copies of texels from the original.
- GrTextureParams params(SkShader::kClamp_TileMode, copyParams.fFilter);
- paint.addColorTextureProcessor(inputTexture, SkMatrix::I(), params);
+ SkScalar sx;
+ SkScalar sy;
+ if (subset) {
+ sx = 1.f / inputTexture->width();
+ sy = 1.f / inputTexture->height();
+ }
- SkRect rect = SkRect::MakeWH(SkIntToScalar(rtDesc.fWidth), SkIntToScalar(rtDesc.fHeight));
- SkRect localRect = SkRect::MakeWH(1.f, 1.f);
+ if (copyParams.fFilter != GrTextureParams::kNone_FilterMode && subset &&
+ (subset->width() != copyParams.fWidth || subset->height() != copyParams.fHeight)) {
+ SkRect domain;
+ domain.fLeft = (subset->fLeft + 0.5f) * sx;
+ domain.fTop = (subset->fTop + 0.5f)* sy;
+ domain.fRight = (subset->fRight - 0.5f) * sx;
+ domain.fBottom = (subset->fBottom - 0.5f) * sy;
+ // This would cause us to read values from outside the subset. Surely, the caller knows
+ // better!
+ SkASSERT(copyParams.fFilter != GrTextureParams::kMipMap_FilterMode);
+ paint.addColorFragmentProcessor(
+ GrTextureDomainEffect::Create(inputTexture, SkMatrix::I(), domain,
+ GrTextureDomain::kClamp_Mode,
+ copyParams.fFilter))->unref();
+ } else {
+ GrTextureParams params(SkShader::kClamp_TileMode, copyParams.fFilter);
+ paint.addColorTextureProcessor(inputTexture, SkMatrix::I(), params);
+ }
+
+ SkRect localRect;
+ if (subset) {
+ localRect = SkRect::Make(*subset);
+ localRect.fLeft *= sx;
+ localRect.fTop *= sy;
+ localRect.fRight *= sx;
+ localRect.fBottom *= sy;
+ } else {
+ localRect = SkRect::MakeWH(1.f, 1.f);
+ }
SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(copy->asRenderTarget()));
if (!drawContext) {
return nullptr;
}
- drawContext->drawNonAARectToRect(GrClip::WideOpen(), paint, SkMatrix::I(), rect, localRect);
+ SkRect dstRect = SkRect::MakeWH(SkIntToScalar(rtDesc.fWidth), SkIntToScalar(rtDesc.fHeight));
+ drawContext->drawNonAARectToRect(GrClip::WideOpen(), paint, SkMatrix::I(), dstRect, localRect);
return copy.detach();
}
-GrTexture* GrTextureParamsAdjuster::refTextureForParams(GrContext* ctx,
- const GrTextureParams& params) {
+GrTextureAdjuster::GrTextureAdjuster(GrTexture* original, const SkIRect& subset)
+ : fOriginal(original) {
+ if (subset.fLeft > 0 || subset.fTop > 0 ||
+ subset.fRight < original->width() || subset.fBottom < original->height()) {
+ fSubset.set(subset);
+ }
+}
+
+GrTexture* GrTextureAdjuster::refTextureSafeForParams(const GrTextureParams& params,
+ SkIPoint* outOffset) {
+ GrTexture* texture = this->originalTexture();
+ GrContext* context = texture->getContext();
+ CopyParams copyParams;
+ const SkIRect* subset = this->subset();
+
+ if (!context->getGpu()->makeCopyForTextureParams(texture->width(), texture->height(), params,
+ &copyParams)) {
+ if (outOffset) {
+ if (subset) {
+ outOffset->set(subset->fLeft, subset->fRight);
+ } else {
+ outOffset->set(0, 0);
+ }
+ }
+ return SkRef(texture);
+ }
+ GrUniqueKey key;
+ this->makeCopyKey(copyParams, &key);
+ if (key.isValid()) {
+ GrTexture* result = context->textureProvider()->findAndRefTextureByUniqueKey(key);
+ if (result) {
+ return result;
+ }
+ }
+ GrTexture* result = copy_on_gpu(texture, subset, copyParams);
+ if (result) {
+ if (key.isValid()) {
+ result->resourcePriv().setUniqueKey(key);
+ this->didCacheCopy(key);
+ }
+ if (outOffset) {
+ outOffset->set(0, 0);
+ }
+ }
+ return result;
+}
+
+//////////////////////////////////////////////////////////////////////////////
+
+GrTexture* GrTextureMaker::refTextureForParams(GrContext* ctx, const GrTextureParams& params) {
CopyParams copyParams;
if (!ctx->getGpu()->makeCopyForTextureParams(this->width(), this->height(), params,
&copyParams)) {
@@ -107,11 +194,10 @@ GrTexture* GrTextureParamsAdjuster::refTextureForParams(GrContext* ctx,
return result;
}
-GrTexture* GrTextureParamsAdjuster::generateTextureForParams(GrContext* ctx,
- const CopyParams& copyParams) {
+GrTexture* GrTextureMaker::generateTextureForParams(GrContext* ctx, const CopyParams& copyParams) {
SkAutoTUnref<GrTexture> original(this->refOriginalTexture(ctx));
if (!original) {
return nullptr;
}
- return copy_on_gpu(original, copyParams);
+ return copy_on_gpu(original, nullptr, copyParams);
}
« no previous file with comments | « src/gpu/GrTextureParamsAdjuster.h ('k') | src/gpu/SkGr.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698