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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 return sk_make_sp<SkSpecialSurface_Raster>(pr, subset, props); | 108 return sk_make_sp<SkSpecialSurface_Raster>(pr, subset, props); |
109 } | 109 } |
110 | 110 |
111 #if SK_SUPPORT_GPU | 111 #if SK_SUPPORT_GPU |
112 /////////////////////////////////////////////////////////////////////////////// | 112 /////////////////////////////////////////////////////////////////////////////// |
113 #include "GrContext.h" | 113 #include "GrContext.h" |
114 #include "SkGpuDevice.h" | 114 #include "SkGpuDevice.h" |
115 | 115 |
116 class SkSpecialSurface_Gpu : public SkSpecialSurface_Base { | 116 class SkSpecialSurface_Gpu : public SkSpecialSurface_Base { |
117 public: | 117 public: |
118 SkSpecialSurface_Gpu(sk_sp<GrTexture> texture, | 118 SkSpecialSurface_Gpu(sk_sp<GrDrawContext> drawContext, |
119 int width, int height, | 119 int width, int height, |
120 const SkIRect& subset, | 120 const SkIRect& subset) |
121 const SkSurfaceProps* props) | 121 : INHERITED(subset, &drawContext->surfaceProps()) |
122 : INHERITED(subset, props) | 122 , fDrawContext(std::move(drawContext)) { |
123 , fTexture(std::move(texture)) { | |
124 | 123 |
125 SkASSERT(fTexture->asRenderTarget()); | 124 sk_sp<SkBaseDevice> device(SkGpuDevice::Make(fDrawContext, width, height
, |
126 | 125 SkGpuDevice::kUninit_InitCo
ntents)); |
127 sk_sp<SkGpuDevice> device(SkGpuDevice::Make(sk_ref_sp(fTexture->asRender
Target()), | |
128 width, height, props, | |
129 SkGpuDevice::kUninit_InitCon
tents)); | |
130 if (!device) { | 126 if (!device) { |
131 return; | 127 return; |
132 } | 128 } |
133 | 129 |
134 fCanvas.reset(new SkCanvas(device.get())); | 130 fCanvas.reset(new SkCanvas(device.get())); |
135 fCanvas->clipRect(SkRect::Make(subset)); | 131 fCanvas->clipRect(SkRect::Make(subset)); |
136 #ifdef SK_IS_BOT | 132 #ifdef SK_IS_BOT |
137 fCanvas->clear(SK_ColorRED); // catch any imageFilter sloppiness | 133 fCanvas->clear(SK_ColorRED); // catch any imageFilter sloppiness |
138 #endif | 134 #endif |
139 } | 135 } |
140 | 136 |
141 ~SkSpecialSurface_Gpu() override { } | 137 ~SkSpecialSurface_Gpu() override { } |
142 | 138 |
143 sk_sp<SkSpecialImage> onMakeImageSnapshot() override { | 139 sk_sp<SkSpecialImage> onMakeImageSnapshot() override { |
144 // Note: we are intentionally zeroing out 'fTexture' here | 140 sk_sp<SkSpecialImage> tmp(SkSpecialImage::MakeFromGpu(this->subset(), |
145 return SkSpecialImage::MakeFromGpu(this->subset(), | 141 kNeedNewImageUniqu
eID_SpecialImage, |
146 kNeedNewImageUniqueID_SpecialImage, | 142 fDrawContext->asTe
xture(), |
147 std::move(fTexture), | 143 &this->props())); |
148 &this->props()); | 144 fDrawContext = nullptr; |
| 145 return tmp; |
149 } | 146 } |
150 | 147 |
151 private: | 148 private: |
152 sk_sp<GrTexture> fTexture; | 149 sk_sp<GrDrawContext> fDrawContext; |
153 | 150 |
154 typedef SkSpecialSurface_Base INHERITED; | 151 typedef SkSpecialSurface_Base INHERITED; |
155 }; | 152 }; |
156 | 153 |
157 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRenderTarget(GrContext* context, | 154 sk_sp<SkSpecialSurface> SkSpecialSurface::MakeRenderTarget(GrContext* context, |
158 int width, int height
, | 155 int width, int height
, |
159 GrPixelConfig config)
{ | 156 GrPixelConfig config)
{ |
160 if (!context) { | 157 if (!context) { |
161 return nullptr; | 158 return nullptr; |
162 } | 159 } |
163 | 160 |
164 GrSurfaceDesc desc; | 161 sk_sp<GrDrawContext> drawContext(context->newDrawContext(SkBackingFit::kAppr
ox, |
165 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 162 width, height, conf
ig)); |
166 desc.fWidth = width; | 163 if (!drawContext) { |
167 desc.fHeight = height; | |
168 desc.fConfig = config; | |
169 | |
170 sk_sp<GrTexture> tex(context->textureProvider()->createApproxTexture(desc)); | |
171 if (!tex) { | |
172 return nullptr; | 164 return nullptr; |
173 } | 165 } |
174 | 166 |
175 const SkIRect subset = SkIRect::MakeWH(width, height); | 167 const SkIRect subset = SkIRect::MakeWH(width, height); |
176 | 168 |
177 return sk_make_sp<SkSpecialSurface_Gpu>(std::move(tex), width, height, subse
t, nullptr); | 169 return sk_make_sp<SkSpecialSurface_Gpu>(std::move(drawContext), width, heigh
t, subset); |
178 } | 170 } |
179 | 171 |
180 #endif | 172 #endif |
OLD | NEW |