Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(241)

Unified Diff: gm/drawbitmaprect.cpp

Issue 1353313002: Make drawbitmaprect GM use Ganesh-backed bitmaps and images (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix no-GPU build Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/drawbitmaprect.cpp
diff --git a/gm/drawbitmaprect.cpp b/gm/drawbitmaprect.cpp
index 2f3362756b478bda5524e27412f870e1f166ca8d..d4fa141482bc81ad816625e5b7960e28d4f6dede 100644
--- a/gm/drawbitmaprect.cpp
+++ b/gm/drawbitmaprect.cpp
@@ -10,8 +10,13 @@
#include "SkBlurMaskFilter.h"
#include "SkColorPriv.h"
#include "SkGradientShader.h"
-#include "SkShader.h"
#include "SkImage.h"
+#include "SkShader.h"
+#include "SkSurface.h"
+
+#if SK_SUPPORT_GPU
+#include "SkGr.h"
+#endif
static SkBitmap make_chessbm(int w, int h) {
SkBitmap bm;
@@ -27,17 +32,18 @@ static SkBitmap make_chessbm(int w, int h) {
return bm;
}
-static SkImage* image_from_bitmap(const SkBitmap& bm) {
- SkBitmap b(bm);
- b.lockPixels();
- return SkImage::NewRasterCopy(b.info(), b.getPixels(), b.rowBytes());
-}
+static SkImage* makebm(SkCanvas* origCanvas, SkBitmap* resultBM, int w, int h) {
+ SkImageInfo info = SkImageInfo::MakeN32Premul(w, h);
+
+ SkAutoTUnref<SkSurface> surface(origCanvas->newSurface(info));
+ if (nullptr == surface) {
+ // picture canvas will return null, so fall-back to raster
+ surface.reset(SkSurface::NewRaster(info));
+ }
-static SkImage* makebm(SkBitmap* bm, int w, int h) {
- bm->allocN32Pixels(w, h);
- bm->eraseColor(SK_ColorTRANSPARENT);
+ SkCanvas* canvas = surface->getCanvas();
- SkCanvas canvas(*bm);
+ canvas->clear(SK_ColorTRANSPARENT);
SkScalar wScalar = SkIntToScalar(w);
SkScalar hScalar = SkIntToScalar(h);
@@ -69,14 +75,30 @@ static SkImage* makebm(SkBitmap* bm, int w, int h) {
SK_ARRAY_COUNT(colors),
SkShader::kRepeat_TileMode,
0, &mat))->unref();
- canvas.drawRect(rect, paint);
+ canvas->drawRect(rect, paint);
rect.inset(wScalar / 8, hScalar / 8);
mat.postScale(SK_Scalar1 / 4, SK_Scalar1 / 4);
}
+
+ SkImage* image = surface->newImageSnapshot();
+
+ SkBitmap tempBM;
+
+#if SK_SUPPORT_GPU
+ if (image->getTexture()) {
+ GrWrapTextureInBitmap(image->getTexture(),
+ image->width(), image->height(), image->isOpaque(), &tempBM);
+ } else
+#endif
+ {
+ image->asLegacyBitmap(&tempBM, SkImage::kRO_LegacyBitmapMode);
+ }
+
// Let backends know we won't change this, so they don't have to deep copy it defensively.
- bm->setImmutable();
+ tempBM.setImmutable();
+ *resultBM = tempBM;
- return image_from_bitmap(*bm);
+ return image;
}
static void canvasproc(SkCanvas* canvas, SkImage*, const SkBitmap& bm, const SkIRect& srcR,
@@ -113,11 +135,15 @@ protected:
SkISize onISize() override { return SkISize::Make(gSize, gSize); }
- void onOnceBeforeDraw() override {
- fImage.reset(makebm(&fLargeBitmap, gBmpSize, gBmpSize));
+ void setupImage(SkCanvas* canvas) {
+ fImage.reset(makebm(canvas, &fLargeBitmap, gBmpSize, gBmpSize));
}
void onDraw(SkCanvas* canvas) override {
+ if (!fImage) {
+ this->setupImage(canvas);
+ }
+
SkRect dstRect = { 0, 0, SkIntToScalar(64), SkIntToScalar(64)};
static const int kMaxSrcRectSize = 1 << (SkNextLog2(gBmpSize) + 2);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698