2 * Copyright 2021 Google LLC
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "src/gpu/graphite/Surface_Graphite.h"
10 #include "include/core/SkCapabilities.h"
11 #include "include/gpu/graphite/Recorder.h"
12 #include "include/gpu/graphite/SkStuff.h"
13 #include "src/gpu/graphite/Caps.h"
14 #include "src/gpu/graphite/Device.h"
15 #include "src/gpu/graphite/Image_Graphite.h"
16 #include "src/gpu/graphite/RecorderPriv.h"
18 namespace skgpu::graphite {
20 Surface::Surface(sk_sp<Device> device)
21 : SkSurface_Base(device->width(), device->height(), &device->surfaceProps())
22 , fDevice(std::move(device)) {
25 Surface::~Surface() {}
27 Recorder* Surface::onGetRecorder() {
28 return fDevice->recorder();
31 SkCanvas* Surface::onNewCanvas() { return new SkCanvas(fDevice); }
33 sk_sp<SkSurface> Surface::onNewSurface(const SkImageInfo& ii) {
34 return MakeGraphite(fDevice->recorder(), ii);
37 sk_sp<SkImage> Surface::onNewImageSnapshot(const SkIRect* subset) {
38 SkImageInfo ii = subset ? this->imageInfo().makeDimensions(subset->size())
41 // TODO: create a real proxy view
42 sk_sp<TextureProxy> proxy(new TextureProxy(ii.dimensions(), {}, SkBudgeted::kNo));
43 TextureProxyView tpv(std::move(proxy));
45 return sk_sp<Image>(new Image(tpv, ii.colorInfo()));
48 void Surface::onWritePixels(const SkPixmap& pixmap, int x, int y) {
49 fDevice->writePixels(pixmap, x, y);
52 bool Surface::onCopyOnWrite(ContentChangeMode) { return true; }
54 bool Surface::onReadPixels(Context* context,
59 return fDevice->readPixels(context, recorder, dst, srcX, srcY);
62 sk_sp<const SkCapabilities> Surface::onCapabilities() {
63 return fDevice->recorder()->priv().refCaps();
66 } // namespace skgpu::graphite