| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrTextureParamsAdjuster.h" | 8 #include "GrTextureParamsAdjuster.h" |
| 9 | 9 |
| 10 #include "GrCaps.h" | 10 #include "GrCaps.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 | 72 |
| 73 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(copy->asRenderT
arget())); | 73 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(copy->asRenderT
arget())); |
| 74 if (!drawContext) { | 74 if (!drawContext) { |
| 75 return nullptr; | 75 return nullptr; |
| 76 } | 76 } |
| 77 | 77 |
| 78 drawContext->drawNonAARectToRect(GrClip::WideOpen(), paint, SkMatrix::I(), r
ect, localRect); | 78 drawContext->drawNonAARectToRect(GrClip::WideOpen(), paint, SkMatrix::I(), r
ect, localRect); |
| 79 return copy.detach(); | 79 return copy.detach(); |
| 80 } | 80 } |
| 81 | 81 |
| 82 static SkBitmap copy_on_cpu(const SkBitmap& bmp, const CopyParams& copyParams) { | |
| 83 SkBitmap stretched; | |
| 84 stretched.allocN32Pixels(copyParams.fWidth, copyParams.fHeight); | |
| 85 SkCanvas canvas(stretched); | |
| 86 SkPaint paint; | |
| 87 switch (copyParams.fFilter) { | |
| 88 case GrTextureParams::kNone_FilterMode: | |
| 89 paint.setFilterQuality(kNone_SkFilterQuality); | |
| 90 break; | |
| 91 case GrTextureParams::kBilerp_FilterMode: | |
| 92 paint.setFilterQuality(kLow_SkFilterQuality); | |
| 93 break; | |
| 94 case GrTextureParams::kMipMap_FilterMode: | |
| 95 paint.setFilterQuality(kMedium_SkFilterQuality); | |
| 96 break; | |
| 97 } | |
| 98 SkRect dstRect = SkRect::MakeWH(SkIntToScalar(copyParams.fWidth), | |
| 99 SkIntToScalar(copyParams.fHeight)); | |
| 100 canvas.drawBitmapRect(bmp, dstRect, &paint); | |
| 101 return stretched; | |
| 102 } | |
| 103 | |
| 104 GrTexture* GrTextureParamsAdjuster::refTextureForParams(GrContext* ctx, | 82 GrTexture* GrTextureParamsAdjuster::refTextureForParams(GrContext* ctx, |
| 105 const GrTextureParams& p
arams) { | 83 const GrTextureParams& p
arams) { |
| 106 CopyParams copyParams; | 84 CopyParams copyParams; |
| 107 if (!ctx->getGpu()->makeCopyForTextureParams(this->width(), this->height(),
params, | 85 if (!ctx->getGpu()->makeCopyForTextureParams(this->width(), this->height(),
params, |
| 108 ©Params)) { | 86 ©Params)) { |
| 109 return this->refOriginalTexture(ctx); | 87 return this->refOriginalTexture(ctx); |
| 110 } | 88 } |
| 111 GrUniqueKey copyKey; | 89 GrUniqueKey copyKey; |
| 112 this->makeCopyKey(copyParams, ©Key); | 90 this->makeCopyKey(copyParams, ©Key); |
| 113 if (copyKey.isValid()) { | 91 if (copyKey.isValid()) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 124 | 102 |
| 125 if (copyKey.isValid()) { | 103 if (copyKey.isValid()) { |
| 126 ctx->textureProvider()->assignUniqueKeyToTexture(copyKey, result); | 104 ctx->textureProvider()->assignUniqueKeyToTexture(copyKey, result); |
| 127 this->didCacheCopy(copyKey); | 105 this->didCacheCopy(copyKey); |
| 128 } | 106 } |
| 129 return result; | 107 return result; |
| 130 } | 108 } |
| 131 | 109 |
| 132 GrTexture* GrTextureParamsAdjuster::generateTextureForParams(GrContext* ctx, | 110 GrTexture* GrTextureParamsAdjuster::generateTextureForParams(GrContext* ctx, |
| 133 const CopyParams& c
opyParams) { | 111 const CopyParams& c
opyParams) { |
| 134 if ((this->width() < ctx->caps()->minTextureSize() || | 112 SkAutoTUnref<GrTexture> original(this->refOriginalTexture(ctx)); |
| 135 this->height() < ctx->caps()->minTextureSize()) && !this->peekOriginalT
exture()) | 113 if (!original) { |
| 136 { | 114 return nullptr; |
| 137 // we can't trust our ability to use HW to perform the stretch, so we re
quest | |
| 138 // a raster instead, and perform the stretch on the CPU. | |
| 139 SkBitmap bitmap; | |
| 140 if (!this->getROBitmap(&bitmap)) { | |
| 141 return nullptr; | |
| 142 } | |
| 143 SkBitmap stretchedBmp = copy_on_cpu(bitmap, copyParams); | |
| 144 return GrUploadBitmapToTexture(ctx, stretchedBmp); | |
| 145 } else { | |
| 146 SkAutoTUnref<GrTexture> original(this->refOriginalTexture(ctx)); | |
| 147 if (!original) { | |
| 148 return nullptr; | |
| 149 } | |
| 150 return copy_on_gpu(original, copyParams); | |
| 151 } | 115 } |
| 116 return copy_on_gpu(original, copyParams); |
| 152 } | 117 } |
| OLD | NEW |