| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "SkCanvas.h" | 8 #include "SkCanvas.h" |
| 9 #include "SkSpecialImage.h" | 9 #include "SkSpecialImage.h" |
| 10 #include "SkSpecialSurface.h" | 10 #include "SkSpecialSurface.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 return sk_make_sp<SkSpecialSurface_Raster>(pr, subset, props); | 105 return sk_make_sp<SkSpecialSurface_Raster>(pr, subset, props); |
| 106 } | 106 } |
| 107 | 107 |
| 108 #if SK_SUPPORT_GPU | 108 #if SK_SUPPORT_GPU |
| 109 /////////////////////////////////////////////////////////////////////////////// | 109 /////////////////////////////////////////////////////////////////////////////// |
| 110 #include "GrContext.h" | 110 #include "GrContext.h" |
| 111 #include "SkGpuDevice.h" | 111 #include "SkGpuDevice.h" |
| 112 | 112 |
| 113 class SkSpecialSurface_Gpu : public SkSpecialSurface_Base { | 113 class SkSpecialSurface_Gpu : public SkSpecialSurface_Base { |
| 114 public: | 114 public: |
| 115 SkSpecialSurface_Gpu(GrTexture* texture, | 115 SkSpecialSurface_Gpu(sk_sp<GrTexture> texture, |
| 116 const SkIRect& subset, | 116 const SkIRect& subset, |
| 117 const SkSurfaceProps* props) | 117 const SkSurfaceProps* props) |
| 118 : INHERITED(subset, props) | 118 : INHERITED(subset, props) |
| 119 , fTexture(SkRef(texture)) { | 119 , fTexture(std::move(texture)) { |
| 120 | 120 |
| 121 SkASSERT(fTexture->asRenderTarget()); | 121 SkASSERT(fTexture->asRenderTarget()); |
| 122 | 122 |
| 123 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(fTexture->asRenderT
arget(), props, | 123 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(fTexture->asRenderT
arget(), props, |
| 124 SkGpuDevice::kUnini
t_InitContents)); | 124 SkGpuDevice::kUnini
t_InitContents)); |
| 125 if (!device) { | 125 if (!device) { |
| 126 return; | 126 return; |
| 127 } | 127 } |
| 128 | 128 |
| 129 fCanvas.reset(new SkCanvas(device)); | 129 fCanvas.reset(new SkCanvas(device)); |
| 130 fCanvas->clipRect(SkRect::Make(subset)); | 130 fCanvas->clipRect(SkRect::Make(subset)); |
| 131 } | 131 } |
| 132 | 132 |
| 133 ~SkSpecialSurface_Gpu() override { } | 133 ~SkSpecialSurface_Gpu() override { } |
| 134 | 134 |
| 135 sk_sp<SkSpecialImage> onMakeImageSnapshot() override { | 135 sk_sp<SkSpecialImage> onMakeImageSnapshot() override { |
| 136 // Note: we are intentionally zeroing out 'fTexture' here |
| 136 return SkSpecialImage::MakeFromGpu(this->subset(), | 137 return SkSpecialImage::MakeFromGpu(this->subset(), |
| 137 kNeedNewImageUniqueID_SpecialImage, f
Texture, | 138 kNeedNewImageUniqueID_SpecialImage, |
| 139 std::move(fTexture), |
| 138 &this->props()); | 140 &this->props()); |
| 139 } | 141 } |
| 140 | 142 |
| 141 private: | 143 private: |
| 142 SkAutoTUnref<GrTexture> fTexture; | 144 sk_sp<GrTexture> fTexture; |
| 143 | 145 |
| 144 typedef SkSpecialSurface_Base INHERITED; | 146 typedef SkSpecialSurface_Base INHERITED; |
| 145 }; | 147 }; |
| 146 | 148 |
| 147 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeFromTexture(const SkIRect& subset, | 149 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeFromTexture(const SkIRect& subset, |
| 148 GrTexture* texture, | 150 sk_sp<GrTexture> textu
re, |
| 149 const SkSurfaceProps*
props) { | 151 const SkSurfaceProps*
props) { |
| 150 if (!texture->asRenderTarget()) { | 152 if (!texture->asRenderTarget()) { |
| 151 return nullptr; | 153 return nullptr; |
| 152 } | 154 } |
| 153 | 155 |
| 154 return sk_make_sp<SkSpecialSurface_Gpu>(texture, subset, props); | 156 return sk_make_sp<SkSpecialSurface_Gpu>(std::move(texture), subset, props); |
| 155 } | 157 } |
| 156 | 158 |
| 157 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRenderTarget(GrContext* context, | 159 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRenderTarget(GrContext* context, |
| 158 const GrSurfaceDesc&
desc, | 160 const GrSurfaceDesc&
desc, |
| 159 const SkSurfaceProps*
props) { | 161 const SkSurfaceProps*
props) { |
| 160 if (!context || !SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag)) { | 162 if (!context || !SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag)) { |
| 161 return nullptr; | 163 return nullptr; |
| 162 } | 164 } |
| 163 | 165 |
| 164 SkAutoTUnref<GrTexture> temp(context->textureProvider()->createApproxTexture
(desc)); | 166 sk_sp<GrTexture> temp(context->textureProvider()->createApproxTexture(desc))
; |
| 165 if (!temp) { | 167 if (!temp) { |
| 166 return nullptr; | 168 return nullptr; |
| 167 } | 169 } |
| 168 | 170 |
| 169 const SkIRect subset = SkIRect::MakeWH(desc.fWidth, desc.fHeight); | 171 const SkIRect subset = SkIRect::MakeWH(desc.fWidth, desc.fHeight); |
| 170 | 172 |
| 171 return sk_make_sp<SkSpecialSurface_Gpu>(temp, subset, props); | 173 return sk_make_sp<SkSpecialSurface_Gpu>(std::move(temp), subset, props); |
| 172 } | |
| 173 | |
| 174 #else | |
| 175 | |
| 176 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeFromTexture(const SkIRect& subset, | |
| 177 GrTexture*, | |
| 178 const SkSurfaceProps*)
{ | |
| 179 return nullptr; | |
| 180 } | |
| 181 | |
| 182 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRenderTarget(GrContext* context, | |
| 183 const GrSurfaceDesc&
desc, | |
| 184 const SkSurfaceProps*
props) { | |
| 185 return nullptr; | |
| 186 } | 174 } |
| 187 | 175 |
| 188 #endif | 176 #endif |
| OLD | NEW |