| OLD | NEW |
| (Empty) | |
| 1 /* |
| 2 * Copyright 2016 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #include "cdl_common.h" |
| 9 |
| 10 #if CDL_ENABLED |
| 11 |
| 12 #include "cdl_surface.h" |
| 13 |
| 14 #include "base/memory/ptr_util.h" |
| 15 #include "cdl_canvas.h" |
| 16 |
| 17 CdlSurface::CdlSurface(sk_sp<SkSurface> surface) |
| 18 : surface_(std::move(surface)) {} |
| 19 CdlSurface::~CdlSurface() {} |
| 20 |
| 21 sk_sp<SkImage> CdlSurface::makeImageSnapshot(SkBudgeted budgeted) { |
| 22 return surface_->makeImageSnapshot(budgeted); |
| 23 } |
| 24 |
| 25 sk_sp<CdlSurface> CdlSurface::MakeRasterDirect(const SkImageInfo& info, |
| 26 void* pixels, |
| 27 size_t rowBytes, |
| 28 const SkSurfaceProps* props) { |
| 29 sk_sp<SkSurface> surface = |
| 30 SkSurface::MakeRasterDirect(info, pixels, rowBytes, props); |
| 31 if (surface.get()) |
| 32 return sk_make_sp<CdlSurface>(surface); |
| 33 return nullptr; |
| 34 } |
| 35 |
| 36 /** |
| 37 * The same as NewRasterDirect, but also accepts a call-back routine, which is |
| 38 * invoked |
| 39 * when the surface is deleted, and is passed the pixel memory and the specified |
| 40 * context. |
| 41 */ |
| 42 sk_sp<CdlSurface> CdlSurface::MakeRasterDirectReleaseProc( |
| 43 const SkImageInfo& info, |
| 44 void* pixels, |
| 45 size_t rowBytes, |
| 46 void (*releaseProc)(void* pixels, void* context), |
| 47 void* context, |
| 48 const SkSurfaceProps* props) { |
| 49 sk_sp<SkSurface> surface = SkSurface::MakeRasterDirectReleaseProc( |
| 50 info, pixels, rowBytes, releaseProc, context, props); |
| 51 if (surface.get()) |
| 52 return sk_make_sp<CdlSurface>(surface); |
| 53 return nullptr; |
| 54 } |
| 55 |
| 56 /** |
| 57 * Return a new surface, with the memory for the pixels automatically allocated |
| 58 * and |
| 59 * zero-initialized, but respecting the specified rowBytes. If rowBytes==0, then |
| 60 * a default |
| 61 * value will be chosen. If a non-zero rowBytes is specified, then any images |
| 62 * snapped off of |
| 63 * this surface (via makeImageSnapshot()) are guaranteed to have the same |
| 64 * rowBytes. |
| 65 * |
| 66 * If the requested surface cannot be created, or the request is not a |
| 67 * supported configuration, NULL will be returned. |
| 68 */ |
| 69 sk_sp<CdlSurface> CdlSurface::MakeRaster(const SkImageInfo& info, |
| 70 size_t rowBytes, |
| 71 const SkSurfaceProps* props) { |
| 72 sk_sp<SkSurface> surface = SkSurface::MakeRaster(info, rowBytes, props); |
| 73 if (surface.get()) |
| 74 return sk_make_sp<CdlSurface>(surface); |
| 75 return nullptr; |
| 76 } |
| 77 |
| 78 #if 0 |
| 79 /** |
| 80 * Used to wrap a pre-existing backend 3D API texture as a SkSurface. The kRende
rTarget flag |
| 81 * must be set on GrBackendTextureDesc for this to succeed. Skia will not assume
ownership |
| 82 * of the texture and the client must ensure the texture is valid for the lifeti
me of the |
| 83 * SkSurface. |
| 84 */ |
| 85 static sk_sp<CdlSurface> CdlSurface::MakeFromBackendTexture(GrContext* context,
const GrBackendTextureDesc& desc, |
| 86 sk_sp<SkColorSpace> color, const SkSu
rfaceProps* props) { |
| 87 return sk_make_sp<CdlSurface>(SkSurface::MakeFromBackendTexture(context, desc,
color, props)); |
| 88 } |
| 89 |
| 90 /** |
| 91 * Used to wrap a pre-existing 3D API rendering target as a SkSurface. Skia will
not assume |
| 92 * ownership of the render target and the client must ensure the render target i
s valid for the |
| 93 * lifetime of the SkSurface. |
| 94 */ |
| 95 static sk_sp<CdlSurface> CdlSurface::MakeFromBackendRenderTarget(GrContext*, |
| 96 const GrBackendRenderTargetDesc&
, |
| 97 sk_sp<SkColorSpace>, |
| 98 const SkSurfaceProps*) { |
| 99 |
| 100 } |
| 101 |
| 102 /** |
| 103 * Used to wrap a pre-existing 3D API texture as a SkSurface. Skia will treat th
e texture as |
| 104 * a rendering target only, but unlike NewFromBackendRenderTarget, Skia will man
age and own |
| 105 * the associated render target objects (but not the provided texture). The kRen
derTarget flag |
| 106 * must be set on GrBackendTextureDesc for this to succeed. Skia will not assume
ownership |
| 107 * of the texture and the client must ensure the texture is valid for the lifeti
me of the |
| 108 * SkSurface. |
| 109 */ |
| 110 static sk_sp<CdlSurface> CdlSurface::MakeFromBackendTextureAsRenderTarget( |
| 111 GrContext*, const GrBackendTextureDesc&, sk_sp<SkColorSpace>, const SkSurfacePro
ps*) { |
| 112 |
| 113 } |
| 114 #endif |
| 115 |
| 116 /** |
| 117 * Return a new surface whose contents will be drawn to an offscreen |
| 118 * render target, allocated by the surface. |
| 119 */ |
| 120 sk_sp<CdlSurface> CdlSurface::MakeRenderTarget(GrContext* gc, |
| 121 SkBudgeted budgeted, |
| 122 const SkImageInfo& info, |
| 123 int sampleCount, |
| 124 GrSurfaceOrigin origin, |
| 125 const SkSurfaceProps* props) { |
| 126 sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget( |
| 127 gc, budgeted, info, sampleCount, origin, props); |
| 128 if (surface.get()) |
| 129 return sk_make_sp<CdlSurface>(surface); |
| 130 return nullptr; |
| 131 } |
| 132 |
| 133 CdlCanvas* CdlSurface::getCanvas() { |
| 134 if (canvas_.get()) |
| 135 return canvas_.get(); |
| 136 canvas_ = base::MakeUnique<CdlPassThroughCanvas>(surface_->getCanvas()); |
| 137 return canvas_.get(); |
| 138 } |
| 139 |
| 140 void CdlSurface::draw(CdlCanvas* canvas, |
| 141 SkScalar x, |
| 142 SkScalar y, |
| 143 const CdlPaint* paint) { |
| 144 auto image = this->makeImageSnapshot(SkBudgeted::kYes); |
| 145 if (image) { |
| 146 canvas->drawImage(image, x, y, paint); |
| 147 } |
| 148 } |
| 149 |
| 150 #endif // CDL_ENABLED |
| OLD | NEW |