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

Side by Side Diff: cc/resources/gpu_rasterizer.cc

Issue 69343005: Added preliminary support for tile rasterization with Ganesh (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix for tests that pass NULL resource_provider/context_provider. Created 7 years 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "cc/resources/gpu_rasterizer.h"
6
7 #include "base/logging.h"
8 #include "cc/output/context_provider.h"
9 #include "cc/resources/resource_format.h"
10 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
11 #include "third_party/skia/include/core/SkCanvas.h"
12 #include "third_party/skia/include/gpu/GrContext.h"
13 #include "third_party/skia/include/gpu/SkGpuDevice.h"
14 #include "ui/gfx/size_conversions.h"
15
16 namespace cc {
17
18 namespace {
19
20 GrPixelConfig toGrFormat(ResourceFormat format) {
21 switch (format) {
22 case RGBA_8888:
23 return kRGBA_8888_GrPixelConfig;
24 case BGRA_8888:
25 return kBGRA_8888_GrPixelConfig;
26 case RGBA_4444:
27 return kRGBA_4444_GrPixelConfig;
28 default:
29 break; // If you break here, you're gonna have a bad time.
30 }
31 DCHECK(false) << "Unsupported resource format.";
32 return kSkia8888_GrPixelConfig;
33 }
34
35 } // namespace
36
37 GpuRasterizer::RasterTask::RasterTask(
38 Tile* tile, scoped_ptr<ResourcePool::Resource> resource)
39 : tile_(tile), resource_(resource.Pass()) {
40 }
41
42 GpuRasterizer::RasterTask::~RasterTask() { }
43
44 GpuRasterizer::Queue::Queue() { }
45
46 GpuRasterizer::Queue::~Queue() { }
47
48 void GpuRasterizer::Queue::Append(
49 Tile* tile, scoped_ptr<ResourcePool::Resource> resource) {
50 raster_tasks_.push_back(new RasterTask(tile, resource.Pass()));
51 }
52
53 scoped_ptr<GpuRasterizer> GpuRasterizer::Create(
54 GpuRasterizerClient* client,
55 ContextProvider* context_provider,
56 ResourceProvider* resource_provider) {
57 return make_scoped_ptr(
58 new GpuRasterizer(client, context_provider, resource_provider));
59 }
60
61 GpuRasterizer::GpuRasterizer(
62 GpuRasterizerClient* client,
63 ContextProvider* context_provider,
64 ResourceProvider* resource_provider)
65 : client_(client),
66 context_provider_(context_provider),
67 resource_provider_(resource_provider) {
68 }
69
70 GpuRasterizer::~GpuRasterizer() {
71 }
72
73 void GpuRasterizer::Rasterize(
74 const Queue& queue,
75 RenderingStatsInstrumentation* rendering_stats_instrumentation) {
76 TRACE_EVENT0("cc", "GpuRasterizer::Rasterize");
77
78 if (queue.raster_tasks_.empty())
79 return;
80
81 blink::WebGraphicsContext3D* context = context_provider_->Context3d();
82 GrContext* gr_context = context_provider_->GrContext();
83 CHECK(context);
84 CHECK(gr_context);
85
86 context->makeContextCurrent();
87 gr_context->resetContext();
88 for (RasterTaskVector::const_iterator it = queue.raster_tasks_.begin();
89 it != queue.raster_tasks_.end(); ++it) {
90 RasterTask* task = *it;
91 Tile* tile = task->tile_;
92 DCHECK_NE(task->resource_->id(), 0u);
93 {
94 ResourceProvider::ScopedWriteLockGL lock(
95 resource_provider_, task->resource_->id());
96
97 DCHECK_NE(lock.texture_id(), 0u);
98 GrBackendTextureDesc desc;
99 desc.fFlags = kRenderTarget_GrBackendTextureFlag;
100 desc.fWidth = tile->size().width();
101 desc.fHeight = tile->size().height();
102 desc.fConfig = toGrFormat(lock.format());
103 desc.fOrigin = kTopLeft_GrSurfaceOrigin;
104 desc.fTextureHandle = lock.texture_id();
105 skia::RefPtr<GrTexture> texture =
106 skia::AdoptRef(gr_context->wrapBackendTexture(desc));
107 skia::RefPtr<SkGpuDevice> device =
108 skia::AdoptRef(SkGpuDevice::Create(texture.get()));
109 CHECK(device);
110 skia::RefPtr<SkCanvas> canvas =
111 skia::AdoptRef(new SkCanvas(device.get()));
112
113 if (tile->opaque_rect().IsEmpty())
114 canvas->clear(SK_ColorTRANSPARENT);
115
116 tile->picture_pile()->RasterDirect(
117 canvas.get(), tile->content_rect(), tile->contents_scale(),
118 rendering_stats_instrumentation);
119 }
120
121 client_->OnGpuRasterTaskCompleted(tile, task->resource_.Pass());
122 }
123 gr_context->flush();
124 }
125
126 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698