| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(copy->asRenderT
arget())); | 111 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(copy->asRenderT
arget())); |
| 112 if (!drawContext) { | 112 if (!drawContext) { |
| 113 return nullptr; | 113 return nullptr; |
| 114 } | 114 } |
| 115 | 115 |
| 116 SkRect dstRect = SkRect::MakeWH(SkIntToScalar(rtDesc.fWidth), SkIntToScalar(
rtDesc.fHeight)); | 116 SkRect dstRect = SkRect::MakeWH(SkIntToScalar(rtDesc.fWidth), SkIntToScalar(
rtDesc.fHeight)); |
| 117 drawContext->drawNonAARectToRect(GrClip::WideOpen(), paint, SkMatrix::I(), d
stRect, localRect); | 117 drawContext->drawNonAARectToRect(GrClip::WideOpen(), paint, SkMatrix::I(), d
stRect, localRect); |
| 118 return copy.detach(); | 118 return copy.detach(); |
| 119 } | 119 } |
| 120 | 120 |
| 121 GrTextureAdjuster::GrTextureAdjuster(GrTexture* original, const SkIRect& subset) | 121 GrTextureAdjuster::GrTextureAdjuster(GrTexture* original, const SkIRect& content
Area) |
| 122 : fOriginal(original) { | 122 : fOriginal(original) { |
| 123 if (subset.fLeft > 0 || subset.fTop > 0 || | 123 if (contentArea.fLeft > 0 || contentArea.fTop > 0 || |
| 124 subset.fRight < original->width() || subset.fBottom < original->height()
) { | 124 contentArea.fRight < original->width() || contentArea.fBottom < original
->height()) { |
| 125 fSubset.set(subset); | 125 fContentArea.set(contentArea); |
| 126 } | 126 } |
| 127 } | 127 } |
| 128 | 128 |
| 129 GrTexture* GrTextureAdjuster::refTextureSafeForParams(const GrTextureParams& par
ams, | 129 GrTexture* GrTextureAdjuster::refTextureSafeForParams(const GrTextureParams& par
ams, |
| 130 SkIPoint* outOffset) { | 130 SkIPoint* outOffset) { |
| 131 GrTexture* texture = this->originalTexture(); | 131 GrTexture* texture = this->originalTexture(); |
| 132 GrContext* context = texture->getContext(); | 132 GrContext* context = texture->getContext(); |
| 133 CopyParams copyParams; | 133 CopyParams copyParams; |
| 134 const SkIRect* subset = this->subset(); | 134 const SkIRect* contentArea = this->contentArea(); |
| 135 | 135 |
| 136 if (!context->getGpu()->makeCopyForTextureParams(texture->width(), texture->
height(), params, | 136 if (contentArea && GrTextureParams::kMipMap_FilterMode == params.filterMode(
)) { |
| 137 ©Params)) { | 137 // If we generate a MIP chain for texture it will read pixel values from
outside the content |
| 138 // area. |
| 139 copyParams.fWidth = contentArea->width(); |
| 140 copyParams.fHeight = contentArea->height(); |
| 141 copyParams.fFilter = GrTextureParams::kBilerp_FilterMode; |
| 142 } else if (!context->getGpu()->makeCopyForTextureParams(texture->width(), te
xture->height(), |
| 143 params, ©Params)
) { |
| 138 if (outOffset) { | 144 if (outOffset) { |
| 139 if (subset) { | 145 if (contentArea) { |
| 140 outOffset->set(subset->fLeft, subset->fRight); | 146 outOffset->set(contentArea->fLeft, contentArea->fRight); |
| 141 } else { | 147 } else { |
| 142 outOffset->set(0, 0); | 148 outOffset->set(0, 0); |
| 143 } | 149 } |
| 144 } | 150 } |
| 145 return SkRef(texture); | 151 return SkRef(texture); |
| 146 } | 152 } |
| 147 GrUniqueKey key; | 153 GrUniqueKey key; |
| 148 this->makeCopyKey(copyParams, &key); | 154 this->makeCopyKey(copyParams, &key); |
| 149 if (key.isValid()) { | 155 if (key.isValid()) { |
| 150 GrTexture* result = context->textureProvider()->findAndRefTextureByUniqu
eKey(key); | 156 GrTexture* result = context->textureProvider()->findAndRefTextureByUniqu
eKey(key); |
| 151 if (result) { | 157 if (result) { |
| 152 return result; | 158 return result; |
| 153 } | 159 } |
| 154 } | 160 } |
| 155 GrTexture* result = copy_on_gpu(texture, subset, copyParams); | 161 GrTexture* result = copy_on_gpu(texture, contentArea, copyParams); |
| 156 if (result) { | 162 if (result) { |
| 157 if (key.isValid()) { | 163 if (key.isValid()) { |
| 158 result->resourcePriv().setUniqueKey(key); | 164 result->resourcePriv().setUniqueKey(key); |
| 159 this->didCacheCopy(key); | 165 this->didCacheCopy(key); |
| 160 } | 166 } |
| 161 if (outOffset) { | 167 if (outOffset) { |
| 162 outOffset->set(0, 0); | 168 outOffset->set(0, 0); |
| 163 } | 169 } |
| 164 } | 170 } |
| 165 return result; | 171 return result; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 194 return result; | 200 return result; |
| 195 } | 201 } |
| 196 | 202 |
| 197 GrTexture* GrTextureMaker::generateTextureForParams(GrContext* ctx, const CopyPa
rams& copyParams) { | 203 GrTexture* GrTextureMaker::generateTextureForParams(GrContext* ctx, const CopyPa
rams& copyParams) { |
| 198 SkAutoTUnref<GrTexture> original(this->refOriginalTexture(ctx)); | 204 SkAutoTUnref<GrTexture> original(this->refOriginalTexture(ctx)); |
| 199 if (!original) { | 205 if (!original) { |
| 200 return nullptr; | 206 return nullptr; |
| 201 } | 207 } |
| 202 return copy_on_gpu(original, nullptr, copyParams); | 208 return copy_on_gpu(original, nullptr, copyParams); |
| 203 } | 209 } |
| OLD | NEW |