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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 SkASSERT(fSubset.height() > 0); | 47 SkASSERT(fSubset.height() > 0); |
48 } | 48 } |
49 | 49 |
50 SkCanvas* SkSpecialSurface::getCanvas() { | 50 SkCanvas* SkSpecialSurface::getCanvas() { |
51 return as_SB(this)->onGetCanvas(); | 51 return as_SB(this)->onGetCanvas(); |
52 } | 52 } |
53 | 53 |
54 SkSpecialImage* SkSpecialSurface::newImageSnapshot() { | 54 SkSpecialImage* SkSpecialSurface::newImageSnapshot() { |
55 SkSpecialImage* image = as_SB(this)->onNewImageSnapshot(); | 55 SkSpecialImage* image = as_SB(this)->onNewImageSnapshot(); |
56 as_SB(this)->reset(); | 56 as_SB(this)->reset(); |
57 return SkSafeRef(image); // the caller will call unref() to balance this | 57 return image; // the caller gets the creation ref |
58 } | 58 } |
59 | 59 |
60 /////////////////////////////////////////////////////////////////////////////// | 60 /////////////////////////////////////////////////////////////////////////////// |
61 #include "SkMallocPixelRef.h" | 61 #include "SkMallocPixelRef.h" |
62 | 62 |
63 class SkSpecialSurface_Raster : public SkSpecialSurface_Base { | 63 class SkSpecialSurface_Raster : public SkSpecialSurface_Base { |
64 public: | 64 public: |
65 SkSpecialSurface_Raster(SkPixelRef* pr, const SkIRect& subset, const SkSurfa
ceProps* props) | 65 SkSpecialSurface_Raster(SkPixelRef* pr, const SkIRect& subset, const SkSurfa
ceProps* props) |
66 : INHERITED(subset, props) { | 66 : INHERITED(subset, props) { |
67 const SkImageInfo& info = pr->info(); | 67 const SkImageInfo& info = pr->info(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 | 103 |
104 #if SK_SUPPORT_GPU | 104 #if SK_SUPPORT_GPU |
105 /////////////////////////////////////////////////////////////////////////////// | 105 /////////////////////////////////////////////////////////////////////////////// |
106 #include "GrContext.h" | 106 #include "GrContext.h" |
107 #include "SkGpuDevice.h" | 107 #include "SkGpuDevice.h" |
108 | 108 |
109 class SkSpecialSurface_Gpu : public SkSpecialSurface_Base { | 109 class SkSpecialSurface_Gpu : public SkSpecialSurface_Base { |
110 public: | 110 public: |
111 SkSpecialSurface_Gpu(GrTexture* texture, const SkIRect& subset, const SkSurf
aceProps* props) | 111 SkSpecialSurface_Gpu(GrTexture* texture, const SkIRect& subset, const SkSurf
aceProps* props) |
112 : INHERITED(subset, props) | 112 : INHERITED(subset, props) |
113 , fTexture(texture) { | 113 , fTexture(SkRef(texture)) { |
114 | 114 |
115 SkASSERT(fTexture->asRenderTarget()); | 115 SkASSERT(fTexture->asRenderTarget()); |
116 | 116 |
117 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(fTexture->asRenderT
arget(), props, | 117 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(fTexture->asRenderT
arget(), props, |
118 SkGpuDevice::kUnini
t_InitContents)); | 118 SkGpuDevice::kUnini
t_InitContents)); |
119 if (!device) { | 119 if (!device) { |
120 return; | 120 return; |
121 } | 121 } |
122 | 122 |
123 fCanvas.reset(new SkCanvas(device)); | 123 fCanvas.reset(new SkCanvas(device)); |
(...skipping 20 matching lines...) Expand all Loading... |
144 return new SkSpecialSurface_Gpu(texture, subset, props); | 144 return new SkSpecialSurface_Gpu(texture, subset, props); |
145 } | 145 } |
146 | 146 |
147 SkSpecialSurface* SkSpecialSurface::NewRenderTarget(GrContext* context, | 147 SkSpecialSurface* SkSpecialSurface::NewRenderTarget(GrContext* context, |
148 const GrSurfaceDesc& desc, | 148 const GrSurfaceDesc& desc, |
149 const SkSurfaceProps* props)
{ | 149 const SkSurfaceProps* props)
{ |
150 if (!context || !SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag)) { | 150 if (!context || !SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag)) { |
151 return nullptr; | 151 return nullptr; |
152 } | 152 } |
153 | 153 |
154 GrTexture* temp = context->textureProvider()->createApproxTexture(desc); | 154 SkAutoTUnref<GrTexture> temp(context->textureProvider()->createApproxTexture
(desc)); |
155 if (!temp) { | 155 if (!temp) { |
156 return nullptr; | 156 return nullptr; |
157 } | 157 } |
158 | 158 |
159 const SkIRect subset = SkIRect::MakeWH(desc.fWidth, desc.fHeight); | 159 const SkIRect subset = SkIRect::MakeWH(desc.fWidth, desc.fHeight); |
160 | 160 |
161 return new SkSpecialSurface_Gpu(temp, subset, props); | 161 return new SkSpecialSurface_Gpu(temp, subset, props); |
162 } | 162 } |
163 | 163 |
164 #else | 164 #else |
165 | 165 |
166 SkSpecialSurface* SkSpecialSurface::NewFromTexture(const SkIRect& subset, GrText
ure*, | 166 SkSpecialSurface* SkSpecialSurface::NewFromTexture(const SkIRect& subset, GrText
ure*, |
167 const SkSurfaceProps*) { | 167 const SkSurfaceProps*) { |
168 return nullptr; | 168 return nullptr; |
169 } | 169 } |
170 | 170 |
171 SkSpecialSurface* SkSpecialSurface::NewRenderTarget(GrContext* context, | 171 SkSpecialSurface* SkSpecialSurface::NewRenderTarget(GrContext* context, |
172 const GrSurfaceDesc& desc, | 172 const GrSurfaceDesc& desc, |
173 const SkSurfaceProps* props)
{ | 173 const SkSurfaceProps* props)
{ |
174 return nullptr; | 174 return nullptr; |
175 } | 175 } |
176 | 176 |
177 #endif | 177 #endif |
OLD | NEW |